From 110078d9ae083814fdeba568a741b85cb70485d0 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Mon, 27 Feb 2023 20:07:49 +0000 Subject: [PATCH] Cherry-pick (and slightly simplify) tests from #9377 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Josef Å upka --- .../ORM/Functional/Ticket/GH9376Test.php | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH9376Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH9376Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH9376Test.php new file mode 100644 index 00000000000..672918c5c36 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH9376Test.php @@ -0,0 +1,133 @@ +_schemaTool->createSchema([ + $this->_em->getClassMetadata(GH9376GiftVariant::class), + $this->_em->getClassMetadata(GH9376Product::class), + $this->_em->getClassMetadata(GH9376Gift::class), + ]); + } + + protected function tearDown(): void + { + $this->_schemaTool->dropSchema([ + $this->_em->getClassMetadata(GH9376GiftVariant::class), + $this->_em->getClassMetadata(GH9376Product::class), + $this->_em->getClassMetadata(GH9376Gift::class), + ]); + + parent::tearDown(); + } + + public function testRemoveCircularRelatedEntities(): void + { + if (! $this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) { + self::markTestSkipped('Platform does not support foreign keys.'); + } + + $product = new GH9376Product(); + $gift = new GH9376Gift($product); + $giftVariant = new GH9376GiftVariant($gift); + + $this->_em->persist($product); + $this->_em->persist($gift); + $this->_em->persist($giftVariant); + $this->_em->flush(); + $this->_em->clear(); + + $persistedGiftVariant = $this->_em->find(GH9376GiftVariant::class, 1); + $this->_em->remove($persistedGiftVariant); + + $persistedGift = $this->_em->find(GH9376Gift::class, 1); + $this->_em->remove($persistedGift); + + $this->_em->flush(); + $this->_em->clear(); + + self::assertEmpty($this->_em->getRepository(GH9376Gift::class)->findAll()); + self::assertEmpty($this->_em->getRepository(GH9376GiftVariant::class)->findAll()); + } +} + +/** + * @Entity + */ +class GH9376GiftVariant +{ + /** + * @var int + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + public $id; + + /** + * @ORM\ManyToOne(targetEntity=GH9376Gift::class) + * @ORM\JoinColumn(nullable=false) + * + * @var GH9376Gift + */ + public $gift; + + public function __construct(GH9376Gift $gift) + { + $this->gift = $gift; + } +} + +/** + * @Entity + */ + +class GH9376Product +{ + /** + * @var int + * @Id @Column(type="integer") + * @GeneratedValue + */ + public $id; +} + +/** + * @Entity + */ +class GH9376Gift +{ + /** + * @var int + * @Id @Column(type="integer") + * @GeneratedValue + */ + public $id; + + /** + * @ORM\ManyToOne(targetEntity=GH9376Product::class) + * @ORM\JoinColumn(nullable=false) + * + * @var GH9376Product + */ + public $product; + + public function __construct(GH9376Product $product) + { + $this->product = $product; + } +}