Skip to content

Commit

Permalink
-- Transformed into a minimal example.
Browse files Browse the repository at this point in the history
-- Processed Ocramius' feedback.
  • Loading branch information
Frikkle authored and Ocramius committed Aug 11, 2017
1 parent db2530d commit da3cd04
Showing 1 changed file with 43 additions and 107 deletions.
150 changes: 43 additions & 107 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DDC6499Test extends OrmFunctionalTestCase
/**
* {@inheritDoc}
*/
protected function setUp()
protected function setUp() : void
{
parent::setUp();

Expand All @@ -25,148 +25,84 @@ protected function setUp()
);
}

/**
* {@inheritDoc}
*/
protected function tearDown() : void
{
parent::tearDown();

$this->_schemaTool->dropSchema(
[
$this->_em->getClassMetadata(DDC6499A::class),
$this->_em->getClassMetadata(DDC6499B::class),
]
);
}

/**
* Test for the bug described in issue #6499.
*/
public function testIssue()
public function testIssue() : void
{
$a = new DDC6499A();
$this->_em->persist($a);

$b = new DDC6499B();
$a->setB($b);
$a->b = $b;
$this->_em->persist($b);

$this->_em->flush();
$this->_em->clear();

// Issue #6499 will result in a Integrity constraint violation before reaching this point
$this->assertEquals(true, true);
self::assertEquals($this->_em->find(DDC6499A::class, $a->id)->b->id, $b->id, "Issue #6499 will result in a Integrity constraint violation before reaching this point.");
}
}

/** @Entity */
class DDC6499A
{
/**
* @Id()
* @GeneratedValue(strategy="AUTO")
* @Column(name="id", type="integer")
* Test for the bug described in issue #6499 (reversed order).
*/
private $id;

/**
* @OneToMany(targetEntity="DDC6499B", mappedBy="a", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $bs;

/**
* @OneToOne(targetEntity="DDC6499B", cascade={"persist"})
* @JoinColumn(nullable=false)
*/
private $b;

/**
* DDC6499A constructor.
*/
public function __construct()
{
$this->bs = new ArrayCollection();
}

/**
* @return int
*/
public function getId()
public function testIssueReversed() : void
{
return $this->id;
}

/**
* @return DDC6499B[]|ArrayCollection
*/
public function getBs()
{
return $this->bs;
}

/**
* @param DDC6499B $b
*/
public function addB(DDC6499B $b)
{
if ($this->bs->contains($b)) return;

$this->bs->add($b);
$a = new DDC6499A();

// Update owning side
$b->setA($this);
}
$b = new DDC6499B();
$a->b = $b;

/**
* @param DDC6499B $b
*/
public function removeB(DDC6499B $b)
{
if (!$this->bs->contains($b)) return;
$this->_em->persist($b);
$this->_em->persist($a);

$this->bs->removeElement($b);
$this->_em->flush();
$this->_em->clear();

// Not updating owning side due to orphan removal
self::assertEquals($this->_em->find(DDC6499A::class, $a->id)->b->id, $b->id, "Issue #6499 will result in a Integrity constraint violation before reaching this point.");
}
}

/** @Entity */
class DDC6499A
{
/**
* @return DDC6499B
* @Id @Column(type="integer") @GeneratedValue
*/
public function getB()
{
return $this->b;
}
public $id;

/**
* @param DDC6499B $b
* @OneToOne(targetEntity="DDC6499B")
* @JoinColumn(nullable=false)
*/
public function setB(DDC6499B $b)
{
$this->b = $b;
}
public $b;
}

/** @Entity */
class DDC6499B
{
/**
* @Id()
* @GeneratedValue(strategy="AUTO")
* @Column(name="id", type="integer")
*/
private $id;

/**
* @ManyToOne(targetEntity="DDC6499A", inversedBy="bs", cascade={"persist"})
*/
private $a;

/**
* @return int
* @Id @Column(type="integer") @GeneratedValue
*/
public function getId()
{
return $this->id;
}
public $id;

/**
* @return DDC6499A
* @ManyToOne(targetEntity="DDC6499A", inversedBy="bs")
*/
public function getA()
{
return $this->a;
}

/**
* @param DDC6499A $a
*/
public function setA(DDC6499A $a)
{
$this->a = $a;
}
public $a;
}

0 comments on commit da3cd04

Please # to comment.