1 | <?php |
||
2 | |||
3 | /* |
||
4 | * |
||
5 | * (c) Yaroslav Honcharuk <[email protected]> |
||
6 | * |
||
7 | * For the full copyright and license information, please view the LICENSE |
||
8 | * file that was distributed with this source code. |
||
9 | */ |
||
10 | |||
11 | namespace Yarhon\RouteGuardBundle\Tests\Controller\ArgumentResolver; |
||
12 | |||
13 | use PHPUnit\Framework\TestCase; |
||
14 | use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; |
||
15 | use Symfony\Component\HttpFoundation\Request; |
||
16 | use Symfony\Component\HttpFoundation\Session\SessionInterface; |
||
17 | use Symfony\Component\HttpFoundation\Session\Session; |
||
18 | use Yarhon\RouteGuardBundle\Controller\ArgumentResolver\SessionValueResolver; |
||
19 | use Yarhon\RouteGuardBundle\Controller\ArgumentResolver\ArgumentResolverContext; |
||
20 | |||
21 | /** |
||
22 | * @author Yaroslav Honcharuk <[email protected]> |
||
23 | */ |
||
24 | class SessionValueResolverTest extends TestCase |
||
25 | { |
||
26 | private $request; |
||
27 | |||
28 | private $context; |
||
29 | |||
30 | private $argument; |
||
31 | |||
32 | public function setUp() |
||
33 | { |
||
34 | $this->request = $this->createMock(Request::class); |
||
35 | |||
36 | $this->context = $this->createMock(ArgumentResolverContext::class); |
||
37 | |||
38 | $this->context->method('getRequest') |
||
0 ignored issues
–
show
|
|||
39 | ->willReturn($this->request); |
||
40 | |||
41 | $this->argument = $this->createMock(ArgumentMetadata::class); |
||
42 | } |
||
43 | |||
44 | public function testSupportsNoSession() |
||
45 | { |
||
46 | $resolver = new SessionValueResolver(); |
||
47 | |||
48 | $this->request->method('hasSession') |
||
49 | ->willReturn(false); |
||
50 | |||
51 | $this->assertFalse($resolver->supports($this->context, $this->argument)); |
||
52 | } |
||
53 | |||
54 | public function testSupportsUnsuitableArgumentType() |
||
55 | { |
||
56 | $resolver = new SessionValueResolver(); |
||
57 | |||
58 | $this->request->method('hasSession') |
||
59 | ->willReturn(true); |
||
60 | |||
61 | $this->argument->method('getType') |
||
62 | ->willReturn('int'); |
||
63 | |||
64 | $this->assertFalse($resolver->supports($this->context, $this->argument)); |
||
65 | } |
||
66 | |||
67 | public function testSupportsWithSession() |
||
68 | { |
||
69 | $resolver = new SessionValueResolver(); |
||
70 | |||
71 | $session = $this->createMock(SessionInterface::class); |
||
72 | |||
73 | $this->request->method('hasSession') |
||
74 | ->willReturn(true); |
||
75 | |||
76 | $this->request->method('getSession') |
||
77 | ->willReturn($session); |
||
78 | |||
79 | $this->argument->method('getType') |
||
80 | ->willReturn(SessionInterface::class); |
||
81 | |||
82 | $this->assertTrue($resolver->supports($this->context, $this->argument)); |
||
83 | } |
||
84 | |||
85 | public function testSupportsWithSessionChild() |
||
86 | { |
||
87 | $resolver = new SessionValueResolver(); |
||
88 | |||
89 | $session = $this->createMock(SessionChild::class); |
||
90 | |||
91 | $this->request->method('hasSession') |
||
92 | ->willReturn(true); |
||
93 | |||
94 | $this->request->method('getSession') |
||
95 | ->willReturn($session); |
||
96 | |||
97 | $this->argument->method('getType') |
||
98 | ->willReturn(SessionChild::class); |
||
99 | |||
100 | $this->assertTrue($resolver->supports($this->context, $this->argument)); |
||
101 | } |
||
102 | |||
103 | public function testSupportsWithSessionTypeMismatch() |
||
104 | { |
||
105 | $resolver = new SessionValueResolver(); |
||
106 | |||
107 | $session = $this->createMock(SessionInterface::class); |
||
108 | |||
109 | $this->request->method('hasSession') |
||
110 | ->willReturn(true); |
||
111 | |||
112 | $this->request->method('getSession') |
||
113 | ->willReturn($session); |
||
114 | |||
115 | $this->argument->method('getType') |
||
116 | ->willReturn(SessionChild::class); |
||
117 | |||
118 | $this->assertFalse($resolver->supports($this->context, $this->argument)); |
||
119 | } |
||
120 | |||
121 | public function testResolve() |
||
122 | { |
||
123 | $resolver = new SessionValueResolver(); |
||
124 | |||
125 | $session = $this->createMock(SessionInterface::class); |
||
126 | |||
127 | $this->request->method('getSession') |
||
128 | ->willReturn($session); |
||
129 | |||
130 | $this->assertSame($session, $resolver->resolve($this->context, $this->argument)); |
||
131 | } |
||
132 | } |
||
133 | |||
134 | class SessionChild extends Session |
||
135 | { |
||
136 | } |
||
137 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.