test entity listener metadata
This commit is contained in:
parent
3c223a59c4
commit
c5d59ab4c7
@ -4,6 +4,7 @@ namespace Doctrine\Tests\Models\Company;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @EntityListeners({"ContractSubscriber","FlexUltraContractSubscriber"})
|
||||
*/
|
||||
class CompanyFlexUltraContract extends CompanyFlexContract
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ class ContractSubscriber
|
||||
/**
|
||||
* @PostPersist
|
||||
*/
|
||||
public function postPersist(CompanyContract $contract)
|
||||
public function postPersistHandler(CompanyContract $contract)
|
||||
{
|
||||
self::$postPersisCalls[] = func_get_args();
|
||||
}
|
||||
@ -24,7 +24,7 @@ class ContractSubscriber
|
||||
/**
|
||||
* @PrePersist
|
||||
*/
|
||||
public function prePersist(CompanyContract $contract)
|
||||
public function prePersistHandler(CompanyContract $contract)
|
||||
{
|
||||
self::$prePersistCalls[] = func_get_args();
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\Company;
|
||||
|
||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
|
||||
class FlexUltraContractSubscriber
|
||||
{
|
||||
static public $prePersistCalls;
|
||||
static public $postPersisCalls;
|
||||
static public $instances;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
self::$instances[] = $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @PrePersist
|
||||
*/
|
||||
public function postPersistHandler1(CompanyContract $contract, LifecycleEventArgs $args)
|
||||
{
|
||||
self::$postPersisCalls[] = func_get_args();
|
||||
}
|
||||
|
||||
/**
|
||||
* @PrePersist
|
||||
*/
|
||||
public function postPersistHandler2(CompanyContract $contract, LifecycleEventArgs $args)
|
||||
{
|
||||
self::$postPersisCalls[] = func_get_args();
|
||||
}
|
||||
}
|
@ -752,6 +752,64 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->assertTrue($guestMetadata->fieldMappings['name']['unique']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1955
|
||||
*/
|
||||
public function testEntityListeners()
|
||||
{
|
||||
if ( ! ($this instanceof AnnotationDriverTest)) {
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
$em = $this->_getTestEntityManager();
|
||||
$factory = $this->createClassMetadataFactory($em);
|
||||
$superClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyContract');
|
||||
$flexClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFixContract');
|
||||
$fixClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexContract');
|
||||
$ultraClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexUltraContract');
|
||||
|
||||
$this->assertArrayHasKey(Events::prePersist, $superClass->entityListeners);
|
||||
$this->assertArrayHasKey(Events::postPersist, $superClass->entityListeners);
|
||||
|
||||
$this->assertCount(1, $superClass->entityListeners[Events::prePersist]);
|
||||
$this->assertCount(1, $superClass->entityListeners[Events::postPersist]);
|
||||
|
||||
$postPersist = $superClass->entityListeners[Events::postPersist][0];
|
||||
$prePersist = $superClass->entityListeners[Events::prePersist][0];
|
||||
|
||||
$this->assertEquals('Doctrine\Tests\Models\Company\ContractSubscriber', $postPersist['class']);
|
||||
$this->assertEquals('Doctrine\Tests\Models\Company\ContractSubscriber', $prePersist['class']);
|
||||
$this->assertEquals('postPersistHandler', $postPersist['method']);
|
||||
$this->assertEquals('prePersistHandler', $prePersist['method']);
|
||||
|
||||
//Inherited listeners
|
||||
$this->assertEquals($fixClass->entityListeners, $superClass->entityListeners);
|
||||
$this->assertEquals($flexClass->entityListeners, $superClass->entityListeners);
|
||||
|
||||
//overrited listeners
|
||||
$this->assertArrayHasKey(Events::postPersist, $ultraClass->entityListeners);
|
||||
$this->assertArrayHasKey(Events::prePersist, $ultraClass->entityListeners);
|
||||
|
||||
$this->assertCount(1, $ultraClass->entityListeners[Events::postPersist]);
|
||||
$this->assertCount(3, $ultraClass->entityListeners[Events::prePersist]);
|
||||
|
||||
$postPersist = $ultraClass->entityListeners[Events::postPersist][0];
|
||||
$prePersist = $ultraClass->entityListeners[Events::prePersist][0];
|
||||
|
||||
$this->assertEquals('Doctrine\Tests\Models\Company\ContractSubscriber', $postPersist['class']);
|
||||
$this->assertEquals('Doctrine\Tests\Models\Company\ContractSubscriber', $prePersist['class']);
|
||||
$this->assertEquals('postPersistHandler', $postPersist['method']);
|
||||
$this->assertEquals('prePersistHandler', $prePersist['method']);
|
||||
|
||||
$prePersist = $ultraClass->entityListeners[Events::prePersist][1];
|
||||
$this->assertEquals('Doctrine\Tests\Models\Company\FlexUltraContractSubscriber', $prePersist['class']);
|
||||
$this->assertEquals('postPersistHandler1', $prePersist['method']);
|
||||
|
||||
$prePersist = $ultraClass->entityListeners[Events::prePersist][2];
|
||||
$this->assertEquals('Doctrine\Tests\Models\Company\FlexUltraContractSubscriber', $prePersist['class']);
|
||||
$this->assertEquals('postPersistHandler2', $prePersist['method']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1955
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user