Merge pull request #6774 from greg0ire/proove_orphan_removal_is_useless
Proove orphan removal is useless
This commit is contained in:
commit
87a6d0b77e
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\OrnementalOrphanRemoval;
|
||||
|
||||
class Person
|
||||
{
|
||||
public $id;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\OrnementalOrphanRemoval;
|
||||
|
||||
class PhoneNumber
|
||||
{
|
||||
public $id;
|
||||
|
||||
public $person;
|
||||
public $phonenumber;
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
|
||||
use Doctrine\DBAL\Driver\Connection;
|
||||
use Doctrine\ORM\Mapping\Driver\XmlDriver;
|
||||
use Doctrine\Tests\Models\OrnementalOrphanRemoval\PhoneNumber;
|
||||
use Doctrine\Tests\Models\OrnementalOrphanRemoval\Person;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* Tests a unidirectional many-to-one association mapping with orphan removal.
|
||||
*/
|
||||
class ManyToOneOrphanRemovalTest extends OrmFunctionalTestCase
|
||||
{
|
||||
private $personId;
|
||||
|
||||
protected static $_modelSets = [
|
||||
'ornemental_orphan_removal' => [
|
||||
Person::class,
|
||||
PhoneNumber::class,
|
||||
]
|
||||
];
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->useModelSet('ornemental_orphan_removal');
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$person = new Person;
|
||||
$person->id = 'ca41a293-799f-4d68-bf79-626c3ad223ec';
|
||||
|
||||
$phone1 = new PhoneNumber;
|
||||
$phone1->id = 'f4132478-c492-4dfe-aab5-a5b79ae129e7';
|
||||
$phone1->phonenumber = '123456';
|
||||
|
||||
$phone2 = new PhoneNumber;
|
||||
$phone2->id = '7faa4cd3-a155-4fbf-bc42-aa4269a4454d';
|
||||
$phone2->phonenumber = '234567';
|
||||
|
||||
$phone1->person = $person;
|
||||
$phone2->person = $person;
|
||||
|
||||
$this->_em->persist($phone1);
|
||||
$this->_em->persist($phone2);
|
||||
$this->_em->persist($person);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->personId = $person->id;
|
||||
$this->_em->clear();
|
||||
}
|
||||
|
||||
public function testOrphanRemovalIsPurelyOrnemental()
|
||||
{
|
||||
$person = $this->_em->getReference(Person::class, $this->personId);
|
||||
|
||||
$this->_em->remove($person);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$query = $this->_em->createQuery(
|
||||
'SELECT u FROM Doctrine\Tests\Models\OrnementalOrphanRemoval\Person u'
|
||||
);
|
||||
$result = $query->getResult();
|
||||
|
||||
$this->assertEquals(0, count($result), 'Person should be removed by EntityManager');
|
||||
|
||||
$query = $this->_em->createQuery(
|
||||
'SELECT p FROM Doctrine\Tests\Models\OrnementalOrphanRemoval\PhoneNumber p'
|
||||
);
|
||||
$result = $query->getResult();
|
||||
|
||||
$this->assertEquals(2, count($result), 'Orphan removal should not kick in');
|
||||
}
|
||||
|
||||
protected function _getEntityManager(
|
||||
Connection $connection = null,
|
||||
MappingDriver $mappingDriver = null
|
||||
) {
|
||||
return parent::_getEntityManager($connection, new XmlDriver(
|
||||
__DIR__.DIRECTORY_SEPARATOR.'xml'
|
||||
));
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping
|
||||
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
|
||||
<entity name="Doctrine\Tests\Models\OrnementalOrphanRemoval\Person" table="ornemental_orphan_removal_person">
|
||||
<id name="id" column="id">
|
||||
<generator strategy="NONE" />
|
||||
</id>
|
||||
</entity>
|
||||
</doctrine-mapping>
|
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping
|
||||
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
|
||||
<entity name="Doctrine\Tests\Models\OrnementalOrphanRemoval\PhoneNumber" table="ornemental_orphan_removal_phone_number">
|
||||
<id name="id" column="id">
|
||||
<generator strategy="NONE" />
|
||||
</id>
|
||||
<many-to-one target-entity="Doctrine\Tests\Models\OrnementalOrphanRemoval\Person" field="person" orphan-removal="true" >
|
||||
<join-column on-delete="SET NULL" />
|
||||
</many-to-one>
|
||||
</entity>
|
||||
</doctrine-mapping>
|
@ -3,6 +3,7 @@
|
||||
namespace Doctrine\Tests;
|
||||
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
|
||||
use Doctrine\DBAL\Driver\Connection;
|
||||
use Doctrine\DBAL\Driver\PDOSqlite\Driver as SqliteDriver;
|
||||
use Doctrine\DBAL\Logging\DebugStack;
|
||||
@ -488,6 +489,11 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
$conn->executeUpdate('DELETE FROM ddc3346_users');
|
||||
}
|
||||
|
||||
if (isset($this->_usedModelSets['ornemental_orphan_removal'])) {
|
||||
$conn->executeUpdate('DELETE FROM ornemental_orphan_removal_person');
|
||||
$conn->executeUpdate('DELETE FROM ornemental_orphan_removal_phone_number');
|
||||
}
|
||||
|
||||
if (isset($this->_usedModelSets['quote'])) {
|
||||
$conn->executeUpdate(
|
||||
sprintf(
|
||||
@ -678,7 +684,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
*
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
*/
|
||||
protected function _getEntityManager(Connection $connection = null) {
|
||||
protected function _getEntityManager(
|
||||
Connection $connection = null,
|
||||
MappingDriver $mappingDriver = null
|
||||
) {
|
||||
// NOTE: Functional tests use their own shared metadata cache, because
|
||||
// the actual database platform used during execution has effect on some
|
||||
// metadata mapping behaviors (like the choice of the ID generation).
|
||||
@ -732,7 +741,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
}
|
||||
|
||||
$config->setMetadataDriverImpl(
|
||||
$config->newDefaultAnnotationDriver(
|
||||
$mappingDriver ?? $config->newDefaultAnnotationDriver(
|
||||
[
|
||||
realpath(__DIR__ . '/Models/Cache'),
|
||||
realpath(__DIR__ . '/Models/GeoNames')
|
||||
|
Loading…
x
Reference in New Issue
Block a user