1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Doctrine\Tests\ORM\Functional; |
||
6 | |||
7 | use Doctrine\Tests\Models\CMS\CmsUser; |
||
8 | use Doctrine\Tests\Models\CMS\CmsGroup; |
||
9 | use Doctrine\ORM\Events; |
||
10 | use Doctrine\Tests\OrmFunctionalTestCase; |
||
11 | |||
12 | /** |
||
13 | * ManyToManyEventTest |
||
14 | * |
||
15 | * @author Francisco Facioni <[email protected]> |
||
16 | */ |
||
17 | class ManyToManyEventTest extends OrmFunctionalTestCase |
||
18 | { |
||
19 | /** |
||
20 | * @var PostUpdateListener |
||
21 | */ |
||
22 | private $listener; |
||
23 | |||
24 | protected function setUp() |
||
25 | { |
||
26 | $this->useModelSet('cms'); |
||
27 | parent::setUp(); |
||
28 | $this->listener = new PostUpdateListener(); |
||
29 | $evm = $this->em->getEventManager(); |
||
30 | $evm->addEventListener(Events::postUpdate, $this->listener); |
||
31 | } |
||
32 | |||
33 | public function testListenerShouldBeNotifiedOnlyWhenUpdating() |
||
34 | { |
||
35 | $user = $this->createNewValidUser(); |
||
36 | $this->em->persist($user); |
||
37 | $this->em->flush(); |
||
38 | self::assertFalse($this->listener->wasNotified); |
||
39 | |||
40 | $group = new CmsGroup(); |
||
41 | $group->name = "admins"; |
||
42 | $user->addGroup($group); |
||
43 | $this->em->persist($user); |
||
44 | $this->em->flush(); |
||
45 | |||
46 | self::assertTrue($this->listener->wasNotified); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @return CmsUser |
||
51 | */ |
||
52 | private function createNewValidUser() |
||
53 | { |
||
54 | $user = new CmsUser(); |
||
55 | $user->username = 'fran6co'; |
||
56 | $user->name = 'Francisco Facioni'; |
||
57 | $group = new CmsGroup(); |
||
58 | $group->name = "users"; |
||
59 | $user->addGroup($group); |
||
60 | return $user; |
||
61 | } |
||
62 | } |
||
63 | |||
64 | class PostUpdateListener |
||
65 | { |
||
66 | /** |
||
67 | * @var bool |
||
68 | */ |
||
69 | public $wasNotified = false; |
||
70 | |||
71 | /** |
||
72 | * @param $args |
||
73 | */ |
||
74 | public function postUpdate($args) |
||
0 ignored issues
–
show
|
|||
75 | { |
||
76 | $this->wasNotified = true; |
||
77 | } |
||
78 | } |
||
79 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.