From d48c6b596a9e62cf275580e1857a90848602fe66 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 22 Sep 2015 11:19:06 +0200 Subject: [PATCH] mapper test --- tests/lib/pq/Mapper/MapperTest.php | 75 ++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/lib/pq/Mapper/MapperTest.php diff --git a/tests/lib/pq/Mapper/MapperTest.php b/tests/lib/pq/Mapper/MapperTest.php new file mode 100644 index 0000000..fa9a4c7 --- /dev/null +++ b/tests/lib/pq/Mapper/MapperTest.php @@ -0,0 +1,75 @@ +conn = new Connection(PQ_TEST_DSN); + $this->conn->exec(PQ_TEST_SETUP_SQL); + Table::$defaultConnection = $this->conn; + $this->mapper = new Mapper; + $this->map = TestModel::mapAs($this->mapper); + } + + protected function tearDown() { + $this->conn->exec(PQ_TEST_TEARDOWN_SQL); + } + + function testBasic() { + $this->mapper->register($this->map); + $this->assertSame($this->map, $this->mapper->mapOf(TestModel::class)); + $this->assertInstanceOf(MapInterface::class, $this->mapper->mapOf(RefTestModel::class)); + } + + /** + * @expectedException UnexpectedValueException + */ + function testMapOfException() { + $this->mapper->mapOf(new stdClass); + } + + function testCreateStorage() { + $this->assertInstanceOf(StorageInterface::class, $this->mapper->createStorage(TestModel::class)); + } + + /** + * @expectedException UnexpectedValueException + */ + function testCreateStorageException() { + $this->assertInstanceOf(StorageInterface::class, $this->mapper->createStorage(foo::class)); + } + + function testGetReflector() { + $o = new RefTestModel; + $r = $this->mapper->getReflector($o, "pk1"); + $this->assertInstanceOf("ReflectionProperty", $r); + $this->assertNull($r->getValue($o)); + $r->setValue($o, 1); + $this->assertSame(1, $r->getValue($o)); + } +} -- 2.30.2