Skip to content

Commit

Permalink
PDO: Clean-up tests so it's easier to see if they use default test ta…
Browse files Browse the repository at this point in the history
…ble (#12552)
  • Loading branch information
Girgias authored Oct 29, 2023
1 parent 4c6dbe0 commit c1fec9b
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 91 deletions.
9 changes: 4 additions & 5 deletions ext/pdo/tests/bug_43139.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ $db = PDOTest::factory();
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);

$from = '';
if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci') {
$from = 'from dual';
} else if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'firebird') {
$from = 'FROM RDB$DATABASE';
switch ($db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
case 'oci': $from = ' FROM DUAL'; break;
case 'firebird': $from = ' FROM RDB$DATABASE'; break;
default: $from = ''; break;
}

var_dump($db->query("select 0 as abc, 1 as xyz, 2 as def $from")->fetchAll(PDO::FETCH_GROUP));
Expand Down
8 changes: 4 additions & 4 deletions ext/pdo/tests/bug_43663.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PDOTest::skip();
?>
--FILE--
<?php
class test extends PDO{
class TestClass extends PDO{
function __call($name, array $args) {
echo "Called $name in ".__CLASS__."\n";
}
Expand All @@ -23,10 +23,10 @@ class test extends PDO{
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';

$a = PDOTest::factory(test::class);
$a = PDOTest::factory(TestClass::class);
$a->foo();
$a->bar();
?>
--EXPECT--
Called foo in test
Called bar in test
Called foo in TestClass
Called bar in TestClass
19 changes: 13 additions & 6 deletions ext/pdo/tests/bug_44861.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ $db = PDOTest::factory();

$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci') {
$from = 'FROM DUAL';
$ob = '1';
} else {
$from = '';
$ob = 'r';
switch ($db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
case 'oci':
$from = 'FROM DUAL';
$ob = '1';
break;
case 'firebird':
$from = 'FROM RDB$DATABASE';
$ob = 'r';
break;
default:
$from = '';
$ob = 'r';
break;
}

$query = "SELECT 'row1' AS r $from UNION SELECT 'row2' $from UNION SELECT 'row3' $from UNION SELECT 'row4' $from ORDER BY $ob";
Expand Down
4 changes: 2 additions & 2 deletions ext/pdo/tests/bug_60665.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();
switch ($db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
case 'oci': $from = 'from dual'; break;
case 'firebird': $from = 'from rdb$database'; break;
case 'oci': $from = ' FROM DUAL'; break;
case 'firebird': $from = ' FROM RDB$DATABASE'; break;
default: $from = ''; break;
}
$statement = $db->prepare("SELECT NULL AS null_value, 0 AS zero, 1 AS one $from");
Expand Down
10 changes: 4 additions & 6 deletions ext/pdo/tests/bug_69356.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ SELECT '
SQL;

switch ($db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
case 'oci':
$query .= ' FROM DUAL';
break;
case 'firebird':
$query .= ' FROM RDB$DATABASE';
break;
case 'oci': $from = ' FROM DUAL'; break;
case 'firebird': $from = ' FROM RDB$DATABASE'; break;
default: $from = ''; break;
}
$query .= $from;

$stmt = $db->query($query);
var_dump($stmt->debugDumpParams());
Expand Down
6 changes: 3 additions & 3 deletions ext/pdo/tests/bug_72788.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';

putenv("PDOTEST_ATTR=" . serialize(array(PDO::ATTR_PERSISTENT => true)));

function test() {
function callback() {
$db = PDOTest::factory('PDO', false);
$stmt = @$db->query("SELECT 1 FROM TABLE_DOES_NOT_EXIST");
if ($stmt === false) {
echo "Statement failed as expected\n";
}
}

test();
test();
callback();
callback();
echo "Done";
?>
--EXPECT--
Expand Down
22 changes: 11 additions & 11 deletions ext/pdo/tests/pdo_011.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Test1
}
}

function test($id,$val='N/A')
function callback($id,$val='N/A')
{
echo __METHOD__ . "($id,$val)\n";
return array($id=>$val);
Expand All @@ -61,10 +61,10 @@ function test($id,$val='N/A')
$f = new Test1(0,0);

$select1->execute();
var_dump($select1->fetchAll(PDO::FETCH_FUNC|PDO::FETCH_GROUP, 'test'));
var_dump($select1->fetchAll(PDO::FETCH_FUNC|PDO::FETCH_GROUP, 'callback'));

$select2->execute();
var_dump($select2->fetchAll(PDO::FETCH_FUNC, 'test'));
var_dump($select2->fetchAll(PDO::FETCH_FUNC, 'callback'));

$select2->execute();
var_dump($select2->fetchAll(PDO::FETCH_FUNC, array('Test1','factory')));
Expand All @@ -90,10 +90,10 @@ PDOTest::dropTableIfExists($db, "test011");
--EXPECTF--
DerivedStatement::__construct(Overloaded)
Test1::__construct(0,0)
test(1,N/A)
test(2,N/A)
test(3,N/A)
test(4,N/A)
callback(1,N/A)
callback(2,N/A)
callback(3,N/A)
callback(4,N/A)
array(2) {
["Group1"]=>
array(2) {
Expand Down Expand Up @@ -122,10 +122,10 @@ array(2) {
}
}
}
test(1,A)
test(2,B)
test(3,C)
test(4,D)
callback(1,A)
callback(2,B)
callback(3,C)
callback(4,D)
array(4) {
[0]=>
array(1) {
Expand Down
22 changes: 11 additions & 11 deletions ext/pdo/tests/pdo_012.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $SELECT = 'SELECT val, grp FROM test012';
$stmt = $db->query($SELECT, PDO::FETCH_NUM);
var_dump($stmt->fetchAll());

class Test
class TestClass
{
public $val;
public $grp;
Expand All @@ -37,13 +37,13 @@ class Test

unset($stmt);

$stmt = $db->query($SELECT, PDO::FETCH_CLASS, 'Test');
$stmt = $db->query($SELECT, PDO::FETCH_CLASS, TestClass::class);
var_dump($stmt->fetchAll());

unset($stmt);

$stmt = $db->query($SELECT, PDO::FETCH_NUM);
$stmt->setFetchMode(PDO::FETCH_CLASS, 'Test', array('Changed'));
$stmt->setFetchMode(PDO::FETCH_CLASS, TestClass::class, array('Changed'));
var_dump($stmt->fetchAll());

?>
Expand All @@ -70,36 +70,36 @@ array(2) {
string(6) "Group2"
}
}
Test::__construct(N/A)
Test::__construct(N/A)
TestClass::__construct(N/A)
TestClass::__construct(N/A)
array(2) {
[0]=>
object(Test)#%d (2) {
object(TestClass)#%d (2) {
["val"]=>
string(1) "A"
["grp"]=>
string(6) "Group1"
}
[1]=>
object(Test)#%d (2) {
object(TestClass)#%d (2) {
["val"]=>
string(1) "B"
["grp"]=>
string(6) "Group2"
}
}
Test::__construct(Changed)
Test::__construct(Changed)
TestClass::__construct(Changed)
TestClass::__construct(Changed)
array(2) {
[0]=>
object(Test)#%d (2) {
object(TestClass)#%d (2) {
["val"]=>
string(1) "A"
["grp"]=>
string(6) "Group1"
}
[1]=>
object(Test)#%d (2) {
object(TestClass)#%d (2) {
["val"]=>
string(1) "B"
["grp"]=>
Expand Down
22 changes: 11 additions & 11 deletions ext/pdo/tests/pdo_013.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ foreach ($stmt as $data)
var_dump($data);
}

class Test
class TestClass
{
public $val;
public $grp;
Expand All @@ -43,14 +43,14 @@ class Test

unset($stmt);

foreach ($db->query($SELECT, PDO::FETCH_CLASS, 'Test') as $data)
foreach ($db->query($SELECT, PDO::FETCH_CLASS, TestClass::class) as $data)
{
var_dump($data);
}

unset($stmt);

$stmt = $db->query($SELECT, PDO::FETCH_CLASS, 'Test', array('WOW'));
$stmt = $db->query($SELECT, PDO::FETCH_CLASS, TestClass::class, array('WOW'));

foreach($stmt as $data)
{
Expand All @@ -76,29 +76,29 @@ array(2) {
[1]=>
string(6) "Group2"
}
Test::__construct(N/A)
object(Test)#%d (2) {
TestClass::__construct(N/A)
object(TestClass)#%d (2) {
["val"]=>
string(1) "A"
["grp"]=>
string(6) "Group1"
}
Test::__construct(N/A)
object(Test)#%d (2) {
TestClass::__construct(N/A)
object(TestClass)#%d (2) {
["val"]=>
string(1) "B"
["grp"]=>
string(6) "Group2"
}
Test::__construct(WOW)
object(Test)#%d (2) {
TestClass::__construct(WOW)
object(TestClass)#%d (2) {
["val"]=>
string(1) "A"
["grp"]=>
string(6) "Group1"
}
Test::__construct(WOW)
object(Test)#%d (2) {
TestClass::__construct(WOW)
object(TestClass)#%d (2) {
["val"]=>
string(1) "B"
["grp"]=>
Expand Down
12 changes: 6 additions & 6 deletions ext/pdo/tests/pdo_014.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $db->exec("INSERT INTO test014 VALUES(1, 'A', 'Group1')");
$db->exec("INSERT INTO test014 VALUES(2, 'B', 'Group2')");
$SELECT = 'SELECT val, grp FROM test014';

class Test
class TestClass
{
public $val;
public $grp;
Expand All @@ -31,7 +31,7 @@ class Test
}
}

$stmt = $db->query($SELECT, PDO::FETCH_CLASS, 'Test', array('WOW'));
$stmt = $db->query($SELECT, PDO::FETCH_CLASS, TestClass::class, array('WOW'));

$it = new IteratorIterator($stmt); /* check if we can convert that thing */

Expand Down Expand Up @@ -78,15 +78,15 @@ $db = PDOTest::factory();
PDOTest::dropTableIfExists($db, "test014");
?>
--EXPECTF--
Test::__construct(WOW)
object(Test)#%d (2) {
TestClass::__construct(WOW)
object(TestClass)#%d (2) {
["val"]=>
string(1) "A"
["grp"]=>
string(6) "Group1"
}
Test::__construct(WOW)
object(Test)#%d (2) {
TestClass::__construct(WOW)
object(TestClass)#%d (2) {
["val"]=>
string(1) "B"
["grp"]=>
Expand Down
4 changes: 2 additions & 2 deletions ext/pdo/tests/pdo_023.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PDODatabaseX extends PDO
echo __METHOD__ . "()\n";
}

function test()
function testMethod()
{
$this->test2 = 2;
var_dump($this->test1);
Expand All @@ -60,7 +60,7 @@ class PDODatabaseX extends PDO
}

$db = PDOTest::factory('PDODatabaseX');
$db->test();
$db->testMethod();
var_dump($db);

$db->query('CREATE TABLE test023(id INT NOT NULL PRIMARY KEY, val VARCHAR(10))');
Expand Down
4 changes: 2 additions & 2 deletions ext/pdo_firebird/tests/bug_76449.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ require_once "payload_server.inc";
$address = run_server(__DIR__ . "/bug_76449.data");

// no need to change the credentials; we're running against a fake server
$dsn = "firebird:dbname=inet://$address/test";
$dsn = "firebird:dbname=inet://$address/test76449";
$username = 'SYSDBA';
$password = 'masterkey';

$dbh = new PDO($dsn, $username, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
var_dump($dbh->exec("INSERT INTO test VALUES ('hihi2', 'xxxxx')"));
var_dump($dbh->exec("INSERT INTO test76449 VALUES ('hihi2', 'xxxxx')"));
?>
--EXPECT--
bool(false)
4 changes: 2 additions & 2 deletions ext/pdo_firebird/tests/bug_76452.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ require_once "payload_server.inc";
$address = run_server(__DIR__ . "/bug_76452.data");

// no need to change the credentials; we're running against a falke server
$dsn = "firebird:dbname=inet://$address/test";
$dsn = "firebird:dbname=inet://$address/test76452";
$username = 'SYSDBA';
$password = 'masterkey';

$dbh = new PDO($dsn, $username, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
$query = $dbh->prepare("select * from test");
$query = $dbh->prepare("SELECT * FROM test76452");
$query->execute();
var_dump($query->fetch());
?>
Expand Down
Loading

0 comments on commit c1fec9b

Please sign in to comment.