1
0
mirror of synced 2025-01-19 15:01:40 +03:00

[DDC-2775] Tests reproducing DDC-2775

This commit is contained in:
Matthieu Napoli 2013-11-04 12:40:51 +01:00
parent 514dd4e852
commit 8bd54be4ec
6 changed files with 192 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<?php
namespace Doctrine\Tests\Models\DDC2775;
/** @Entity */
class AdminRole extends Role
{
}

View File

@ -0,0 +1,40 @@
<?php
namespace Doctrine\Tests\Models\DDC2775;
/**
* @Entity
*/
class Authorization
{
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @ManyToOne(targetEntity="User", inversedBy="authorizations")
*/
private $user;
/**
* @ManyToOne(targetEntity="Role", inversedBy="authorizations")
*/
private $role;
public function getId()
{
return $this->id;
}
public function setUser(User $user)
{
$this->user = $user;
}
public function setRole(Role $role)
{
$this->role = $role;
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace Doctrine\Tests\Models\DDC2775;
/**
* @Entity
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="role_type", type="string")
* @DiscriminatorMap({"admin"="AdminRole"})
*/
abstract class Role
{
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @ManyToOne(targetEntity="User", inversedBy="roles")
*/
private $user;
/**
* @OneToMany(targetEntity="Authorization", mappedBy="role", cascade={"all"}, orphanRemoval=true)
*/
public $authorizations;
public function getId()
{
return $this->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);
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Doctrine\Tests\Models\DDC2775;
/** @Entity */
class User
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @OneToMany(targetEntity="Role", mappedBy="user", cascade={"all"}, orphanRemoval=true)
*/
public $roles;
/**
* @OneToMany(targetEntity="Authorization", mappedBy="user", cascade={"all"}, orphanRemoval=true)
*/
public $authorizations;
public function getId()
{
return $this->id;
}
public function addRole(Role $role)
{
$this->roles[] = $role;
$role->setUser($this);
}
public function addAuthorization(Authorization $authorization)
{
$this->authorizations[] = $authorization;
$authorization->setUser($this);
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\Models\DDC2775\AdminRole;
use Doctrine\Tests\Models\DDC2775\Authorization;
use Doctrine\Tests\Models\DDC2775\User;
/**
* Functional tests for cascade remove with class table inheritance.
*
* @author Matthieu Napoli <matthieu@mnapoli.fr>
*/
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();
}
}

View File

@ -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',
),
);
/**