From 70e305a918fcf193009831d4e89aa8c386df3dc4 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Tue, 29 Mar 2016 09:24:08 +0200 Subject: Ported / fixed most old tests --- tests/unit/Data/TableGateway/BaseGateway.php | 96 ++++++++++++++++++++++ tests/unit/Data/TableGateway/BaseGatewayTest.php | 96 ---------------------- tests/unit/Data/TableGateway/CountTest.php | 8 +- tests/unit/Data/TableGateway/MagicCallTest.php | 10 +-- .../TableGateway/TableGatewayDeleteByPkTest.php | 12 +-- .../Data/TableGateway/TableGatewayPgsqlTest.php | 20 +++-- .../Data/TableGateway/TableInfoGatewayTest.php | 6 +- tests/unit/Data/TableGateway/TestFindByPk.php | 10 +-- 8 files changed, 133 insertions(+), 125 deletions(-) create mode 100644 tests/unit/Data/TableGateway/BaseGateway.php delete mode 100644 tests/unit/Data/TableGateway/BaseGatewayTest.php (limited to 'tests/unit/Data/TableGateway') diff --git a/tests/unit/Data/TableGateway/BaseGateway.php b/tests/unit/Data/TableGateway/BaseGateway.php new file mode 100644 index 00000000..3ab23b19 --- /dev/null +++ b/tests/unit/Data/TableGateway/BaseGateway.php @@ -0,0 +1,96 @@ +gateway1===null) + { + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest'); + $this->gateway1 = new TTableGateway('address', $conn); + } + return $this->gateway1; + } + + /** + * @return TTableGateway + */ + function getGateway2() + { + if($this->gateway2===null) + { + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest'); + $this->gateway2 = new TTableGateway('department_sections', $conn); + } + return $this->gateway2; + } + + function setup() + { + $this->delete_all(); + } + + function add_record1() + { + $result = $this->getGateway()->insert($this->get_record1()); + $this->assertTrue(intval($result) > 0); + } + function add_record2() + { + $result = $this->getGateway()->insert($this->get_record2()); + $this->assertTrue(intval($result) > 0); + } + function get_record1() + { + return array( + 'username' => 'Username', + 'phone' => 121987, + 'field1_boolean' => true, + 'field2_date' => '2007-12-25', + 'field3_double' => 121.1, + 'field4_integer' => 3, + 'field5_text' => 'asdasd', + 'field6_time' => '12:40:00', + 'field7_timestamp' => 'NOW', + 'field8_money' => '121.12', + 'field9_numeric' => 98.2232, + 'int_fk1'=>1, + 'int_fk2'=>1, + ); + } + + + function get_record2() + { + return array( + 'username' => 'record2', + 'phone' => 45233, + 'field1_boolean' => false, + 'field2_date' => '2004-10-05', + 'field3_double' => 1221.1, + 'field4_integer' => 2, + 'field5_text' => 'hello world', + 'field6_time' => '22:40:00', + 'field7_timestamp' => 'NOW', + 'field8_money' => '1121.12', + 'field9_numeric' => 8.2213, + 'int_fk1'=>1, + 'int_fk2'=>1, + ); + } + function delete_all() + { + $this->getGateway()->deleteAll('1=1'); + } +} \ No newline at end of file diff --git a/tests/unit/Data/TableGateway/BaseGatewayTest.php b/tests/unit/Data/TableGateway/BaseGatewayTest.php deleted file mode 100644 index b97ef4a0..00000000 --- a/tests/unit/Data/TableGateway/BaseGatewayTest.php +++ /dev/null @@ -1,96 +0,0 @@ -gateway1===null) - { - $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); - $this->gateway1 = new TTableGateway('address', $conn); - } - return $this->gateway1; - } - - /** - * @return TTableGateway - */ - function getGateway2() - { - if($this->gateway2===null) - { - $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); - $this->gateway2 = new TTableGateway('department_sections', $conn); - } - return $this->gateway2; - } - - function setup() - { - $this->delete_all(); - } - - function add_record1() - { - $result = $this->getGateway()->insert($this->get_record1()); - $this->assertTrue(intval($result) > 0); - } - function add_record2() - { - $result = $this->getGateway()->insert($this->get_record2()); - $this->assertTrue(intval($result) > 0); - } - function get_record1() - { - return array( - 'username' => 'Username', - 'phone' => 121987, - 'field1_boolean' => true, - 'field2_date' => '2007-12-25', - 'field3_double' => 121.1, - 'field4_integer' => 3, - 'field5_text' => 'asdasd', - 'field6_time' => '12:40:00', - 'field7_timestamp' => 'NOW', - 'field8_money' => '$121.12', - 'field9_numeric' => 98.2232, - 'int_fk1'=>1, - 'int_fk2'=>1, - ); - } - - - function get_record2() - { - return array( - 'username' => 'record2', - 'phone' => 45233, - 'field1_boolean' => false, - 'field2_date' => '2004-10-05', - 'field3_double' => 1221.1, - 'field4_integer' => 2, - 'field5_text' => 'hello world', - 'field6_time' => '22:40:00', - 'field7_timestamp' => 'NOW', - 'field8_money' => '$1121.12', - 'field9_numeric' => 8.2213, - 'int_fk1'=>1, - 'int_fk2'=>1, - ); - } - function delete_all() - { - $this->getGateway()->deleteAll('1=1'); - } -} \ No newline at end of file diff --git a/tests/unit/Data/TableGateway/CountTest.php b/tests/unit/Data/TableGateway/CountTest.php index 074d935b..1d3b60ee 100644 --- a/tests/unit/Data/TableGateway/CountTest.php +++ b/tests/unit/Data/TableGateway/CountTest.php @@ -1,18 +1,18 @@ getGateway2()->count(); - $this->assertEqual(44,$result); + $this->assertEquals(5,$result); $result = $this->getGateway2()->count('department_id = ?', 1); - $this->assertEqual(4, $result); + $this->assertEquals(2, $result); } } \ No newline at end of file diff --git a/tests/unit/Data/TableGateway/MagicCallTest.php b/tests/unit/Data/TableGateway/MagicCallTest.php index 56cc85b3..caf10019 100644 --- a/tests/unit/Data/TableGateway/MagicCallTest.php +++ b/tests/unit/Data/TableGateway/MagicCallTest.php @@ -1,18 +1,18 @@ add_record1(); $this->add_record2(); $result = $this->getGateway()->findByUsername("record2"); - $this->assertEqual($result['username'], 'record2'); + $this->assertEquals($result['username'], 'record2'); } function test_combined_and_or() @@ -20,7 +20,7 @@ class MagicCallTest extends BaseGatewayTest $this->add_record1(); $this->add_record2(); $result = $this->getGateway()->findAllByUsername_OR_phone('Username', '45233')->readAll(); - $this->assertEqual(2, count($result)); + $this->assertEquals(2, count($result)); } function test_no_result() @@ -28,6 +28,6 @@ class MagicCallTest extends BaseGatewayTest $this->add_record1(); $this->add_record2(); $result = $this->getGateway()->findAllByUsername_and_phone('Username', '45233')->readAll(); - $this->assertEqual(0, count($result)); + $this->assertEquals(0, count($result)); } } \ No newline at end of file diff --git a/tests/unit/Data/TableGateway/TableGatewayDeleteByPkTest.php b/tests/unit/Data/TableGateway/TableGatewayDeleteByPkTest.php index 6bcaeb91..36d1be11 100644 --- a/tests/unit/Data/TableGateway/TableGatewayDeleteByPkTest.php +++ b/tests/unit/Data/TableGateway/TableGatewayDeleteByPkTest.php @@ -1,11 +1,11 @@ getGateway()->getLastInsertId(); $deleted = $this->getGateway()->deleteByPk($id); - $this->assertEqual(1, $deleted); + $this->assertEquals(1, $deleted); } function test_delete_by_multiple_pk() @@ -25,7 +25,7 @@ class TableGatewayDeleteByPkTest extends BaseGatewayTest $deleted = $this->getGateway()->deleteByPk($id1, $id2); - $this->assertEqual(2, $deleted); + $this->assertEquals(2, $deleted); } function test_delete_by_multiple_pk2() @@ -37,7 +37,7 @@ class TableGatewayDeleteByPkTest extends BaseGatewayTest $deleted = $this->getGateway()->deleteByPk(array($id1, $id2)); - $this->assertEqual(2, $deleted); + $this->assertEquals(2, $deleted); } function test_delete_by_multiple_pk3() @@ -49,6 +49,6 @@ class TableGatewayDeleteByPkTest extends BaseGatewayTest $deleted = $this->getGateway()->deleteByPk(array(array($id1), array($id2))); - $this->assertEqual(2, $deleted); + $this->assertEquals(2, $deleted); } } \ No newline at end of file diff --git a/tests/unit/Data/TableGateway/TableGatewayPgsqlTest.php b/tests/unit/Data/TableGateway/TableGatewayPgsqlTest.php index 234f70bd..fae1f394 100644 --- a/tests/unit/Data/TableGateway/TableGatewayPgsqlTest.php +++ b/tests/unit/Data/TableGateway/TableGatewayPgsqlTest.php @@ -1,11 +1,19 @@ markTestSkipped( + 'The pgsql extension is not available.' + ); + } + } function test_update() { @@ -20,7 +28,7 @@ class TableGatewayPgsqlTest extends BaseGatewayTest $expect['username'] = 'tester 1'; $expect['field5_text'] = null; unset($expect['field7_timestamp']); unset($test['field7_timestamp']); - $this->assertEqual($expect, $test); + $this->assertEquals($expect, $test); $this->assertTrue($this->getGateway()->deleteAll('username = ?', 'tester 1')); } @@ -38,7 +46,7 @@ class TableGatewayPgsqlTest extends BaseGatewayTest $expect['username'] = 'tester 1'; $expect['field5_text'] = null; unset($expect['field7_timestamp']); unset($test['field7_timestamp']); - $this->assertEqual($expect, $test); + $this->assertEquals($expect, $test); $this->assertTrue($this->getGateway()->deleteAll('username = :name', array(':name'=>'tester 1'))); } @@ -49,10 +57,10 @@ class TableGatewayPgsqlTest extends BaseGatewayTest $this->add_record2(); $results = $this->getGateway()->findAll('true')->readAll(); - $this->assertEqual(count($results), 2); + $this->assertEquals(count($results), 2); $result = $this->getGateway()->findAllBySql('SELECT username FROM address WHERE phone = ?', '45233')->read(); - $this->assertEqual($result['username'], 'record2'); + $this->assertEquals($result['username'], 'record2'); } } \ No newline at end of file diff --git a/tests/unit/Data/TableGateway/TableInfoGatewayTest.php b/tests/unit/Data/TableGateway/TableInfoGatewayTest.php index 24b94690..9d4c2a49 100644 --- a/tests/unit/Data/TableGateway/TableInfoGatewayTest.php +++ b/tests/unit/Data/TableGateway/TableInfoGatewayTest.php @@ -1,11 +1,11 @@ add_record2(); $info = TDbMetaData::getInstance($conn)->getTableInfo('address'); $table = new TTableGateway($info, $conn); - $this->assertEqual(count($table->findAll()->readAll()), 2); + $this->assertEquals(count($table->findAll()->readAll()), 2); } } \ No newline at end of file diff --git a/tests/unit/Data/TableGateway/TestFindByPk.php b/tests/unit/Data/TableGateway/TestFindByPk.php index f23fafa7..264231e6 100644 --- a/tests/unit/Data/TableGateway/TestFindByPk.php +++ b/tests/unit/Data/TableGateway/TestFindByPk.php @@ -1,11 +1,11 @@ assertEqual($record1, $result); + $this->assertEquals($record1, $result); } function test_composite_key() @@ -31,7 +31,7 @@ class TestFindByPk extends BaseGatewayTest $result = $gateway->findByPk(1,1); $expect = array("department_id" => 1, "section_id" => 1, "order" => 0); - $this->assertEqual($expect, $result); + $this->assertEquals($expect, $result); } function test_find_all_keys() @@ -44,7 +44,7 @@ class TestFindByPk extends BaseGatewayTest array("department_id" => 1, "section_id" => 1, "order" => 0), array("department_id" => 3, "section_id" => 13, "order" => 0)); - $this->assertEqual($expect, $result); + $this->assertEquals($expect, $result); } } \ No newline at end of file -- cgit v1.2.3