2010-05-15 23:32:34 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../../../TestInit.php';
|
|
|
|
|
|
|
|
class DDC440Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
|
|
{
|
2010-07-29 02:10:23 +04:00
|
|
|
|
2010-05-15 23:32:34 +04:00
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2010-07-29 02:10:23 +04:00
|
|
|
try {
|
2010-05-15 23:32:34 +04:00
|
|
|
$this->_schemaTool->createSchema(array(
|
2010-07-29 02:10:23 +04:00
|
|
|
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC440Phone'),
|
|
|
|
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC440Client')
|
2010-05-15 23:32:34 +04:00
|
|
|
));
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
// Swallow all exceptions. We do not test the schema tool here.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-440
|
|
|
|
*/
|
|
|
|
public function testOriginalEntityDataEmptyWhenProxyLoadedFromTwoAssociations()
|
|
|
|
{
|
|
|
|
|
2010-07-29 02:10:23 +04:00
|
|
|
|
|
|
|
/* The key of the problem is that the first phone is fetched via two association, main_phone and phones.
|
2011-12-20 01:56:19 +04:00
|
|
|
*
|
2010-07-29 02:10:23 +04:00
|
|
|
* You will notice that the original_entity_datas are not loaded for the first phone. (They are for the second)
|
2011-12-20 01:56:19 +04:00
|
|
|
*
|
|
|
|
* In the Client entity definition, if you define the main_phone relation after the phones relation, both assertions pass.
|
2010-07-29 02:10:23 +04:00
|
|
|
* (for the sake or this test, I defined the main_phone relation before the phones relation)
|
2011-12-20 01:56:19 +04:00
|
|
|
*
|
2010-07-29 02:10:23 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
//Initialize some data
|
2010-05-15 23:32:34 +04:00
|
|
|
$client = new DDC440Client;
|
|
|
|
$client->setName('Client1');
|
|
|
|
|
|
|
|
$phone = new DDC440Phone;
|
|
|
|
$phone->setNumber('418 111-1111');
|
|
|
|
$phone->setClient($client);
|
|
|
|
|
|
|
|
$phone2 = new DDC440Phone;
|
|
|
|
$phone2->setNumber('418 222-2222');
|
|
|
|
$phone2->setClient($client);
|
2010-07-29 02:10:23 +04:00
|
|
|
|
2010-05-15 23:32:34 +04:00
|
|
|
$client->setMainPhone($phone);
|
2010-07-29 02:10:23 +04:00
|
|
|
|
2010-05-15 23:32:34 +04:00
|
|
|
$this->_em->persist($client);
|
|
|
|
$this->_em->flush();
|
|
|
|
$id = $client->getId();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
|
|
|
$uw = $this->_em->getUnitOfWork();
|
|
|
|
$client = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC440Client', $id);
|
|
|
|
$clientPhones = $client->getPhones();
|
|
|
|
$p1 = $clientPhones[0];
|
|
|
|
$p2 = $clientPhones[1];
|
|
|
|
|
|
|
|
// Test the first phone. The assertion actually failed because original entity data is not set properly.
|
|
|
|
// This was because it is also set as MainPhone and that one is created as a proxy, not the
|
|
|
|
// original object when the find on Client is called. However loading proxies did not work correctly.
|
2011-07-26 13:38:09 +04:00
|
|
|
$this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC440Phone', $p1);
|
2010-05-15 23:32:34 +04:00
|
|
|
$originalData = $uw->getOriginalEntityData($p1);
|
|
|
|
$this->assertEquals($phone->getNumber(), $originalData['number']);
|
|
|
|
|
|
|
|
|
|
|
|
//If you comment out previous test, this one should pass
|
2011-07-26 13:38:09 +04:00
|
|
|
$this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC440Phone', $p2);
|
2010-05-15 23:32:34 +04:00
|
|
|
$originalData = $uw->getOriginalEntityData($p2);
|
|
|
|
$this->assertEquals($phone2->getNumber(), $originalData['number']);
|
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
2010-05-15 23:32:34 +04:00
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
2010-05-15 23:32:34 +04:00
|
|
|
/**
|
2010-07-29 02:10:23 +04:00
|
|
|
* @Entity
|
|
|
|
* @Table(name="phone")
|
|
|
|
*/
|
|
|
|
class DDC440Phone
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2010-05-15 23:32:34 +04:00
|
|
|
* @Column(name="id", type="integer")
|
|
|
|
* @Id
|
|
|
|
* @GeneratedValue(strategy="AUTO")
|
|
|
|
*/
|
|
|
|
protected $id;
|
2010-07-29 02:10:23 +04:00
|
|
|
/**
|
2010-05-15 23:32:34 +04:00
|
|
|
* @ManyToOne(targetEntity="DDC440Client",inversedBy="phones")
|
|
|
|
* @JoinColumns({
|
|
|
|
* @JoinColumn(name="client_id", referencedColumnName="id")
|
|
|
|
* })
|
|
|
|
*/
|
|
|
|
protected $client;
|
|
|
|
/**
|
2010-07-29 02:10:23 +04:00
|
|
|
* @Column(name="phonenumber", type="string")
|
2010-05-15 23:32:34 +04:00
|
|
|
*/
|
|
|
|
protected $number;
|
2010-07-29 02:10:23 +04:00
|
|
|
|
|
|
|
public function setNumber($value)
|
|
|
|
{
|
|
|
|
$this->number = $value;
|
2010-05-15 23:32:34 +04:00
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
|
|
|
public function getNumber()
|
|
|
|
{
|
|
|
|
return $this->number;
|
2010-05-15 23:32:34 +04:00
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
|
|
|
public function setClient(DDC440Client $value, $update_inverse=true)
|
2010-05-15 23:32:34 +04:00
|
|
|
{
|
|
|
|
$this->client = $value;
|
2010-07-29 02:10:23 +04:00
|
|
|
if ($update_inverse) {
|
|
|
|
$value->addPhone($this);
|
|
|
|
}
|
2010-05-15 23:32:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getClient()
|
|
|
|
{
|
|
|
|
return $this->client;
|
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
|
|
|
public function getId()
|
2010-05-15 23:32:34 +04:00
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
|
|
|
public function setId($value)
|
|
|
|
{
|
|
|
|
$this->id = $value;
|
2010-05-15 23:32:34 +04:00
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
2010-05-15 23:32:34 +04:00
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
2010-05-15 23:32:34 +04:00
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
* @Table(name="client")
|
|
|
|
*/
|
2010-07-29 02:10:23 +04:00
|
|
|
class DDC440Client
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2010-05-15 23:32:34 +04:00
|
|
|
* @Column(name="id", type="integer")
|
|
|
|
* @Id
|
|
|
|
* @GeneratedValue(strategy="AUTO")
|
|
|
|
*/
|
|
|
|
protected $id;
|
|
|
|
/**
|
|
|
|
* @OneToOne(targetEntity="DDC440Phone", fetch="EAGER")
|
|
|
|
* @JoinColumns({
|
|
|
|
* @JoinColumn(name="main_phone_id", referencedColumnName="id",onDelete="SET NULL")
|
|
|
|
* })
|
|
|
|
*/
|
|
|
|
protected $main_phone;
|
|
|
|
/**
|
|
|
|
* @OneToMany(targetEntity="DDC440Phone", mappedBy="client", cascade={"persist", "remove"}, fetch="EAGER")
|
2010-11-19 01:07:32 +03:00
|
|
|
* @orderBy({"number"="ASC"})
|
2010-05-15 23:32:34 +04:00
|
|
|
*/
|
|
|
|
protected $phones;
|
|
|
|
/**
|
|
|
|
* @Column(name="name", type="string")
|
|
|
|
*/
|
|
|
|
protected $name;
|
2010-07-29 02:10:23 +04:00
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2010-05-15 23:32:34 +04:00
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
|
|
|
public function setName($value)
|
|
|
|
{
|
|
|
|
$this->name = $value;
|
2010-05-15 23:32:34 +04:00
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->name;
|
2010-05-15 23:32:34 +04:00
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
2010-05-15 23:32:34 +04:00
|
|
|
public function addPhone(DDC440Phone $value)
|
|
|
|
{
|
|
|
|
$this->phones[] = $value;
|
2010-07-29 02:10:23 +04:00
|
|
|
$value->setClient($this, false);
|
2010-05-15 23:32:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getPhones()
|
|
|
|
{
|
|
|
|
return $this->phones;
|
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
|
|
|
public function setMainPhone(DDC440Phone $value)
|
|
|
|
{
|
|
|
|
$this->main_phone = $value;
|
2010-05-15 23:32:34 +04:00
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
|
|
|
public function getMainPhone()
|
|
|
|
{
|
|
|
|
return $this->main_phone;
|
2010-05-15 23:32:34 +04:00
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
|
|
|
public function getId()
|
2010-05-15 23:32:34 +04:00
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
|
|
|
public function setId($value)
|
|
|
|
{
|
|
|
|
$this->id = $value;
|
2010-05-15 23:32:34 +04:00
|
|
|
}
|
2010-07-29 02:10:23 +04:00
|
|
|
|
2010-05-15 23:32:34 +04:00
|
|
|
}
|