--- /dev/null
+<?php
+
+namespace pq\Mapper;
+
+require_once __DIR__."/../../../setup.inc";
+
+use pq\Connection;
+use pq\Gateway\Table;
+use pq\Mapper\ObjectManager;
+use QueryLogger;
+use TestModel;
+
+class ObjectManagerTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @var Connection
+ */
+ protected $conn;
+ /**
+ * @var ObjectManager
+ */
+ protected $objectManager;
+
+ /**
+ * 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 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.'
+ );
+ }
+
+}
<?php
+use pq\Connection;
+use pq\Gateway\Table;
+use pq\Mapper\Map;
+use pq\Mapper\MapInterface;
+use pq\Mapper\Mapper;
+use pq\Query\ExecutorInterface;
+use pq\Query\Writer;
+
ini_set("date.timezone", "UTC");
ini_set("error_reporting", E_ALL);
require_once __DIR__ . "/../vendor/autoload.php";
-function executeInConcurrentTransaction(\pq\Query\ExecutorInterface $exec, $sql, array $params = null) {
+function executeInConcurrentTransaction(ExecutorInterface $exec, $sql, array $params = null) {
$conn = $exec->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;
$logfile = __DIR__."/query.log";
}
if (!$this->fp = @fopen($logfile, "a")) {
- throw new \RuntimeException(error_get_last()["message"]);
+ throw new RuntimeException(error_get_last()["message"]);
}
}
}
}
- function update(\SplSubject $executor) {
+ function update(SplSubject $executor) {
$result = $executor->getResult();
if (isset($result)) {
fprintf($this->fp, "[%s] R %s\n",
}
}
}
+
+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")
+ );
+ }
+}