#1130 DDC-3300 - removing unused ResolveDiscriminatorMapListener
and related test
This commit is contained in:
parent
b7c28924b1
commit
8a6b1b48e3
@ -1,82 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Tools;
|
||||
|
||||
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
|
||||
/**
|
||||
* ResolveDiscriminatorMapListener
|
||||
*
|
||||
* Mechanism to overwrite interfaces or classes specified in discrimination map
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @since 2.2
|
||||
*/
|
||||
class ResolveDiscriminatorMapListener
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $resolveTargetEntities = array();
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param array $resolveTargetEntities
|
||||
*/
|
||||
public function __construct(array $resolveTargetEntities)
|
||||
{
|
||||
$this->resolveTargetEntities = $resolveTargetEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes event and resolves new target entity names.
|
||||
*
|
||||
* @param LoadClassMetadataEventArgs $args
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadClassMetadata(LoadClassMetadataEventArgs $args)
|
||||
{
|
||||
$classMetadata = $args->getClassMetadata();
|
||||
|
||||
if (!empty($classMetadata->discriminatorMap)) {
|
||||
|
||||
$this->remapDiscriminatorMap($classMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all Interfaces in discriminator map
|
||||
*
|
||||
* @param \Doctrine\ORM\Mapping\ClassMetadataInfo $classMetadata
|
||||
*/
|
||||
private function remapDiscriminatorMap(ClassMetadataInfo $classMetadata)
|
||||
{
|
||||
foreach ($classMetadata->discriminatorMap as $name => $interface) {
|
||||
|
||||
if (isset($this->resolveTargetEntities[$interface])) {
|
||||
|
||||
$classMetadata->discriminatorMap[$name] = $this->resolveTargetEntities[$interface];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools;
|
||||
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\ORM\Mapping\ClassMetadataFactory;
|
||||
use Doctrine\ORM\Mapping\Column;
|
||||
use Doctrine\ORM\Mapping\MappedSuperclass;
|
||||
use Doctrine\ORM\Tools\ResolveDiscriminatorMapListener;
|
||||
|
||||
class ResolveDiscriminatorMapListenerTest extends \Doctrine\Tests\OrmTestCase
|
||||
{
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $em = null;
|
||||
|
||||
/**
|
||||
* @var ClassMetadataFactory
|
||||
*/
|
||||
private $factory = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$annotationDriver = $this->createAnnotationDriver();
|
||||
|
||||
$this->em = $this->_getTestEntityManager();
|
||||
$this->em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
|
||||
$this->factory = new ClassMetadataFactory;
|
||||
$this->factory->setEntityManager($this->em);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-3300
|
||||
*/
|
||||
public function testResolveDiscriminatorMapListenerTestCanResolveDiscriminatorMap()
|
||||
{
|
||||
$evm = $this->em->getEventManager();
|
||||
$listener = new ResolveDiscriminatorMapListener(array(
|
||||
'Doctrine\Tests\ORM\Tools\BossInterface' => 'Doctrine\Tests\ORM\Tools\Boss',
|
||||
'Doctrine\Tests\ORM\Tools\EmployeeInterface' => 'Doctrine\Tests\ORM\Tools\Employee',
|
||||
));
|
||||
|
||||
$evm->addEventListener(Events::loadClassMetadata, $listener);
|
||||
$cm = $this->factory->getMetadataFor('Doctrine\Tests\ORM\Tools\Person');
|
||||
$meta = $cm->discriminatorMap;
|
||||
$this->assertSame('Doctrine\Tests\ORM\Tools\Boss', $meta['boss']);
|
||||
$this->assertSame('Doctrine\Tests\ORM\Tools\Employee', $meta['employee']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-3300
|
||||
*/
|
||||
public function testResolveDiscriminatorMapListenerTestCannotResolveWrongDiscriminatorMap()
|
||||
{
|
||||
$evm = $this->em->getEventManager();
|
||||
$listener = new ResolveDiscriminatorMapListener(array(
|
||||
'Doctrine\Tests\ORM\Tools\EmployeeInterface' => 'Doctrine\Tests\ORM\Tools\Employee',
|
||||
));
|
||||
|
||||
$evm->addEventListener(Events::loadClassMetadata, $listener);
|
||||
$cm = $this->factory->getMetadataFor('Doctrine\Tests\ORM\Tools\Person');
|
||||
$meta = $cm->discriminatorMap;
|
||||
$this->assertSame('Doctrine\Tests\ORM\Tools\BossInterface', $meta['boss']);
|
||||
$this->assertSame('Doctrine\Tests\ORM\Tools\Employee', $meta['employee']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @InheritanceType("SINGLE_TABLE")
|
||||
* @DiscriminatorColumn(name="discr", type="string")
|
||||
* @DiscriminatorMap({
|
||||
* "boss" = "\Doctrine\Tests\ORM\Tools\BossInterface",
|
||||
* "employee" = "\Doctrine\Tests\ORM\Tools\EmployeeInterface"
|
||||
* })
|
||||
*/
|
||||
abstract class Person
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @Column(type="integer")
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
|
||||
interface BossInterface
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class Boss extends Person implements BossInterface
|
||||
{
|
||||
/**
|
||||
* @Column(type="integer")
|
||||
*/
|
||||
private $earnedMoneyInEuros;
|
||||
}
|
||||
|
||||
interface EmployeeInterface
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class Employee extends Person implements EmployeeInterface
|
||||
{
|
||||
/**
|
||||
* @Column(type="integer")
|
||||
*/
|
||||
private $daysOfLifeReducedInDays;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user