Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC168Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 use Doctrine\Tests\Models\Company\CompanyEmployee;
6
7 require_once __DIR__ . '/../../../TestInit.php';
8
9 class DDC168Test extends \Doctrine\Tests\OrmFunctionalTestCase
10 {
11     protected $oldMetadata;
12
13     protected function setUp() {
14         $this->useModelSet('company');
15         parent::setUp();
16
17         $this->oldMetadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee');
18
19         $metadata = clone $this->oldMetadata;
20         ksort($metadata->reflFields);
21         $this->_em->getMetadataFactory()->setMetadataFor('Doctrine\Tests\Models\Company\CompanyEmployee', $metadata);
22     }
23
24     public function tearDown()
25     {
26         $this->_em->getMetadataFactory()->setMetadataFor('Doctrine\Tests\Models\Company\CompanyEmployee', $this->oldMetadata);
27         parent::tearDown();
28     }
29
30     /**
31      * @group DDC-168
32      */
33     public function testJoinedSubclassPersisterRequiresSpecificOrderOfMetadataReflFieldsArray()
34     {
35         //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
36
37         $spouse = new CompanyEmployee;
38         $spouse->setName("Blub");
39         $spouse->setDepartment("Accounting");
40         $spouse->setSalary(500);
41
42         $employee = new CompanyEmployee;
43         $employee->setName("Foo");
44         $employee->setDepartment("bar");
45         $employee->setSalary(1000);
46         $employee->setSpouse($spouse);
47
48         $this->_em->persist($spouse);
49         $this->_em->persist($employee);
50
51         $this->_em->flush();
52         $this->_em->clear();
53
54         $q = $this->_em->createQuery("SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e WHERE e.name = ?1");
55         $q->setParameter(1, "Foo");
56         $theEmployee = $q->getSingleResult();
57
58         $this->assertEquals("bar", $theEmployee->getDepartment());
59         $this->assertEquals("Foo", $theEmployee->getName());
60         $this->assertEquals(1000, $theEmployee->getSalary());
61         $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $theEmployee);
62         $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $theEmployee->getSpouse());
63     }
64 }