5 use PHPUnit_Framework_TestCase
;
12 require_once __DIR__
."/../../../setup.inc";
14 class MapTest
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
= $this->mapper
->mapOf(TestModel
::class);
37 $this->map
->getGateway()->getQueryExecutor()->attach(new QueryLogger());
38 $this->mapper
->mapOf(RefTestModel
::class)->getGateway()->getQueryExecutor()->attach(new QueryLogger());
41 protected function tearDown() {
42 $this->conn
->exec(PQ_TEST_TEARDOWN_SQL
);
46 $row = $this->map
->getGateway()->find(["id="=>1])->current();
47 $obj = $this->map
->map($row);
48 $this->assertEquals($row->data
->get(), $obj->data
);
51 function testUnmap() {
52 $obj = new \TestModel
;
53 $obj->data
= "this is a test";
54 $this->map
->unmap($obj);
55 $this->assertSame(4, $obj->id
);
58 function testUnmapRef() {
59 $obj = new \TestModel
;
60 $obj->ref1
= $obj->ref2
= [
63 $this->map
->unmap($obj);