X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Flib%2Fpq%2FGateway%2FTableTest.php;h=a43634cf203114fee18a5f9a54d4ade57cce53c8;hb=b39e14404cfeac177d41b152690b6adbb2b1e4bf;hp=e1b66870c706fe1e9f7518e1bef1ed8722c2435e;hpb=580991717f5e8bb237403757e2111a8d04aca616;p=m6w6%2Fpq-gateway diff --git a/tests/lib/pq/Gateway/TableTest.php b/tests/lib/pq/Gateway/TableTest.php index e1b6687..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,18 +67,31 @@ 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() { $this->table->delete(array("id!=" => 0)); $this->assertCount(0, $this->table->find()); } + + public function testWith() { + $relation = $this->table->getRelations("test")->reftest; + $rowset = $this->table->with([$relation], array("another_test_id=" => 2)); + $this->assertCount(1, $rowset); + $this->assertEquals(array( + "id" => 2, + "created" => new \pq\DateTime("today"), + "counter" => 0, + "number" => 0, + "data" => "today" + ), $rowset->current()->getData()); + } }