diff --git a/tests/Tests/ORM/Functional/Ticket/GH5665CommitOrderTest.php b/tests/Tests/ORM/Functional/Ticket/GH5665CommitOrderTest.php new file mode 100644 index 00000000000..487fe371bb3 --- /dev/null +++ b/tests/Tests/ORM/Functional/Ticket/GH5665CommitOrderTest.php @@ -0,0 +1,116 @@ +setUpEntitySchema([GH5665CommitOrderItem::class, GH5665CommitOrderSubitem::class]); + } + + public function testIssue(): void + { + $item = new GH5665CommitOrderItem(); + $sub1 = new GH5665CommitOrderSubitem(); + $sub2 = new GH5665CommitOrderSubitem(); + $item->addItem($sub1); + $item->addItem($sub2); + $item->featuredItem = $sub2; + $this->_em->persist($item); + $this->_em->flush(); + + $this->expectNotToPerformAssertions(); + + $this->_em->remove($item); + $this->_em->flush(); + } +} + +/** + * @ORM\Entity + */ +class GH5665CommitOrderItem +{ + /** + * @ORM\Column(name="id", type="integer") + * @ORM\Id + * @ORM\GeneratedValue(strategy="AUTO") + * + * @var int + */ + public $id; + + /** + * @ORM\OneToMany(targetEntity="GH5665CommitOrderSubitem", mappedBy="item", cascade={"all"}, orphanRemoval=true) + * + * @var Collection + */ + public $items; + + /** + * @ORM\ManyToOne(targetEntity="GH5665CommitOrderSubitem") + * + * Adding the following would make the test pass, since it shifts responsibility for + * NULLing references to the DB layer. The #5665 issue is about the request that this + * happen on the ORM level. + * > @-ORM\JoinColumn(onDelete="SET NULL") + * + * @var GH5665CommitOrderSubitem + */ + public $featuredItem; + + public function __construct() + { + $this->items = new ArrayCollection(); + } + + public function addItem(GH5665CommitOrderSubitem $item) + { + $this->items[] = $item; + $item->item = $this; + } +} + +/** + * @ORM\Entity + */ +class GH5665CommitOrderSubitem +{ + /** + * @ORM\Column(name="id", type="integer") + * @ORM\Id + * @ORM\GeneratedValue(strategy="AUTO") + * + * @var integer + */ + public $id; + + /** + * @var GH5665CommitOrderItem + * + * @ORM\ManyToOne(targetEntity="GH5665CommitOrderItem", inversedBy="items") + */ + public $item; +}