3 namespace Doctrine\Tests\ORM\Functional\Ticket;
5 require_once __DIR__ . '/../../../TestInit.php';
7 class DDC440Test extends \Doctrine\Tests\OrmFunctionalTestCase
10 protected function setUp()
14 $this->_schemaTool->createSchema(array(
15 $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC440Phone'),
16 $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC440Client')
18 } catch (\Exception $e) {
19 // Swallow all exceptions. We do not test the schema tool here.
26 public function testOriginalEntityDataEmptyWhenProxyLoadedFromTwoAssociations()
30 /* The key of the problem is that the first phone is fetched via two association, main_phone and phones.
32 * You will notice that the original_entity_datas are not loaded for the first phone. (They are for the second)
34 * In the Client entity definition, if you define the main_phone relation after the phones relation, both assertions pass.
35 * (for the sake or this test, I defined the main_phone relation before the phones relation)
39 //Initialize some data
40 $client = new DDC440Client;
41 $client->setName('Client1');
43 $phone = new DDC440Phone;
44 $phone->setNumber('418 111-1111');
45 $phone->setClient($client);
47 $phone2 = new DDC440Phone;
48 $phone2->setNumber('418 222-2222');
49 $phone2->setClient($client);
51 $client->setMainPhone($phone);
53 $this->_em->persist($client);
55 $id = $client->getId();
58 $uw = $this->_em->getUnitOfWork();
59 $client = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC440Client', $id);
60 $clientPhones = $client->getPhones();
61 $p1 = $clientPhones[0];
62 $p2 = $clientPhones[1];
64 // Test the first phone. The assertion actually failed because original entity data is not set properly.
65 // This was because it is also set as MainPhone and that one is created as a proxy, not the
66 // original object when the find on Client is called. However loading proxies did not work correctly.
67 $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC440Phone', $p1);
68 $originalData = $uw->getOriginalEntityData($p1);
69 $this->assertEquals($phone->getNumber(), $originalData['number']);
72 //If you comment out previous test, this one should pass
73 $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC440Phone', $p2);
74 $originalData = $uw->getOriginalEntityData($p2);
75 $this->assertEquals($phone2->getNumber(), $originalData['number']);
82 * @Table(name="phone")
88 * @Column(name="id", type="integer")
90 * @GeneratedValue(strategy="AUTO")
94 * @ManyToOne(targetEntity="DDC440Client",inversedBy="phones")
96 * @JoinColumn(name="client_id", referencedColumnName="id")
101 * @Column(name="phonenumber", type="string")
105 public function setNumber($value)
107 $this->number = $value;
110 public function getNumber()
112 return $this->number;
115 public function setClient(DDC440Client $value, $update_inverse=true)
117 $this->client = $value;
118 if ($update_inverse) {
119 $value->addPhone($this);
123 public function getClient()
125 return $this->client;
128 public function getId()
133 public function setId($value)
142 * @Table(name="client")
148 * @Column(name="id", type="integer")
150 * @GeneratedValue(strategy="AUTO")
154 * @OneToOne(targetEntity="DDC440Phone", fetch="EAGER")
156 * @JoinColumn(name="main_phone_id", referencedColumnName="id",onDelete="SET NULL")
159 protected $main_phone;
161 * @OneToMany(targetEntity="DDC440Phone", mappedBy="client", cascade={"persist", "remove"}, fetch="EAGER")
162 * @orderBy({"number"="ASC"})
166 * @Column(name="name", type="string")
170 public function __construct()
175 public function setName($value)
177 $this->name = $value;
180 public function getName()
185 public function addPhone(DDC440Phone $value)
187 $this->phones[] = $value;
188 $value->setClient($this, false);
191 public function getPhones()
193 return $this->phones;
196 public function setMainPhone(DDC440Phone $value)
198 $this->main_phone = $value;
201 public function getMainPhone()
203 return $this->main_phone;
206 public function getId()
211 public function setId($value)