Completed
Push — master ( 236a45...b262d2 )
by Yaroslav
09:39
created

SymfonySecurityResolverTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 29
dl 0
loc 59
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testResolveException() 0 18 1
A testSupports() 0 7 1
A setUp() 0 2 1
A testResolve() 0 24 1
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\Security\TestResolver;
12
13
use PHPUnit\Framework\TestCase;
14
use Yarhon\RouteGuardBundle\Routing\RouteContext;
15
use Yarhon\RouteGuardBundle\Security\TestResolver\SymfonySecurityResolverInterface;
16
use Yarhon\RouteGuardBundle\Security\Test\TestInterface;
17
use Yarhon\RouteGuardBundle\Security\Test\SymfonyAccessControlTest;
18
use Yarhon\RouteGuardBundle\Security\TestResolver\SymfonySecurityResolver;
19
use Yarhon\RouteGuardBundle\Exception\RuntimeException;
20
21
/**
22
 * @author Yaroslav Honcharuk <[email protected]>
23
 */
24
class SymfonySecurityResolverTest extends TestCase
25
{
26
    public function setUp()
27
    {
28
    }
29
30
    public function testSupports()
31
    {
32
        $delegatingResolver = new SymfonySecurityResolver();
33
34
        $test = $this->createMock(TestInterface::class);
35
36
        $this->assertTrue($delegatingResolver->supports($test));
37
    }
38
39
    public function testResolve()
40
    {
41
        $resolvers = [
42
            $this->createMock(SymfonySecurityResolverInterface::class),
43
            $this->createMock(SymfonySecurityResolverInterface::class),
44
        ];
45
46
        $resolvers[0]->method('supports')
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        $resolvers[0]->/** @scrutinizer ignore-call */ 
47
                       method('supports')

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.

Loading history...
47
            ->willReturn(false);
48
49
        $resolvers[1]->method('supports')
50
            ->willReturn(true);
51
52
        $delegatingResolver = new SymfonySecurityResolver($resolvers);
53
54
        $test = new SymfonyAccessControlTest(['ROLE_USER']);
55
        $routeContext = new RouteContext('index');
56
57
        $resolvers[1]->expects($this->once())
58
            ->method('resolve')
59
            ->with($test, $routeContext)
60
            ->willReturn(['foo']);
61
62
        $this->assertSame(['foo'], $delegatingResolver->resolve($test, $routeContext));
63
    }
64
65
    public function testResolveException()
66
    {
67
        $resolvers = [
68
            $this->createMock(SymfonySecurityResolverInterface::class),
69
        ];
70
71
        $resolvers[0]->method('supports')
72
            ->willReturn(false);
73
74
        $delegatingResolver = new SymfonySecurityResolver($resolvers);
75
76
        $test = new SymfonyAccessControlTest(['ROLE_USER']);
77
        $routeContext = new RouteContext('index');
78
79
        $this->expectException(RuntimeException::class);
80
        $this->expectExceptionMessage(sprintf('No resolver exists for test instance of "%s".', SymfonyAccessControlTest::class));
81
82
        $delegatingResolver->resolve($test, $routeContext);
83
    }
84
}
85