test fixups
authorMichael Wallner <mike@php.net>
Thu, 25 Apr 2013 08:22:31 +0000 (10:22 +0200)
committerMichael Wallner <mike@php.net>
Thu, 25 Apr 2013 08:22:31 +0000 (10:22 +0200)
composer.json
tests/lib/pq/Gateway/CellTest.php
tests/lib/pq/Gateway/RowTest.php
tests/lib/pq/Gateway/RowsetTest.php
tests/lib/pq/Gateway/TableTest.php
tests/setup.inc

index 8d6d33ce5ba0e77e0db10d20d55e7547a9372853..d0b230f45c3e2b3da5103d6ccbe63ba5124ff407 100644 (file)
@@ -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.*"
+       }
 }
index 9dc96805f0dda5855d63f8e425ab4b0c5f3002c2..fc08ba68f5efb743ca2eca593319f52e80a1bdd0 100644 (file)
@@ -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);
        }
 
        /**
index 6a738d3b4e54dae0f58be6d3f8141c57809e101b..1d339639c27d5cda471ce5a68589750b9a3e1b23 100644 (file)
@@ -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"
index 037192a38728f8eba4b78fe31c45306a19c11e42..6f16595994316ba4a49c0da7b89d275ca57bf463 100644 (file)
@@ -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()));
        }
index f3d955819c4e25ba6eeecf35c6e3064aa3431cf7..a43634cf203114fee18a5f9a54d4ade57cce53c8 100644 (file)
@@ -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"
index 38dff5a3202f8000bab1758803696d6c235127b4..47998cf7353c1c7b40c877f66285cd6f4a9945f1 100644 (file)
@@ -2,7 +2,7 @@
 
 const PQ_TEST_DSN = "";
 
-const PQ_TEST_TABLE_CREATE = <<<SQL
+const PQ_TEST_SETUP_SQL = <<<SQL
        drop table if exists test cascade;
        create table test (
                id serial primary key, 
@@ -10,26 +10,14 @@ const PQ_TEST_TABLE_CREATE = <<<SQL
                counter int, 
                number decimal, 
                data text
-       )
-SQL;
-
-const PQ_TEST_TABLE_DROP = <<<SQL
-       drop table if exists test cascade;
-SQL;
-
-const PQ_TEST_REFTABLE_CREATE = <<<SQL
+       );
+       
        drop table if exists reftest cascade;
        create table reftest (
                test_id integer not null references test on delete cascade,
                another_test_id integer not null references test on delete cascade
        );
-SQL;
-
-const PQ_TEST_REFTABLE_DROP = <<<SQL
-       drop table if exists reftest cascade;
-SQL;
-
-const PQ_TEST_DATA = <<<SQL
+       
        insert into test values (default, 'yesterday', -1, -1.1, 'yesterday');
        insert into test values (default, 'today', 0, 0, 'today');
        insert into test values (default, 'tomorrow', 1, 1.1, 'tomorrow');
@@ -39,9 +27,12 @@ const PQ_TEST_DATA = <<<SQL
        insert into reftest values (3,1);
 SQL;
 
-spl_autoload_register(function($c) {
-       if (substr($c,0,3) == "pq\\") return require_once sprintf("%s/../lib/%s.php", __DIR__, strtr($c, "\\", "/"));
-});
+const PQ_TEST_TEARDOWN_SQL = <<<SQL
+       drop table if exists test cascade;
+       drop table if exists reftest cascade;
+SQL;
+
+include_once __DIR__ . "/../lib/autoload.php";
 
 function executeInConcurrentTransaction(\pq\Query\ExecutorInterface $exec, $sql, array $params = null) {
        $conn = $exec->getConnection();