diff --git a/tests/Doctrine/Tests/Models/DDC2775/AdminRole.php b/tests/Doctrine/Tests/Models/DDC2775/AdminRole.php new file mode 100644 index 000000000..d40bb625a --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC2775/AdminRole.php @@ -0,0 +1,8 @@ +id; + } + + public function setUser(User $user) + { + $this->user = $user; + } + + public function setRole(Role $role) + { + $this->role = $role; + } +} diff --git a/tests/Doctrine/Tests/Models/DDC2775/Role.php b/tests/Doctrine/Tests/Models/DDC2775/Role.php new file mode 100644 index 000000000..7812b2e89 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC2775/Role.php @@ -0,0 +1,49 @@ +id; + } + + public function getUser() + { + return $this->user; + } + + public function setUser(User $user) + { + $this->user = $user; + } + + public function addAuthorization(Authorization $authorization) + { + $this->authorizations[] = $authorization; + $authorization->setRole($this); + } +} diff --git a/tests/Doctrine/Tests/Models/DDC2775/User.php b/tests/Doctrine/Tests/Models/DDC2775/User.php new file mode 100644 index 000000000..07b1b09be --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC2775/User.php @@ -0,0 +1,40 @@ +id; + } + + public function addRole(Role $role) + { + $this->roles[] = $role; + $role->setUser($this); + } + + public function addAuthorization(Authorization $authorization) + { + $this->authorizations[] = $authorization; + $authorization->setUser($this); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php new file mode 100644 index 000000000..f8259f7c8 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php @@ -0,0 +1,49 @@ + + */ +class DDC2775Test extends \Doctrine\Tests\OrmFunctionalTestCase +{ + protected function setUp() { + $this->useModelSet('ddc2775'); + parent::setUp(); + } + + /** + * @group DDC-2775 + */ + public function testIssueCascadeRemove() + { + $user = new User(); + + $role = new AdminRole(); + $user->addRole($role); + + $authorization = new Authorization(); + $user->addAuthorization($authorization); + $role->addAuthorization($authorization); + + $this->_em->persist($user); + $this->_em->flush(); + + // Need to clear so that associations are lazy-loaded + $this->_em->clear(); + + $user = $this->_em->find('Doctrine\Tests\Models\DDC2775\User', $user->getId()); + + $this->_em->remove($user); + $this->_em->flush(); + + // With the bug, the second flush throws an error because the cascade remove didn't work correctly + $this->_em->flush(); + } +} diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index d2a41cfb9..57fad7db7 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -162,6 +162,12 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\Taxi\Car', 'Doctrine\Tests\Models\Taxi\Driver', ), + 'ddc2775' => array( + 'Doctrine\Tests\Models\DDC2775\User', + 'Doctrine\Tests\Models\DDC2775\Role', + 'Doctrine\Tests\Models\DDC2775\AdminRole', + 'Doctrine\Tests\Models\DDC2775\Authorization', + ), ); /**