X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=vendor%2Fdoctrine%2Form%2Ftests%2FDoctrine%2FTests%2FORM%2FFunctional%2FManyToManyEventTest.php;fp=vendor%2Fdoctrine%2Form%2Ftests%2FDoctrine%2FTests%2FORM%2FFunctional%2FManyToManyEventTest.php;h=47c96b1fe005bd2559938d3c03bdd63881138dd7;hb=8b04b2d11798dee4f3e1358e4f43e97a6df851f6;hp=0000000000000000000000000000000000000000;hpb=73568cf05a785a45f94ca3f2351d9e07bf917958;p=zf2.biz%2Fapplication_blanche.git diff --git a/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/ManyToManyEventTest.php b/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/ManyToManyEventTest.php new file mode 100644 index 0000000..47c96b1 --- /dev/null +++ b/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/ManyToManyEventTest.php @@ -0,0 +1,76 @@ + + */ +class ManyToManyEventTest extends \Doctrine\Tests\OrmFunctionalTestCase +{ + /** + * @var PostUpdateListener + */ + private $listener; + + protected function setUp() + { + $this->useModelSet('cms'); + parent::setUp(); + $this->listener = new PostUpdateListener(); + $evm = $this->_em->getEventManager(); + $evm->addEventListener(Events::postUpdate, $this->listener); + } + + public function testListenerShouldBeNotifiedOnlyWhenUpdating() + { + $user = $this->createNewValidUser(); + $this->_em->persist($user); + $this->_em->flush(); + $this->assertFalse($this->listener->wasNotified); + + $group = new CmsGroup(); + $group->name = "admins"; + $user->addGroup($group); + $this->_em->persist($user); + $this->_em->flush(); + + $this->assertTrue($this->listener->wasNotified); + } + + /** + * @return CmsUser + */ + private function createNewValidUser() + { + $user = new CmsUser(); + $user->username = 'fran6co'; + $user->name = 'Francisco Facioni'; + $group = new CmsGroup(); + $group->name = "users"; + $user->addGroup($group); + return $user; + } +} + +class PostUpdateListener +{ + /** + * @var bool + */ + public $wasNotified = false; + + /** + * @param $args + */ + public function postUpdate($args) + { + $this->wasNotified = true; + } +} + +