X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Flib%2Fpq%2FGateway%2FTableTest.php;h=a43634cf203114fee18a5f9a54d4ade57cce53c8;hb=b39e14404cfeac177d41b152690b6adbb2b1e4bf;hp=bee7bddcaa93f9fd4888ca12190b4e30082e2207;hpb=20d2b6bcce8f1c7a1aaa375b86ffb5be30674956;p=m6w6%2Fpq-gateway diff --git a/tests/lib/pq/Gateway/TableTest.php b/tests/lib/pq/Gateway/TableTest.php index bee7bdd..a43634c 100644 --- a/tests/lib/pq/Gateway/TableTest.php +++ b/tests/lib/pq/Gateway/TableTest.php @@ -2,11 +2,8 @@ namespace pq\Gateway; -include __DIR__."/../../../setup.inc"; +include_once __DIR__."/../../../setup.inc"; -/** - * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-03-05 at 16:08:03. - */ class TableTest extends \PHPUnit_Framework_TestCase { /** @@ -17,108 +14,84 @@ class TableTest extends \PHPUnit_Framework_TestCase { /** * @var Table */ - protected $object; + protected $table; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ 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->object = new Table(PQ_TEST_TABLE_NAME); + $this->table = new Table("test"); + $this->table->getQueryExecutor()->attach(new \QueryLogger()); } - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ protected function tearDown() { - $this->conn->exec(PQ_TEST_DROP_TABLE); + $this->conn->exec(PQ_TEST_TEARDOWN_SQL); } - /** - * Creates test data in the test table - */ - protected function createTestData() { - $this->conn->exec(PQ_TEST_CREATE_DATA); - } - - /** - * @covers pq\Gateway\Table::setRowsetPrototype - */ public function testSetRowsetPrototype() { $prop = new \ReflectionProperty("\\pq\\Gateway\\Table", "rowset"); $prop->setAccessible(true); - $this->assertEquals("\\pq\\Gateway\\Rowset", $prop->getValue($this->object)); - $this->object->setRowsetPrototype(null); - $this->assertNull($prop->getValue($this->object)); - $rowset = new \pq\Gateway\Rowset($this->object); - $this->object->setRowsetPrototype($rowset); - $this->assertSame($rowset, $prop->getValue($this->object)); + $this->assertEquals("\\pq\\Gateway\\Rowset", $prop->getValue($this->table)); + $this->table->setRowsetPrototype(null); + $this->assertNull($prop->getValue($this->table)); + $rowset = new \pq\Gateway\Rowset($this->table); + $this->table->setRowsetPrototype($rowset); + $this->assertSame($rowset, $prop->getValue($this->table)); } - /** - * @covers pq\Gateway\Table::getConnection - */ public function testGetConnection() { - $this->assertSame($this->conn, $this->object->getConnection()); + $this->assertSame($this->conn, $this->table->getConnection()); } - /** - * @covers pq\Gateway\Table::getName - */ public function testGetName() { - $this->assertSame(PQ_TEST_TABLE_NAME, $this->object->getName()); + $this->assertSame("test", $this->table->getName()); } - /** - * @covers pq\Gateway\Table::find - */ public function testFind() { - $rowset = $this->object->find(); + $rowset = $this->table->find(); $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset); - $rowset = $this->object->find(array("id = " => 1)); + $rowset = $this->table->find(array("id = " => 1)); $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset); - $rowset = $this->object->find(array("id = " => 0)); + $rowset = $this->table->find(array("id = " => 0)); $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset); - $rowset = $this->object->find(array(array("id<" => 2), array("id>" => 2))); + $rowset = $this->table->find(array(array("id<" => 2), array("id>" => 2))); $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset); } - /** - * @covers pq\Gateway\Table::create - */ public function testCreate() { - $rowset = $this->object->create(array("id" => new \pq\Query\Expr("DEFAULT"))); + $rowset = $this->table->create(array("id" => new \pq\Query\Expr("DEFAULT"))); $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset); $this->assertCount(1, $rowset); } - /** - * @covers pq\Gateway\Table::update - */ public function testUpdate() { - $row = $this->object->create(array())->current(); + $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->object->update(array("id = " => $row->id), $data)->current(); + $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()); } - /** - * @covers pq\Gateway\Table::delete - */ public function testDelete() { - $this->object->delete(array("id!=" => 0)); - $this->assertCount(0, $this->object->find()); + $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()); } - }