Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

move call listeners tests to AbstractMappingDriverTest

  • Loading branch information...
commit 3c223a59c407610db94b1d5ad16916b72eabdd5c 1 parent 0f081d7
@FabioBatSilva authored fabio.silva committed
View
2  lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
@@ -427,7 +427,9 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
}
$listener = new \ReflectionClass($listener);
+ /* @var $method \ReflectionMethod */
foreach ($listener->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
+ // find method callbacks.
foreach ($this->getMethodCallbacks($method) as $value) {
$metadata->addEntityListener($value[1], $listener->name, $value[0]);
}
View
45 tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php
@@ -2,10 +2,14 @@
namespace Doctrine\Tests\ORM\Mapping;
-use Doctrine\ORM\Mapping\ClassMetadata,
- Doctrine\ORM\Mapping\ClassMetadataInfo,
- Doctrine\ORM\Mapping\Driver\XmlDriver,
- Doctrine\ORM\Mapping\Driver\YamlDriver;
+use Doctrine\ORM\Events;
+use Doctrine\ORM\Event\LifecycleEventArgs;
+use Doctrine\Tests\Models\Company\CompanyFixContract;
+use Doctrine\Tests\Models\Company\CompanyFlexContract;
+use Doctrine\Tests\Models\Company\ContractSubscriber;
+
+use Doctrine\ORM\Mapping\ClassMetadata;
+use Doctrine\ORM\Mapping\ClassMetadataInfo;
require_once __DIR__ . '/../../TestInit.php';
@@ -748,6 +752,39 @@ public function testAttributeOverridesMapping()
$this->assertTrue($guestMetadata->fieldMappings['name']['unique']);
}
+ /**
+ * @group DDC-1955
+ */
+ public function testCallEntityListeners()
+ {
+ if ( ! ($this instanceof AnnotationDriverTest)) {
+ $this->markTestIncomplete();
+ }
+
+ $em = $this->_getTestEntityManager();
+ $factory = $this->createClassMetadataFactory($em);
+ $flexClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFixContract');
+ $fixClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexContract');
+
+ ContractSubscriber::$prePersistCalls = null;
+ ContractSubscriber::$postPersisCalls = null;
+
+ $fix = new CompanyFixContract();
+ $fixArg = new LifecycleEventArgs($fix, $em);
+
+ $flex = new CompanyFlexContract();
+ $flexArg = new LifecycleEventArgs($fix, $em);
+
+ $fixClass->dispatchEntityListeners(Events::prePersist, $fix, $fixArg);
+ $flexClass->dispatchEntityListeners(Events::prePersist, $flex, $flexArg);
+
+ $this->assertSame($fix, ContractSubscriber::$prePersistCalls[0][0]);
+ $this->assertSame($fixArg, ContractSubscriber::$prePersistCalls[0][1]);
+
+ $this->assertCount(1, ContractSubscriber::$instances);
+ $this->assertNull(ContractSubscriber::$postPersisCalls);
+ }
+
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.