2011-11-09 22:09:35 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
2016-05-11 01:55:12 +07:00
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
2011-11-09 22:09:35 +01:00
|
|
|
|
2016-05-11 01:55:12 +07:00
|
|
|
class DDC1258Test extends OrmFunctionalTestCase
|
2011-11-09 22:09:35 +01:00
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2016-12-07 23:33:41 +01:00
|
|
|
$this->_schemaTool->createSchema(
|
|
|
|
[
|
2016-12-08 18:01:04 +01:00
|
|
|
$this->_em->getClassMetadata(TestEntity::class),
|
|
|
|
$this->_em->getClassMetadata(TestAdditionalEntity::class)
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
);
|
2011-11-09 22:09:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIssue()
|
|
|
|
{
|
|
|
|
$testEntity = new TestEntity();
|
|
|
|
$testEntity->setValue(3);
|
|
|
|
$testEntity->setAdditional(new TestAdditionalEntity());
|
|
|
|
$this->_em->persist($testEntity);
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
|
|
|
// So here the value is 3
|
|
|
|
$this->assertEquals(3, $testEntity->getValue());
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$test = $this->_em->getRepository(TestEntity::class)->find(1);
|
2011-11-09 22:09:35 +01:00
|
|
|
|
|
|
|
// New value is set
|
|
|
|
$test->setValue(5);
|
|
|
|
|
|
|
|
// So here the value is 5
|
|
|
|
$this->assertEquals(5, $test->getValue());
|
|
|
|
|
|
|
|
// Get the additional entity
|
|
|
|
$additional = $test->getAdditional();
|
|
|
|
|
|
|
|
// Still 5..
|
|
|
|
$this->assertEquals(5, $test->getValue());
|
|
|
|
|
|
|
|
// Force the proxy to load
|
|
|
|
$additional->getBool();
|
|
|
|
|
|
|
|
// The value should still be 5
|
|
|
|
$this->assertEquals(5, $test->getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class TestEntity
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Id
|
|
|
|
* @Column(type="integer")
|
|
|
|
* @GeneratedValue(strategy="AUTO")
|
|
|
|
*/
|
|
|
|
protected $id;
|
|
|
|
/**
|
|
|
|
* @Column(type="integer")
|
|
|
|
*/
|
|
|
|
protected $value;
|
|
|
|
/**
|
|
|
|
* @OneToOne(targetEntity="TestAdditionalEntity", inversedBy="entity", orphanRemoval=true, cascade={"persist", "remove"})
|
|
|
|
*/
|
|
|
|
protected $additional;
|
|
|
|
|
|
|
|
public function getValue()
|
|
|
|
{
|
|
|
|
return $this->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setValue($value)
|
|
|
|
{
|
|
|
|
$this->value = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAdditional()
|
|
|
|
{
|
|
|
|
return $this->additional;
|
|
|
|
}
|
2011-12-19 22:56:19 +01:00
|
|
|
|
2011-11-09 22:09:35 +01:00
|
|
|
public function setAdditional($additional)
|
|
|
|
{
|
|
|
|
$this->additional = $additional;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class TestAdditionalEntity
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Id
|
|
|
|
* @Column(type="integer")
|
|
|
|
* @GeneratedValue(strategy="AUTO")
|
|
|
|
*/
|
|
|
|
protected $id;
|
|
|
|
/**
|
|
|
|
* @OneToOne(targetEntity="TestEntity", mappedBy="additional")
|
|
|
|
*/
|
|
|
|
protected $entity;
|
|
|
|
/**
|
|
|
|
* @Column(type="boolean")
|
|
|
|
*/
|
|
|
|
protected $bool;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->bool = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBool()
|
|
|
|
{
|
|
|
|
return $this->bool;
|
|
|
|
}
|
2011-12-19 22:56:19 +01:00
|
|
|
|
2011-11-09 22:09:35 +01:00
|
|
|
public function setBool($bool)
|
|
|
|
{
|
|
|
|
$this->bool = $bool;
|
|
|
|
}
|
|
|
|
}
|