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\Container; |
12
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
15
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
16
|
|
|
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; |
17
|
|
|
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface; |
18
|
|
|
use Symfony\Component\Config\Definition\Processor; |
19
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
20
|
|
|
use Symfony\Component\Config\Definition\Exception\Exception as ConfigDefinitionException; |
21
|
|
|
use Yarhon\RouteGuardBundle\DependencyInjection\Container\ForeignExtensionAccessor; |
22
|
|
|
use Yarhon\RouteGuardBundle\Exception\LogicException; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Yaroslav Honcharuk <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class ForeignExtensionAccessorTest extends TestCase |
28
|
|
|
{ |
29
|
|
|
public function testGetProcessedConfig() |
30
|
|
|
{ |
31
|
|
|
$rawConfig = [ |
32
|
|
|
[ |
33
|
|
|
'key1' => 'value1', |
34
|
|
|
], |
35
|
|
|
[ |
36
|
|
|
'key2' => 'value2', |
37
|
|
|
], |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
$configuration = $this->createMock(ConfigurationInterface::class); |
41
|
|
|
|
42
|
|
|
$extension = $this->createMock(Extension::class); |
43
|
|
|
$extension->method('getAlias') |
|
|
|
|
44
|
|
|
->willReturn('foreign'); |
45
|
|
|
$extension->method('getConfiguration') |
46
|
|
|
->willReturn($configuration); |
47
|
|
|
|
48
|
|
|
$processor = $this->createMock(Processor::class); |
49
|
|
|
$processor->expects($this->once()) |
50
|
|
|
->method('processConfiguration') |
51
|
|
|
->with($configuration, $rawConfig) |
52
|
|
|
->willReturn(['processed' => true]); |
53
|
|
|
|
54
|
|
|
$accessor = new ForeignExtensionAccessor($processor); |
55
|
|
|
$container = new ContainerBuilder(); |
56
|
|
|
$container->registerExtension($extension); |
57
|
|
|
|
58
|
|
|
$container->loadFromExtension('foreign', $rawConfig[0]); |
59
|
|
|
$container->loadFromExtension('foreign', $rawConfig[1]); |
60
|
|
|
|
61
|
|
|
$config = $accessor->getProcessedConfig($container, $extension); |
62
|
|
|
|
63
|
|
|
$this->assertEquals(['processed' => true], $config); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testGetProcessedConfigNotInstanceOfConfigurationExtensionException() |
67
|
|
|
{ |
68
|
|
|
$extension = $this->createMock(ExtensionInterface::class); |
69
|
|
|
$extension->method('getAlias') |
70
|
|
|
->willReturn('foreign'); |
71
|
|
|
|
72
|
|
|
$processor = $this->createMock(Processor::class); |
73
|
|
|
|
74
|
|
|
$accessor = new ForeignExtensionAccessor($processor); |
75
|
|
|
$container = new ContainerBuilder(); |
76
|
|
|
$container->registerExtension($extension); |
77
|
|
|
|
78
|
|
|
$this->expectException(LogicException::class); |
79
|
|
|
$this->expectExceptionMessage(sprintf('"%s" extension class is not an instance of %s.', 'foreign', ConfigurationExtensionInterface::class)); |
80
|
|
|
|
81
|
|
|
$accessor->getProcessedConfig($container, $extension); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testGetProcessedConfigConfigDefinitionException() |
85
|
|
|
{ |
86
|
|
|
$configuration = $this->createMock(ConfigurationInterface::class); |
87
|
|
|
|
88
|
|
|
$extension = $this->createMock(Extension::class); |
89
|
|
|
$extension->method('getAlias') |
90
|
|
|
->willReturn('foreign'); |
91
|
|
|
$extension->method('getConfiguration') |
92
|
|
|
->willReturn($configuration); |
93
|
|
|
|
94
|
|
|
$processor = $this->createMock(Processor::class); |
95
|
|
|
$processor->method('processConfiguration') |
96
|
|
|
->willThrowException(new ConfigDefinitionException('test')); |
97
|
|
|
|
98
|
|
|
$accessor = new ForeignExtensionAccessor($processor); |
99
|
|
|
$container = new ContainerBuilder(); |
100
|
|
|
$container->registerExtension($extension); |
101
|
|
|
|
102
|
|
|
$this->expectException(LogicException::class); |
103
|
|
|
$this->expectExceptionMessage('Cannot read configuration of the "foreign" extension because of configuration exception.'); |
104
|
|
|
|
105
|
|
|
$accessor->getProcessedConfig($container, $extension); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
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.