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\ParameterBag; |
||
16 | use Yarhon\RouteGuardBundle\Controller\ArgumentResolver\RequestAttributeValueResolver; |
||
17 | use Yarhon\RouteGuardBundle\Controller\ArgumentResolver\ArgumentResolverContext; |
||
18 | |||
19 | /** |
||
20 | * @author Yaroslav Honcharuk <[email protected]> |
||
21 | */ |
||
22 | class RequestAttributeValueResolverTest extends TestCase |
||
23 | { |
||
24 | private $attributes; |
||
25 | |||
26 | private $context; |
||
27 | |||
28 | private $argument; |
||
29 | |||
30 | public function setUp() |
||
31 | { |
||
32 | $this->attributes = $this->createMock(ParameterBag::class); |
||
33 | |||
34 | $this->context = $this->createMock(ArgumentResolverContext::class); |
||
35 | |||
36 | $this->context->method('getAttributes') |
||
0 ignored issues
–
show
|
|||
37 | ->willReturn($this->attributes); |
||
38 | |||
39 | $this->argument = $this->createMock(ArgumentMetadata::class); |
||
40 | |||
41 | $this->argument->method('isVariadic') |
||
42 | ->willReturn(false); |
||
43 | } |
||
44 | |||
45 | public function testSupportsHasAttribute() |
||
46 | { |
||
47 | $resolver = new RequestAttributeValueResolver(); |
||
48 | |||
49 | $this->argument->method('getName') |
||
50 | ->willReturn('arg'); |
||
51 | |||
52 | $this->attributes->expects($this->once()) |
||
53 | ->method('has') |
||
54 | ->with('arg') |
||
55 | ->willReturn(true); |
||
56 | |||
57 | $this->assertTrue($resolver->supports($this->context, $this->argument)); |
||
58 | } |
||
59 | |||
60 | public function testSupportsNotHasAttribute() |
||
61 | { |
||
62 | $resolver = new RequestAttributeValueResolver(); |
||
63 | |||
64 | $this->argument->method('getName') |
||
65 | ->willReturn('arg'); |
||
66 | |||
67 | $this->attributes->expects($this->once()) |
||
68 | ->method('has') |
||
69 | ->with('arg') |
||
70 | ->willReturn(false); |
||
71 | |||
72 | $this->assertFalse($resolver->supports($this->context, $this->argument)); |
||
73 | } |
||
74 | |||
75 | public function testResolve() |
||
76 | { |
||
77 | $resolver = new RequestAttributeValueResolver(); |
||
78 | |||
79 | $this->argument->method('getName') |
||
80 | ->willReturn('arg'); |
||
81 | |||
82 | $this->attributes->expects($this->once()) |
||
83 | ->method('get') |
||
84 | ->with('arg') |
||
85 | ->willReturn(5); |
||
86 | |||
87 | $this->assertEquals(5, $resolver->resolve($this->context, $this->argument)); |
||
88 | } |
||
89 | } |
||
90 |
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.