Skip to content
Browse files

test entity listener metadata

  • Loading branch information...
1 parent 3c223a5 commit c5d59ab4c797ac079da1169799ac8729ff259335 @FabioBatSilva committed with fabio.silva Jul 29, 2012
View
1 tests/Doctrine/Tests/Models/Company/CompanyFlexUltraContract.php
@@ -4,6 +4,7 @@
/**
* @Entity
+ * @EntityListeners({"ContractSubscriber","FlexUltraContractSubscriber"})
*/
class CompanyFlexUltraContract extends CompanyFlexContract
{
View
4 tests/Doctrine/Tests/Models/Company/ContractSubscriber.php
@@ -16,15 +16,15 @@ public function __construct()
/**
* @PostPersist
*/
- public function postPersist(CompanyContract $contract)
+ public function postPersistHandler(CompanyContract $contract)
{
self::$postPersisCalls[] = func_get_args();
}
/**
* @PrePersist
*/
- public function prePersist(CompanyContract $contract)
+ public function prePersistHandler(CompanyContract $contract)
{
self::$prePersistCalls[] = func_get_args();
}
View
33 tests/Doctrine/Tests/Models/Company/FlexUltraContractSubscriber.php
@@ -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();
+ }
+}
View
58 tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php
@@ -755,6 +755,64 @@ public function testAttributeOverridesMapping()
/**
* @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
+ */
public function testCallEntityListeners()
{
if ( ! ($this instanceof AnnotationDriverTest)) {

0 comments on commit c5d59ab

Please sign in to comment.
Something went wrong with that request. Please try again.