From dd0e02e912c45621b0928998c1d4257400681068 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Fri, 2 Jun 2023 21:28:11 +0000 Subject: [PATCH] Add test to show #7180 has been fixed Tests suggested in https://github.com/doctrine/orm/pull/7180#issuecomment-380841413 and https://github.com/doctrine/orm/pull/7180#issuecomment-381067448 by @arnaud-lb. Co-authored-by: Arnaud Le Blanc --- .../ORM/Functional/Ticket/GH7180Test.php | 217 ++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7180Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7180Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7180Test.php new file mode 100644 index 00000000000..07a9389d1b0 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7180Test.php @@ -0,0 +1,217 @@ +setUpEntitySchema([GH7180A::class, GH7180B::class, GH7180C::class, GH7180D::class, GH7180E::class, GH7180F::class, GH7180G::class]); + } + + public function testIssue(): void + { + $a = new GH7180A(); + $b = new GH7180B(); + $c = new GH7180C(); + + $a->b = $b; + $b->a = $a; + $c->a = $a; + + $this->_em->persist($a); + $this->_em->persist($b); + $this->_em->persist($c); + + $this->_em->flush(); + + self::assertIsInt($a->id); + self::assertIsInt($b->id); + self::assertIsInt($c->id); + } + + public function testIssue3NodeCycle(): void + { + $d = new GH7180D(); + $e = new GH7180E(); + $f = new GH7180F(); + $g = new GH7180G(); + + $d->e = $e; + $e->f = $f; + $f->d = $d; + $g->d = $d; + + $this->_em->persist($d); + $this->_em->persist($e); + $this->_em->persist($f); + $this->_em->persist($g); + + $this->_em->flush(); + + self::assertIsInt($d->id); + self::assertIsInt($e->id); + self::assertIsInt($f->id); + self::assertIsInt($g->id); + } +} + +/** + * @Entity + */ +class GH7180A +{ + /** + * @GeneratedValue() + * @Id @Column(type="integer") + * @var int + */ + public $id; + + /** + * @OneToOne(targetEntity=GH7180B::class, inversedBy="a") + * @JoinColumn(nullable=false) + * @var GH7180B + */ + public $b; +} + +/** + * @Entity + */ +class GH7180B +{ + /** + * @GeneratedValue() + * @Id + * @Column(type="integer") + * @var int + */ + public $id; + + /** + * @OneToOne(targetEntity=GH7180A::class, mappedBy="b") + * @JoinColumn(nullable=true) + * @var GH7180A + */ + public $a; +} + +/** + * @Entity + */ +class GH7180C +{ + /** + * @GeneratedValue() + * @Id @Column(type="integer") + * @var int + */ + public $id; + + /** + * @ManyToOne(targetEntity=GH7180A::class) + * @JoinColumn(nullable=false) + * @var GH7180A + */ + public $a; +} + +/** + * @Entity + */ +class GH7180D +{ + /** + * @GeneratedValue() + * @Id @Column(type="integer") + * @var int + */ + public $id; + + /** + * @OneToOne(targetEntity=GH7180E::class) + * @JoinColumn(nullable=false) + * @var GH7180E + */ + public $e; +} + +/** + * @Entity + */ +class GH7180E +{ + /** + * @GeneratedValue() + * @Id @Column(type="integer") + * @var int + */ + public $id; + + /** + * @OneToOne(targetEntity=GH7180F::class) + * @JoinColumn(nullable=false) + * @var GH7180F + */ + public $f; +} + +/** + * @Entity + */ +class GH7180F +{ + /** + * @GeneratedValue() + * @Id @Column(type="integer") + * @var int + */ + public $id; + + /** + * @ManyToOne(targetEntity=GH7180D::class) + * @JoinColumn(nullable=true) + * @var GH7180D + */ + public $d; +} + +/** + * @Entity + */ +class GH7180G +{ + /** + * @GeneratedValue() + * @Id @Column(type="integer") + * @var int + */ + public $id; + + /** + * @ManyToOne(targetEntity=GH7180D::class) + * @JoinColumn(nullable=false) + * @var GH7180D + */ + public $d; +}