diff --git a/tests/Doctrine/Tests/Models/Company/CompanyFlexUltraContract.php b/tests/Doctrine/Tests/Models/Company/CompanyFlexUltraContract.php index b9ad3d4c9..ce76821a6 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyFlexUltraContract.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyFlexUltraContract.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\Models\Company; /** * @Entity + * @EntityListeners({"ContractSubscriber","FlexUltraContractSubscriber"}) */ class CompanyFlexUltraContract extends CompanyFlexContract { diff --git a/tests/Doctrine/Tests/Models/Company/ContractSubscriber.php b/tests/Doctrine/Tests/Models/Company/ContractSubscriber.php index e6557c0fc..2a7d7c76a 100644 --- a/tests/Doctrine/Tests/Models/Company/ContractSubscriber.php +++ b/tests/Doctrine/Tests/Models/Company/ContractSubscriber.php @@ -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(); } diff --git a/tests/Doctrine/Tests/Models/Company/FlexUltraContractSubscriber.php b/tests/Doctrine/Tests/Models/Company/FlexUltraContractSubscriber.php new file mode 100644 index 000000000..fd64594ba --- /dev/null +++ b/tests/Doctrine/Tests/Models/Company/FlexUltraContractSubscriber.php @@ -0,0 +1,33 @@ +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 */