11<?php
22
3+ declare (strict_types=1 );
4+
35namespace Tests \NodeVisitor ;
46
57use DAMA \MenuBundle \MenuTree \MenuTreeTraverserInterface ;
68use DAMA \MenuBundle \Node \Node ;
79use DAMA \MenuBundle \Node \NodeFactory ;
810use DAMA \MenuBundle \NodeVisitor \NodeFilter ;
11+ use PHPUnit \Framework \Attributes \DataProvider ;
12+ use PHPUnit \Framework \Attributes \TestWith ;
913use PHPUnit \Framework \MockObject \MockObject ;
1014use PHPUnit \Framework \TestCase ;
1115use Symfony \Component \ExpressionLanguage \Expression ;
1519
1620class NodeFilterTest extends TestCase
1721{
18- /**
19- * @var NodeFilter
20- */
21- private $ filter ;
22-
23- /**
24- * @var TokenStorageInterface|MockObject
25- */
26- private $ tokenStorage ;
27-
28- /**
29- * @var AuthorizationCheckerInterface|MockObject
30- */
31- private $ authChecker ;
32-
33- /**
34- * @var Node
35- */
36- private $ node ;
37-
38- /**
39- * @var Node|MockObject
40- */
41- private $ parent ;
22+ private NodeFilter $ filter ;
23+ private TokenStorageInterface &MockObject $ tokenStorage ;
24+ private AuthorizationCheckerInterface &MockObject $ authChecker ;
25+ private Node $ node ;
26+ private Node &MockObject $ parent ;
27+ private TokenInterface &MockObject $ token ;
4228
4329 public function setUp (): void
4430 {
4531 $ this ->tokenStorage = $ this ->createMock (TokenStorageInterface::class);
4632 $ this ->authChecker = $ this ->createMock (AuthorizationCheckerInterface::class);
4733 $ this ->filter = new NodeFilter ($ this ->tokenStorage , $ this ->authChecker );
4834 $ this ->node = new Node ();
49- $ this ->parent = $ this ->getMockBuilder (Node::class)-> getMock ( );
35+ $ this ->parent = $ this ->createMock (Node::class);
5036 $ this ->node ->setParent ($ this ->parent );
37+ $ this ->token = $ this ->createMock (TokenInterface::class);
5138 }
5239
53- /**
54- * @dataProvider getTestData
55- */
56- public function testVisit (array $ permissions , $ getTokenReturn , $ isGrantedReturn , $ expectsFiltered ): void
40+ #[DataProvider('getTestData ' )]
41+ public function testVisit (array $ permissions , bool $ hasToken , $ isGrantedReturn , $ expectsFiltered ): void
5742 {
5843 $ this ->node ->setRequiredPermissions ($ permissions );
5944
6045 $ this ->tokenStorage
6146 ->expects ($ this ->any ())
6247 ->method ('getToken ' )
63- ->will ( $ this ->returnValue ( $ getTokenReturn ) )
48+ ->willReturn ( $ hasToken ? $ this ->token : null )
6449 ;
6550
6651 $ this ->authChecker
6752 ->expects ($ this ->any ())
6853 ->method ('isGranted ' )
69- ->will ( $ this -> returnValue ( $ isGrantedReturn) )
54+ ->willReturn ( $ isGrantedReturn )
7055 ;
7156
7257 if ($ expectsFiltered ) {
@@ -84,10 +69,8 @@ public function testVisit(array $permissions, $getTokenReturn, $isGrantedReturn,
8469 }
8570 }
8671
87- /**
88- * @testWith [true]
89- * [false]
90- */
72+ #[TestWith([true ])]
73+ #[TestWith([false ])]
9174 public function testRemoveParentIfNoActiveChildren (bool $ remove ): void
9275 {
9376 $ tree = (new NodeFactory ())->create ();
@@ -117,14 +100,14 @@ public function testRemoveParentIfNoActiveChildren(bool $remove): void
117100 $ this ->assertCount ($ remove ? 0 : 1 , $ tree ->getChildren ());
118101 }
119102
120- public function getTestData ()
103+ public static function getTestData (): array
121104 {
122105 return [
123- [[], $ this -> createMock (TokenInterface::class) , true , false ],
124- [['FOO ' ], $ this -> createMock (TokenInterface::class) , true , false ],
125- [['FOO ' ], $ this -> createMock (TokenInterface::class) , false , true ],
126- [['FOO ' ], null , true , true ],
127- [[new Expression ('something ' )], null , true , true ],
106+ [[], true , true , false ],
107+ [['FOO ' ], true , true , false ],
108+ [['FOO ' ], true , false , true ],
109+ [['FOO ' ], false , true , true ],
110+ [[new Expression ('something ' )], false , true , true ],
128111 ];
129112 }
130113}
0 commit comments