From 8f75d7b11676a27e21b5f82ba9d6e60d3a57bc58 Mon Sep 17 00:00:00 2001 From: Andrea Sprega Date: Fri, 24 Oct 2014 23:10:37 +0200 Subject: [PATCH 1/2] [DDC-3343] Failing test case --- .../ORM/Functional/Ticket/DDC3343Test.php | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3343Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3343Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3343Test.php new file mode 100644 index 00000000000..c8a1f73592a --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3343Test.php @@ -0,0 +1,92 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3343User'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3343Group'), + )); + + // Save a group and an associated user (in an extra lazy association) + $group = new DDC3343Group(); + $user = new DDC3343User(); + + $group->users->add($user); + + $this->_em->persist($group); + $this->_em->persist($user); + $this->_em->flush(); + + // Fetch the group and the user again and remove the user from the collection. + $this->_em->clear(); + + $group = $this->_em->find(__NAMESPACE__ . '\DDC3343Group', $group->id); + $user = $this->_em->find(__NAMESPACE__ . '\DDC3343User', $user->id); + + $group->users->removeElement($user); + + $this->_em->persist($group); + $this->_em->flush(); + + // Even if the collection is extra lazy, the user should not have been deleted. + $this->_em->clear(); + + $user = $this->_em->find(__NAMESPACE__ . '\DDC3343User', $user->id); + $this->assertNotNull($user); + } +} + +/** + * @Entity + */ +class DDC3343User +{ + /** + * @Id + * @GeneratedValue + * @Column(type="integer") + */ + public $id; + + /** + * @ManyToOne(targetEntity="DDC3343Group", inversedBy="users") + */ + protected $group; +} + +/** + * @Entity + */ +class DDC3343Group +{ + /** + * @Id + * @GeneratedValue + * @Column(type="integer") + */ + public $id; + + /** + * @OneToMany(targetEntity="DDC3343User", mappedBy="group", fetch="EXTRA_LAZY") + */ + public $users; + + public function __construct() + { + $this->users = new ArrayCollection(); + } +} From 9688551a9c351cfb232a6c9bb26976f3669b9cf6 Mon Sep 17 00:00:00 2001 From: Andrea Sprega Date: Sat, 25 Oct 2014 00:02:57 +0200 Subject: [PATCH 2/2] [DDC-3343] Failing test case (updated) --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3343Test.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3343Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3343Test.php index c8a1f73592a..c6db00bef6a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3343Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3343Test.php @@ -39,14 +39,11 @@ public function testEntityNotDeletedWhenRemovedFromExtraLazyAssociation() $group->users->removeElement($user); - $this->_em->persist($group); - $this->_em->flush(); - - // Even if the collection is extra lazy, the user should not have been deleted. + // Even though the collection is extra lazy, the user should not have been deleted. $this->_em->clear(); $user = $this->_em->find(__NAMESPACE__ . '\DDC3343User', $user->id); - $this->assertNotNull($user); + $this->assertInstanceOf(__NAMESPACE__ . '\DDC3343User', $user); } }