|
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\DependencyInjection\Compiler; |
|
12
|
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
|
16
|
|
|
use Yarhon\RouteGuardBundle\DependencyInjection\Compiler\SymfonySecurityBundlePass; |
|
17
|
|
|
use Yarhon\RouteGuardBundle\Security\TestProvider\SymfonyAccessControlProvider; |
|
18
|
|
|
use Yarhon\RouteGuardBundle\Security\TestResolver\SymfonyAccessControlResolver; |
|
19
|
|
|
use Yarhon\RouteGuardBundle\DependencyInjection\Container\ForeignExtensionAccessor; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author Yaroslav Honcharuk <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class SymfonySecurityBundlePassTest extends TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var ContainerBuilder |
|
28
|
|
|
*/ |
|
29
|
|
|
private $container; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var SymfonySecurityBundlePass |
|
33
|
|
|
*/ |
|
34
|
|
|
private $pass; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var ForeignExtensionAccessor; |
|
38
|
|
|
*/ |
|
39
|
|
|
private $foreignExtensionAccessor; |
|
40
|
|
|
|
|
41
|
|
|
private $securityExtension; |
|
42
|
|
|
|
|
43
|
|
|
public function setUp() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->container = new ContainerBuilder(); |
|
46
|
|
|
|
|
47
|
|
|
$this->foreignExtensionAccessor = $this->createMock(ForeignExtensionAccessor::class); |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
$this->pass = new SymfonySecurityBundlePass($this->foreignExtensionAccessor); |
|
50
|
|
|
|
|
51
|
|
|
$this->securityExtension = $this->createMock(Extension::class); |
|
52
|
|
|
|
|
53
|
|
|
$this->securityExtension->method('getAlias') |
|
|
|
|
|
|
54
|
|
|
->willReturn('security'); |
|
55
|
|
|
|
|
56
|
|
|
$this->container->register(SymfonyAccessControlProvider::class); |
|
57
|
|
|
$this->container->register(SymfonyAccessControlResolver::class); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testWithoutSecurityBundle() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->pass->process($this->container); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertFalse($this->container->hasDefinition(SymfonyAccessControlProvider::class)); |
|
65
|
|
|
$this->assertFalse($this->container->hasDefinition(SymfonyAccessControlResolver::class)); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testWithSecurityBundleNoAccessControl() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->foreignExtensionAccessor->method('getProcessedConfig') |
|
|
|
|
|
|
71
|
|
|
->willReturn([]); |
|
72
|
|
|
|
|
73
|
|
|
$this->container->registerExtension($this->securityExtension); |
|
74
|
|
|
|
|
75
|
|
|
$this->pass->process($this->container); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertFalse($this->container->hasDefinition(SymfonyAccessControlProvider::class)); |
|
78
|
|
|
$this->assertFalse($this->container->hasDefinition(SymfonyAccessControlResolver::class)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testWithSecurityBundleEmptyAccessControl() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->foreignExtensionAccessor->method('getProcessedConfig') |
|
84
|
|
|
->willReturn(['access_control' => []]); |
|
85
|
|
|
|
|
86
|
|
|
$this->container->registerExtension($this->securityExtension); |
|
87
|
|
|
|
|
88
|
|
|
$this->pass->process($this->container); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertFalse($this->container->hasDefinition(SymfonyAccessControlProvider::class)); |
|
91
|
|
|
$this->assertFalse($this->container->hasDefinition(SymfonyAccessControlResolver::class)); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function testWithAccessControl() |
|
95
|
|
|
{ |
|
96
|
|
|
$rules = [ |
|
97
|
|
|
['path' => '/path1'], |
|
98
|
|
|
]; |
|
99
|
|
|
|
|
100
|
|
|
$this->foreignExtensionAccessor->method('getProcessedConfig') |
|
101
|
|
|
->willReturn(['access_control' => $rules]); |
|
102
|
|
|
|
|
103
|
|
|
$this->container->registerExtension($this->securityExtension); |
|
104
|
|
|
|
|
105
|
|
|
$this->pass->process($this->container); |
|
106
|
|
|
|
|
107
|
|
|
$this->assertTrue($this->container->hasDefinition(SymfonyAccessControlProvider::class)); |
|
108
|
|
|
$this->assertTrue($this->container->hasDefinition(SymfonyAccessControlResolver::class)); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function testImportRules() |
|
112
|
|
|
{ |
|
113
|
|
|
$rules = [ |
|
114
|
|
|
['path' => '/path1'], |
|
115
|
|
|
['path' => '/path2'], |
|
116
|
|
|
]; |
|
117
|
|
|
|
|
118
|
|
|
$this->foreignExtensionAccessor->method('getProcessedConfig') |
|
119
|
|
|
->willReturn(['access_control' => $rules]); |
|
120
|
|
|
|
|
121
|
|
|
$this->container->registerExtension($this->securityExtension); |
|
122
|
|
|
|
|
123
|
|
|
$this->pass->process($this->container); |
|
124
|
|
|
|
|
125
|
|
|
$methodCalls = $this->container->getDefinition(SymfonyAccessControlProvider::class)->getMethodCalls(); |
|
126
|
|
|
$this->assertCount(1, $methodCalls); |
|
127
|
|
|
|
|
128
|
|
|
list($name, $arguments) = $methodCalls[0]; |
|
129
|
|
|
$this->assertEquals('importRules', $name); |
|
130
|
|
|
$this->assertEquals($rules, $arguments[0]); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..