X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Flib%2Fpq%2FGateway%2FTableTest.php;h=c9bf19f5977f2ef5adb5488010a08e8e1db8c7e7;hb=d1379696731e50755ace6e92fa04ae24fe34651b;hp=65c93f717b483923d5bd87c935165ff528f5b8f2;hpb=4879955d1b86d606dc24401f26ebde9be7612fbf;p=m6w6%2Fpq-gateway diff --git a/tests/lib/pq/Gateway/TableTest.php b/tests/lib/pq/Gateway/TableTest.php index 65c93f7..c9bf19f 100644 --- a/tests/lib/pq/Gateway/TableTest.php +++ b/tests/lib/pq/Gateway/TableTest.php @@ -2,7 +2,7 @@ namespace pq\Gateway; -include_once __DIR__."/../../../setup.inc"; +require_once __DIR__."/../../../setup.inc"; class TableTest extends \PHPUnit_Framework_TestCase { @@ -17,21 +17,17 @@ class TableTest extends \PHPUnit_Framework_TestCase { protected $table; protected function setUp() { - $this->conn = new \pq\Connection(PQ_DSN); - $this->conn->exec(PQ_TEST_DROP_TABLE); - $this->conn->exec(PQ_TEST_CREATE_TABLE); + $this->conn = new \pq\Connection(PQ_TEST_DSN); + $this->conn->exec(PQ_TEST_SETUP_SQL); Table::$defaultConnection = $this->conn; - $this->table = new Table(PQ_TEST_TABLE_NAME); + $this->table = new Table("test"); + $this->table->getQueryExecutor()->attach(new \QueryLogger()); } protected function tearDown() { - $this->conn->exec(PQ_TEST_DROP_TABLE); + $this->conn->exec(PQ_TEST_TEARDOWN_SQL); } - protected function createTestData() { - $this->conn->exec(PQ_TEST_CREATE_DATA); - } - public function testSetRowsetPrototype() { $prop = new \ReflectionProperty("\\pq\\Gateway\\Table", "rowset"); $prop->setAccessible(true); @@ -48,7 +44,7 @@ class TableTest extends \PHPUnit_Framework_TestCase { } public function testGetName() { - $this->assertSame(PQ_TEST_TABLE_NAME, $this->table->getName()); + $this->assertSame("test", $this->table->getName()); } public function testFind() { @@ -71,18 +67,34 @@ 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", + "list" => array(3,2,1), + "prop" => null ); $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($data, $row->getData()); } public function testDelete() { $this->table->delete(array("id!=" => 0)); $this->assertCount(0, $this->table->find()); } + + public function testWith() { + $rowset = $this->table->with(["reftest"], 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", + "list" => array(0,1,2), + "prop" => null + ), $rowset->current()->getData()); + } }