From: Michael Wallner Date: Thu, 25 Apr 2013 08:22:31 +0000 (+0200) Subject: test fixups X-Git-Tag: v1.0.0~3 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=348c73cdaf65cf9df2d6f582a96bf8694f1255f5;p=m6w6%2Fpq-gateway test fixups --- diff --git a/composer.json b/composer.json index 8d6d33c..d0b230f 100644 --- a/composer.json +++ b/composer.json @@ -1,23 +1,23 @@ { - "name": "mike_php_net/pq-gateway", - "type": "library", - "description": "Table/row gateway for ext-pq", - "keywords": ["postgres", "orm", "gateway", "pq"], - "homepage": "http://bitbucket.org/mike_php_net/pq-gateway", - "license": "BSD-2-Clause", - "authors": [ - { - "name": "Michael Wallner", - "email": "mike@php.net" - } - ], - "autoload": { - "psr-0": { - "pq\\Gateway": "lib", - "pq\\Query": "lib" - } - }, - "suggest": { - "reactphp/promise": "1.0.*" - } + "name": "mike_php_net/pq-gateway", + "type": "library", + "description": "Table/row gateway for ext-pq", + "keywords": ["postgres", "orm", "gateway", "pq"], + "homepage": "http://bitbucket.org/mike_php_net/pq-gateway", + "license": "BSD-2-Clause", + "authors": [ + { + "name": "Michael Wallner", + "email": "mike@php.net" + } + ], + "autoload": { + "psr-0": { + "pq\\Gateway": "lib", + "pq\\Query": "lib" + } + }, + "suggest": { + "reactphp/promise": "1.0.*" + } } diff --git a/tests/lib/pq/Gateway/CellTest.php b/tests/lib/pq/Gateway/CellTest.php index 9dc9680..fc08ba6 100644 --- a/tests/lib/pq/Gateway/CellTest.php +++ b/tests/lib/pq/Gateway/CellTest.php @@ -18,17 +18,14 @@ class CellTest extends \PHPUnit_Framework_TestCase { protected function setUp() { $this->conn = new \pq\Connection(PQ_TEST_DSN); - $this->conn->exec(PQ_TEST_TABLE_CREATE); - $this->conn->exec(PQ_TEST_REFTABLE_CREATE); - $this->conn->exec(PQ_TEST_DATA); + $this->conn->exec(PQ_TEST_SETUP_SQL); Table::$defaultConnection = $this->conn; $this->table = new Table("test"); $this->table->getQueryExecutor()->attach(new \QueryLogger()); } protected function tearDown() { - $this->conn->exec(PQ_TEST_REFTABLE_DROP); - $this->conn->exec(PQ_TEST_TABLE_DROP); + $this->conn->exec(PQ_TEST_TEARDOWN_SQL); } /** diff --git a/tests/lib/pq/Gateway/RowTest.php b/tests/lib/pq/Gateway/RowTest.php index 6a738d3..1d33963 100644 --- a/tests/lib/pq/Gateway/RowTest.php +++ b/tests/lib/pq/Gateway/RowTest.php @@ -18,27 +18,24 @@ class RowTest extends \PHPUnit_Framework_TestCase { protected function setUp() { $this->conn = new \pq\Connection(PQ_TEST_DSN); - $this->conn->exec(PQ_TEST_TABLE_CREATE); - $this->conn->exec(PQ_TEST_REFTABLE_CREATE); - $this->conn->exec(PQ_TEST_DATA); + $this->conn->exec(PQ_TEST_SETUP_SQL); Table::$defaultConnection = $this->conn; $this->table = new Table("test"); $this->table->getQueryExecutor()->attach(new \QueryLogger()); } protected function tearDown() { - $this->conn->exec(PQ_TEST_REFTABLE_DROP); - $this->conn->exec(PQ_TEST_TABLE_DROP); + $this->conn->exec(PQ_TEST_TEARDOWN_SQL); } function testBasic() { $row = new Row($this->table, array("id" => 3), true); $this->assertTrue($row->isDirty()); $row->refresh(); - $this->assertSame( + $this->assertEquals( array( "id" => "3", - "created" => date("Y-m-d H:i:s", strtotime("tomorrow")), + "created" => new \pq\DateTime("tomorrow"), "counter" => "1", "number" => "1.1", "data" => "tomorrow" diff --git a/tests/lib/pq/Gateway/RowsetTest.php b/tests/lib/pq/Gateway/RowsetTest.php index 037192a..6f16595 100644 --- a/tests/lib/pq/Gateway/RowsetTest.php +++ b/tests/lib/pq/Gateway/RowsetTest.php @@ -18,17 +18,14 @@ class RowsetTest extends \PHPUnit_Framework_TestCase { protected function setUp() { $this->conn = new \pq\Connection(PQ_TEST_DSN); - $this->conn->exec(PQ_TEST_TABLE_CREATE); - $this->conn->exec(PQ_TEST_REFTABLE_CREATE); - $this->conn->exec(PQ_TEST_DATA); + $this->conn->exec(PQ_TEST_SETUP_SQL); Table::$defaultConnection = $this->conn; $this->table = new Table("test"); $this->table->getQueryExecutor()->attach(new \QueryLogger()); } protected function tearDown() { - $this->conn->exec(PQ_TEST_REFTABLE_DROP); - $this->conn->exec(PQ_TEST_TABLE_DROP); + $this->conn->exec(PQ_TEST_TEARDOWN_SQL); } public function test__invoke() { @@ -117,9 +114,9 @@ class RowsetTest extends \PHPUnit_Framework_TestCase { $json = sprintf('[{"id":"1","created":"%s","counter":"-1","number":"-1.1","data":"yesterday"}' .',{"id":"2","created":"%s","counter":"0","number":"0","data":"today"}' .',{"id":"3","created":"%s","counter":"1","number":"1.1","data":"tomorrow"}]', - date("Y-m-d H:i:s", strtotime("yesterday")), - date("Y-m-d H:i:s", strtotime("today")), - date("Y-m-d H:i:s", strtotime("tomorrow")) + new \pq\DateTime("yesterday"), + new \pq\DateTime("today"), + new \pq\DateTime("tomorrow") ); $this->assertJsonStringEqualsJsonString($json, json_encode($this->table->find())); } diff --git a/tests/lib/pq/Gateway/TableTest.php b/tests/lib/pq/Gateway/TableTest.php index f3d9558..a43634c 100644 --- a/tests/lib/pq/Gateway/TableTest.php +++ b/tests/lib/pq/Gateway/TableTest.php @@ -18,17 +18,14 @@ class TableTest extends \PHPUnit_Framework_TestCase { protected function setUp() { $this->conn = new \pq\Connection(PQ_TEST_DSN); - $this->conn->exec(PQ_TEST_TABLE_CREATE); - $this->conn->exec(PQ_TEST_REFTABLE_CREATE); - $this->conn->exec(PQ_TEST_DATA); + $this->conn->exec(PQ_TEST_SETUP_SQL); Table::$defaultConnection = $this->conn; $this->table = new Table("test"); $this->table->getQueryExecutor()->attach(new \QueryLogger()); } protected function tearDown() { - $this->conn->exec(PQ_TEST_REFTABLE_DROP); - $this->conn->exec(PQ_TEST_TABLE_DROP); + $this->conn->exec(PQ_TEST_TEARDOWN_SQL); } public function testSetRowsetPrototype() { @@ -70,14 +67,14 @@ class TableTest extends \PHPUnit_Framework_TestCase { public function testUpdate() { $row = $this->table->create(array())->current(); $data = array( - "created" => "2013-03-03 03:03:03", + "created" => new \pq\DateTime("2013-03-03 03:03:03"), "counter" => 2, "number" => 2.2, "data" => "this is a test", ); $row = $this->table->update(array("id = " => $row->id), $data)->current(); $data = array("id" => $row->id->get()) + $data; - $this->assertSame(array_map(function($v){return strval($v);}, $data), $row->getData()); + $this->assertEquals(array_map(function($v){return strval($v);}, $data), $row->getData()); } public function testDelete() { @@ -91,7 +88,7 @@ class TableTest extends \PHPUnit_Framework_TestCase { $this->assertCount(1, $rowset); $this->assertEquals(array( "id" => 2, - "created" => date_create("today")->format("Y-m-d H:i:s"), + "created" => new \pq\DateTime("today"), "counter" => 0, "number" => 0, "data" => "today" diff --git a/tests/setup.inc b/tests/setup.inc index 38dff5a..47998cf 100644 --- a/tests/setup.inc +++ b/tests/setup.inc @@ -2,7 +2,7 @@ const PQ_TEST_DSN = ""; -const PQ_TEST_TABLE_CREATE = <<getConnection();