X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=tests%2Flib%2Fpq%2FGateway%2FTableTest.php;h=f3d955819c4e25ba6eeecf35c6e3064aa3431cf7;hb=3c8b32baaac62855e2c9f5bfdb5ede9685ce2b76;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..f3d9558 100644 --- a/tests/lib/pq/Gateway/TableTest.php +++ b/tests/lib/pq/Gateway/TableTest.php @@ -17,21 +17,20 @@ 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_TABLE_CREATE); + $this->conn->exec(PQ_TEST_REFTABLE_CREATE); + $this->conn->exec(PQ_TEST_DATA); 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_REFTABLE_DROP); + $this->conn->exec(PQ_TEST_TABLE_DROP); } - 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 +47,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() { @@ -85,4 +84,17 @@ class TableTest extends \PHPUnit_Framework_TestCase { $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" => date_create("today")->format("Y-m-d H:i:s"), + "counter" => 0, + "number" => 0, + "data" => "today" + ), $rowset->current()->getData()); + } }