Permalink
Browse files

test entity listener calls

  • Loading branch information...
1 parent c5d59ab commit ccc0a2a94f4ee01fa155fc68bb1e4608d5c29088 @FabioBatSilva committed with fabio.silva Jul 30, 2012
@@ -5,7 +5,7 @@
class ContractSubscriber
{
static public $prePersistCalls;
- static public $postPersisCalls;
+ static public $postPersistCalls;
static public $instances;
public function __construct()
@@ -18,7 +18,7 @@ public function __construct()
*/
public function postPersistHandler(CompanyContract $contract)
{
- self::$postPersisCalls[] = func_get_args();
+ self::$postPersistCalls[] = func_get_args();
}
/**
@@ -7,7 +7,6 @@
class FlexUltraContractSubscriber
{
static public $prePersistCalls;
- static public $postPersisCalls;
static public $instances;
public function __construct()
@@ -18,16 +17,16 @@ public function __construct()
/**
* @PrePersist
*/
- public function postPersistHandler1(CompanyContract $contract, LifecycleEventArgs $args)
+ public function prePersistHandler1(CompanyContract $contract, LifecycleEventArgs $args)
{
- self::$postPersisCalls[] = func_get_args();
+ self::$prePersistCalls[] = func_get_args();
}
/**
* @PrePersist
*/
- public function postPersistHandler2(CompanyContract $contract, LifecycleEventArgs $args)
+ public function prePersistHandler2(CompanyContract $contract, LifecycleEventArgs $args)
{
- self::$postPersisCalls[] = func_get_args();
+ self::$prePersistCalls[] = func_get_args();
}
}
@@ -18,26 +18,6 @@ class EntityListenersDispatcherTest extends \Doctrine\Tests\OrmFunctionalTestCas
*/
public function testEntityListeners()
{
- $flexClass = $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyFixContract');
- $fixClass = $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyFlexContract');
-
- $this->assertNull(ContractSubscriber::$instances);
- $this->assertNull(ContractSubscriber::$prePersistCalls);
- $this->assertNull(ContractSubscriber::$postPersisCalls);
-
- $fix = new CompanyFixContract();
- $fixArg = new LifecycleEventArgs($fix, $this->_em);
-
- $flex = new CompanyFlexContract();
- $flexArg = new LifecycleEventArgs($fix, $this->_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);
+ $this->markTestIncomplete();
}
}
@@ -7,6 +7,7 @@
use Doctrine\Tests\Models\Company\CompanyFixContract;
use Doctrine\Tests\Models\Company\CompanyFlexContract;
use Doctrine\Tests\Models\Company\ContractSubscriber;
+use Doctrine\Tests\Models\Company\FlexUltraContractSubscriber;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
@@ -803,11 +804,11 @@ public function testEntityListeners()
$prePersist = $ultraClass->entityListeners[Events::prePersist][1];
$this->assertEquals('Doctrine\Tests\Models\Company\FlexUltraContractSubscriber', $prePersist['class']);
- $this->assertEquals('postPersistHandler1', $prePersist['method']);
+ $this->assertEquals('prePersistHandler1', $prePersist['method']);
$prePersist = $ultraClass->entityListeners[Events::prePersist][2];
$this->assertEquals('Doctrine\Tests\Models\Company\FlexUltraContractSubscriber', $prePersist['class']);
- $this->assertEquals('postPersistHandler2', $prePersist['method']);
+ $this->assertEquals('prePersistHandler2', $prePersist['method']);
}
/**
@@ -823,24 +824,45 @@ public function testCallEntityListeners()
$factory = $this->createClassMetadataFactory($em);
$flexClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFixContract');
$fixClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexContract');
+ $ultraClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexUltraContract');
- ContractSubscriber::$prePersistCalls = null;
- ContractSubscriber::$postPersisCalls = null;
+ ContractSubscriber::$prePersistCalls = null;
+ ContractSubscriber::$postPersistCalls = null;
+ FlexUltraContractSubscriber::$prePersistCalls = null;
$fix = new CompanyFixContract();
$fixArg = new LifecycleEventArgs($fix, $em);
$flex = new CompanyFlexContract();
$flexArg = new LifecycleEventArgs($fix, $em);
+ $ultra = new CompanyFlexContract();
+ $ultraArg = new LifecycleEventArgs($ultra, $em);
+
$fixClass->dispatchEntityListeners(Events::prePersist, $fix, $fixArg);
$flexClass->dispatchEntityListeners(Events::prePersist, $flex, $flexArg);
+ $ultraClass->dispatchEntityListeners(Events::prePersist, $ultra, $ultraArg);
+
+ $this->assertCount(3, ContractSubscriber::$prePersistCalls);
+ $this->assertCount(2, FlexUltraContractSubscriber::$prePersistCalls);
$this->assertSame($fix, ContractSubscriber::$prePersistCalls[0][0]);
$this->assertSame($fixArg, ContractSubscriber::$prePersistCalls[0][1]);
+ $this->assertSame($flex, ContractSubscriber::$prePersistCalls[1][0]);
+ $this->assertSame($flexArg, ContractSubscriber::$prePersistCalls[1][1]);
+
+ $this->assertSame($ultra, ContractSubscriber::$prePersistCalls[2][0]);
+ $this->assertSame($ultraArg, ContractSubscriber::$prePersistCalls[2][1]);
+
+ $this->assertSame($ultra, FlexUltraContractSubscriber::$prePersistCalls[0][0]);
+ $this->assertSame($ultraArg, FlexUltraContractSubscriber::$prePersistCalls[0][1]);
+
+ $this->assertSame($ultra, FlexUltraContractSubscriber::$prePersistCalls[1][0]);
+ $this->assertSame($ultraArg, FlexUltraContractSubscriber::$prePersistCalls[1][1]);
+
$this->assertCount(1, ContractSubscriber::$instances);
- $this->assertNull(ContractSubscriber::$postPersisCalls);
+ $this->assertNull(ContractSubscriber::$postPersistCalls);
}
}

0 comments on commit ccc0a2a

Please sign in to comment.