10 use UnexpectedValueException
;
12 require_once __DIR__
."/../../../setup.inc";
14 class MapperTest
extends \PHPUnit_Framework_TestCase
31 protected function setUp() {
32 $this->conn
= new Connection(PQ_TEST_DSN
);
33 $this->conn
->exec(PQ_TEST_SETUP_SQL
);
34 Table
::$defaultConnection = $this->conn
;
35 $this->mapper
= new Mapper
;
36 $this->map
= TestModel
::mapAs($this->mapper
);
39 protected function tearDown() {
40 $this->conn
->exec(PQ_TEST_TEARDOWN_SQL
);
43 function testBasic() {
44 $this->mapper
->register($this->map
);
45 $this->assertSame($this->map
, $this->mapper
->mapOf(TestModel
::class));
46 $this->assertInstanceOf(MapInterface
::class, $this->mapper
->mapOf(RefTestModel
::class));
50 * @expectedException UnexpectedValueException
52 function testMapOfException() {
53 $this->mapper
->mapOf(new stdClass
);
56 function testCreateStorage() {
57 $this->assertInstanceOf(StorageInterface
::class, $this->mapper
->createStorage(TestModel
::class));
61 * @expectedException UnexpectedValueException
63 function testCreateStorageException() {
64 $this->assertInstanceOf(StorageInterface
::class, $this->mapper
->createStorage(foo
::class));
67 function testGetReflector() {
68 $o = new RefTestModel
;
69 $r = $this->mapper
->getReflector($o, "pk1");
70 $this->assertInstanceOf("ReflectionProperty", $r);
71 $this->assertNull($r->getValue($o));
73 $this->assertSame(1, $r->getValue($o));