|
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') |
|
|
|
|
|
|
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
|
|
|
|
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.