11 use UnexpectedValueException
;
13 require_once __DIR__
."/../../../setup.inc";
15 class MapperTest
extends \PHPUnit_Framework_TestCase
32 protected function setUp() {
33 $this->conn
= new Connection(PQ_TEST_DSN
);
34 $this->conn
->exec(PQ_TEST_SETUP_SQL
);
35 Table
::$defaultConnection = $this->conn
;
36 $this->mapper
= new Mapper
;
37 $this->map
= TestModel
::mapAs($this->mapper
);
38 $this->map
->getGateway()->getQueryExecutor()->attach(new QueryLogger());
41 protected function tearDown() {
42 $this->conn
->exec(PQ_TEST_TEARDOWN_SQL
);
45 function testBasic() {
46 $this->mapper
->register($this->map
);
47 $this->assertSame($this->map
, $this->mapper
->mapOf(TestModel
::class));
48 $this->assertInstanceOf(MapInterface
::class, $this->mapper
->mapOf(RefTestModel
::class));
52 * @expectedException UnexpectedValueException
54 function testMapOfException() {
55 $this->mapper
->mapOf(new stdClass
);
58 function testCreateStorage() {
59 $this->assertInstanceOf(StorageInterface
::class, $this->mapper
->createStorage(TestModel
::class));
63 * @expectedException UnexpectedValueException
65 function testCreateStorageException() {
66 $this->assertInstanceOf(StorageInterface
::class, $this->mapper
->createStorage(foo
::class));
69 function testGetReflector() {
70 $o = new RefTestModel
;
71 $r = $this->mapper
->getReflector($o, "pk1");
72 $this->assertInstanceOf("ReflectionProperty", $r);
73 $this->assertNull($r->getValue($o));
75 $this->assertSame(1, $r->getValue($o));