From: Michael Wallner Date: Mon, 21 Sep 2015 18:51:30 +0000 (+0200) Subject: first test X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=9667b439ab6355373207938e9a6fb20c68857786;p=m6w6%2Fpq-gateway first test --- diff --git a/lib/pq/Mapper/ObjectManager.php b/lib/pq/Mapper/ObjectManager.php index 0281904..e56fac2 100644 --- a/lib/pq/Mapper/ObjectManager.php +++ b/lib/pq/Mapper/ObjectManager.php @@ -31,6 +31,14 @@ class ObjectManager $this->map = $map; } + /** + * Get the map + * @return MapInterface + */ + function getMap() { + return $this->map; + } + /** * Reset all managed objects */ diff --git a/tests/lib/pq/Mapper/ObjectManagerTest.php b/tests/lib/pq/Mapper/ObjectManagerTest.php new file mode 100644 index 0000000..a73ddd4 --- /dev/null +++ b/tests/lib/pq/Mapper/ObjectManagerTest.php @@ -0,0 +1,221 @@ +conn = new Connection(PQ_TEST_DSN); + $this->conn->exec(PQ_TEST_SETUP_SQL); + Table::$defaultConnection = $this->conn; + $mapper = new Mapper; + $mapping = TestModel::mapAs($mapper); + $mapping->getGateway()->getQueryExecutor()->attach(new QueryLogger()); + $this->objectManager = new ObjectManager($mapping); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() { + + } + + public function testBasic() { + $row = $this->objectManager->getMap()->getGateway()->find(["id="=>1])->current(); + $row_id = $this->objectManager->rowId($row); + $this->assertFalse($this->objectManager->hasObject($row_id)); + $this->objectManager->createObject($row); + $this->assertTrue($this->objectManager->hasObject($row_id)); + $this->objectManager->reset(); + $this->assertFalse($this->objectManager->hasObject($row_id)); + } + + /** + * @covers pq\Mapper\ObjectManager::rowId + * @todo Implement testRowId(). + */ + public function testRowId() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers pq\Mapper\ObjectManager::objectId + * @todo Implement testObjectId(). + */ + public function testObjectId() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers pq\Mapper\ObjectManager::extractRowId + * @todo Implement testExtractRowId(). + */ + public function testExtractRowId() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers pq\Mapper\ObjectManager::serializeRowId + * @todo Implement testSerializeRowId(). + */ + public function testSerializeRowId() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers pq\Mapper\ObjectManager::hasObject + * @todo Implement testHasObject(). + */ + public function testHasObject() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers pq\Mapper\ObjectManager::createObject + * @todo Implement testCreateObject(). + */ + public function testCreateObject() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers pq\Mapper\ObjectManager::resetObject + * @todo Implement testResetObject(). + */ + public function testResetObject() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers pq\Mapper\ObjectManager::getObject + * @todo Implement testGetObject(). + */ + public function testGetObject() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers pq\Mapper\ObjectManager::getObjectById + * @todo Implement testGetObjectById(). + */ + public function testGetObjectById() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers pq\Mapper\ObjectManager::asObject + * @todo Implement testAsObject(). + */ + public function testAsObject() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers pq\Mapper\ObjectManager::hasRow + * @todo Implement testHasRow(). + */ + public function testHasRow() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers pq\Mapper\ObjectManager::createRow + * @todo Implement testCreateRow(). + */ + public function testCreateRow() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers pq\Mapper\ObjectManager::resetRow + * @todo Implement testResetRow(). + */ + public function testResetRow() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers pq\Mapper\ObjectManager::getRow + * @todo Implement testGetRow(). + */ + public function testGetRow() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @covers pq\Mapper\ObjectManager::asRow + * @todo Implement testAsRow(). + */ + public function testAsRow() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + +} diff --git a/tests/setup.inc b/tests/setup.inc index bdee9d3..3a639a5 100644 --- a/tests/setup.inc +++ b/tests/setup.inc @@ -1,5 +1,13 @@ getConnection(); - $exec->setConnection(new pq\Connection(PQ_TEST_DSN)); - $exec->execute(new \pq\Query\Writer($sql, $params), function(){}); + $exec->setConnection(new Connection(PQ_TEST_DSN)); + $exec->execute(new Writer($sql, $params), function(){}); $exec->setConnection($conn); } -class QueryLogger implements \SplObserver +class QueryLogger implements SplObserver { protected $fp; @@ -57,7 +65,7 @@ class QueryLogger implements \SplObserver $logfile = __DIR__."/query.log"; } if (!$this->fp = @fopen($logfile, "a")) { - throw new \RuntimeException(error_get_last()["message"]); + throw new RuntimeException(error_get_last()["message"]); } } @@ -67,7 +75,7 @@ class QueryLogger implements \SplObserver } } - function update(\SplSubject $executor) { + function update(SplSubject $executor) { $result = $executor->getResult(); if (isset($result)) { fprintf($this->fp, "[%s] R %s\n", @@ -81,3 +89,29 @@ class QueryLogger implements \SplObserver } } } + +class TestModel implements JsonSerializable { + private $id, $created, $counter, $number, $data, $list, $prop; + + function jsonSerialize() { + return get_object_vars($this); + } + + /** + * @param Mapper $mapper + * @return MapInterface + */ + static function mapAs(Mapper $mapper) { + return new Map( + __CLASS__, + new Table("test"), + $mapper->mapField("id"), + $mapper->mapField("created"), + $mapper->mapField("counter"), + $mapper->mapField("number"), + $mapper->mapField("data"), + $mapper->mapField("list"), + $mapper->mapField("prop") + ); + } +}