From 1e57c460487b7ef5662ef44e2a0b4c7c387bfc5c Mon Sep 17 00:00:00 2001 From: Richard van Laak Date: Thu, 20 May 2021 10:59:06 +0200 Subject: [PATCH] add test to demonstrate #6499 persistence ordering bug on non-nullable cascading relationship --- .../ORM/Functional/Ticket/DDC6499Test.php | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php new file mode 100644 index 00000000000..b6bd4c0a876 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php @@ -0,0 +1,82 @@ +_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(DDC6499A::class), + $this->_em->getClassMetadata(DDC6499B::class), + ] + ); + } + + 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(): void + { + $a = new DDC6499A(); + + $this->_em->persist($a); + $this->_em->flush(); + $this->_em->clear(); + + self::assertEquals($this->_em->find(DDC6499A::class, $a->id)->b->id, $a->b->id, 'Issue #6499 will result in a Integrity constraint violation before reaching this point.'); + } +} + +/** @Entity */ +class DDC6499A +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + public $id; + + /** + * @OneToOne(targetEntity="DDC6499B", cascade={"persist"}) + * @JoinColumn(nullable=false) + */ + public $b; + + public function __construct() + { + $this->b = new DDC6499B(); + } +} + +/** @Entity */ +class DDC6499B +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + public $id; +}