DDC-2931 - cleaning up code formatting/simplifying test case
This commit is contained in:
parent
72d838a804
commit
157c793810
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||||
|
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../TestInit.php';
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -14,71 +12,51 @@ class DDC2931Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->_schemaTool->createSchema(array(
|
$this->_schemaTool->createSchema(array(
|
||||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2931User'),
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2931User'),
|
||||||
));
|
));
|
||||||
} catch(\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
// no action needed - schema seems to be already in place
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIssue()
|
public function testIssue()
|
||||||
{
|
{
|
||||||
$first = new DDC2931User(null);
|
$first = new DDC2931User();
|
||||||
|
$second = new DDC2931User();
|
||||||
|
$third = new DDC2931User();
|
||||||
|
|
||||||
|
$second->parent = $first;
|
||||||
|
$third->parent = $second;
|
||||||
|
|
||||||
$this->_em->persist($first);
|
$this->_em->persist($first);
|
||||||
|
|
||||||
$second = new DDC2931User($first);
|
|
||||||
$this->_em->persist($second);
|
$this->_em->persist($second);
|
||||||
|
|
||||||
$third = new DDC2931User($second);
|
|
||||||
$this->_em->persist($third);
|
$this->_em->persist($third);
|
||||||
|
|
||||||
|
|
||||||
$this->_em->flush();
|
$this->_em->flush();
|
||||||
$this->_em->clear();
|
$this->_em->clear();
|
||||||
|
|
||||||
// Load Entity in second order
|
// Load Entity in second order
|
||||||
$second = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC2931User', $second->getId());
|
$second = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC2931User', $second->id);
|
||||||
// crash here with "Segmentation error" caused by infinite loop. This work correctly with doctrine 2.3
|
$this->assertSame(2, $second->getRank());
|
||||||
$second->getRank();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/** @Entity */
|
||||||
* @Entity
|
|
||||||
*/
|
|
||||||
class DDC2931User
|
class DDC2931User
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */
|
||||||
* @Id
|
public $id;
|
||||||
* @Column(type="integer")
|
|
||||||
* @GeneratedValue(strategy="AUTO")
|
|
||||||
*/
|
|
||||||
protected $id;
|
|
||||||
|
|
||||||
/**
|
/** @OneToOne(targetEntity="DDC2931User", inversedBy="child") */
|
||||||
*
|
public $parent;
|
||||||
* @OneToOne(targetEntity="DDC2931User", inversedBy="child")
|
|
||||||
* @JoinColumn(name="parent_id", referencedColumnName="id", nullable = true)
|
|
||||||
**/
|
|
||||||
protected $parent;
|
|
||||||
|
|
||||||
/**
|
/** @OneToOne(targetEntity="DDC2931User", mappedBy="parent") */
|
||||||
* @OneToOne(targetEntity="DDC2931User", mappedBy="parent")
|
public $child;
|
||||||
**/
|
|
||||||
protected $child;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructeur.
|
|
||||||
*/
|
|
||||||
public function __construct ($parent = null)
|
|
||||||
{
|
|
||||||
$this->parent = $parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Rank recursively
|
* Return Rank recursively
|
||||||
@ -87,81 +65,6 @@ class DDC2931User
|
|||||||
*/
|
*/
|
||||||
public function getRank()
|
public function getRank()
|
||||||
{
|
{
|
||||||
if($this->parent == null)
|
return 1 + ($this->parent ? $this->parent->getRank() : 0);
|
||||||
return 1;
|
|
||||||
return 1 + $this->parent->getRank();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the $id
|
|
||||||
*/
|
|
||||||
public function getId ()
|
|
||||||
{
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the $parent
|
|
||||||
*/
|
|
||||||
public function getParent ()
|
|
||||||
{
|
|
||||||
return $this->parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param integer $id
|
|
||||||
*/
|
|
||||||
public function setId ($id)
|
|
||||||
{
|
|
||||||
$this->id = $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param DDC2931User $parent
|
|
||||||
*/
|
|
||||||
public function setParent ($parent)
|
|
||||||
{
|
|
||||||
$this->parent = $parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the $child
|
|
||||||
*/
|
|
||||||
public function getChild ()
|
|
||||||
{
|
|
||||||
return $this->child;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param DDC2931User $child
|
|
||||||
*/
|
|
||||||
public function setChild ($child)
|
|
||||||
{
|
|
||||||
$this->child = $child;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Magic getter to expose protected properties.
|
|
||||||
*
|
|
||||||
* @param string $property
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function __get ($property)
|
|
||||||
{
|
|
||||||
return $this->$property;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Magic setter to save protected properties.
|
|
||||||
*
|
|
||||||
* @param string $property
|
|
||||||
* @param mixed $value
|
|
||||||
*/
|
|
||||||
public function __set ($property, $value)
|
|
||||||
{
|
|
||||||
$this->$property = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user