[DDC-2775] Tests reproducing DDC-2775
This commit is contained in:
parent
95d000e51b
commit
65bcdbf4c7
8
tests/Doctrine/Tests/Models/DDC2775/AdminRole.php
Normal file
8
tests/Doctrine/Tests/Models/DDC2775/AdminRole.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\Models\DDC2775;
|
||||||
|
|
||||||
|
/** @Entity */
|
||||||
|
class AdminRole extends Role
|
||||||
|
{
|
||||||
|
}
|
40
tests/Doctrine/Tests/Models/DDC2775/Authorization.php
Normal file
40
tests/Doctrine/Tests/Models/DDC2775/Authorization.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
49
tests/Doctrine/Tests/Models/DDC2775/Role.php
Normal file
49
tests/Doctrine/Tests/Models/DDC2775/Role.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
40
tests/Doctrine/Tests/Models/DDC2775/User.php
Normal file
40
tests/Doctrine/Tests/Models/DDC2775/User.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
49
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php
Normal file
49
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -162,6 +162,12 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
|||||||
'Doctrine\Tests\Models\Taxi\Car',
|
'Doctrine\Tests\Models\Taxi\Car',
|
||||||
'Doctrine\Tests\Models\Taxi\Driver',
|
'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',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user