1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bicycle\TesseractBridgeBundle\Tests\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Bicycle\Tesseract\Bridge\Configuration; |
6
|
|
|
use Bicycle\TesseractBridgeBundle\DependencyInjection\BicycleTesseractBridgeExtension; |
7
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
10
|
|
|
use Symfony\Component\DependencyInjection; |
11
|
|
|
|
12
|
|
|
class BicycleTesseractBridgeExtensionTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** @var BicycleTesseractBridgeExtension */ |
15
|
|
|
private BicycleTesseractBridgeExtension $testInstance; |
16
|
|
|
|
17
|
|
|
/** @var DependencyInjection\ContainerBuilder|MockObject */ |
18
|
|
|
private $containerMock; |
19
|
|
|
|
20
|
|
|
/** @var DependencyInjection\Definition|MockObject */ |
21
|
|
|
private $serviceDefMock; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritDoc} |
25
|
|
|
*/ |
26
|
|
|
protected function setUp(): void |
27
|
|
|
{ |
28
|
|
|
parent::setUp(); |
29
|
|
|
|
30
|
|
|
$this->testInstance = new BicycleTesseractBridgeExtension(); |
31
|
|
|
$this->containerMock = $this |
32
|
|
|
->getMockBuilder(DependencyInjection\ContainerBuilder::class) |
33
|
|
|
->disableOriginalConstructor() |
34
|
|
|
->getMock(); |
35
|
|
|
$this->serviceDefMock = $this |
36
|
|
|
->getMockBuilder(DependencyInjection\Definition::class) |
37
|
|
|
->disableOriginalConstructor() |
38
|
|
|
->getMock(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
public function incorrectConfigDataProvider(): array |
45
|
|
|
{ |
46
|
|
|
return [ |
47
|
|
|
[ |
48
|
|
|
[], |
49
|
|
|
'The child ' . |
50
|
|
|
'(config "integrations" under)|(node "integrations" at path)' . |
51
|
|
|
' "bicycle_tesseract_bridge"| must be configured.', |
52
|
|
|
], |
53
|
|
|
[ |
54
|
|
|
['integrations' => []], |
55
|
|
|
'The child ' . |
56
|
|
|
'(config "integrations" under)|(node "integrations" at path)' . |
57
|
|
|
' "bicycle_tesseract_bridge" must be configured.', |
58
|
|
|
], |
59
|
|
|
[ |
60
|
|
|
['bicycle_tesseract_bridge' => []], |
61
|
|
|
'The child ' . |
62
|
|
|
'(config "integrations" under)|(node "integrations" at path)' . |
63
|
|
|
' "bicycle_tesseract_bridge" must be configured.', |
64
|
|
|
], |
65
|
|
|
[ |
66
|
|
|
['bicycle_tesseract_bridge' => ['integrations' => []]], |
67
|
|
|
'Invalid configuration for path "bicycle_tesseract_bridge.integrations": ' . |
68
|
|
|
'At least one integration must be enabled', |
69
|
|
|
], |
70
|
|
|
[ |
71
|
|
|
['bicycle_tesseract_bridge' => ['integrations' => ['cli' => [], 'ffi' => []]]], |
72
|
|
|
'Invalid configuration for path "bicycle_tesseract_bridge.integrations": ' . |
73
|
|
|
'Enabled integrations must have configured path', |
74
|
|
|
], |
75
|
|
|
[ |
76
|
|
|
['bicycle_tesseract_bridge' => ['integrations' => ['cli' => ['path' => 'test'], 'ffi' => []]]], |
77
|
|
|
'Invalid configuration for path "bicycle_tesseract_bridge.integrations": ' . |
78
|
|
|
'Enabled integrations must have configured path', |
79
|
|
|
], |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @dataProvider incorrectConfigDataProvider |
85
|
|
|
* |
86
|
|
|
* @param array $configuration |
87
|
|
|
* @param string $exceptionMessage |
88
|
|
|
*/ |
89
|
|
|
public function testIncorrectConfiguration(array $configuration, string $exceptionMessage): void |
90
|
|
|
{ |
91
|
|
|
$this->expectException(InvalidConfigurationException::class); |
92
|
|
|
$this->getExpectedExceptionMessageRegExp($exceptionMessage); |
|
|
|
|
93
|
|
|
$this->testInstance->load($configuration, $this->containerMock); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testLoad(): void |
97
|
|
|
{ |
98
|
|
|
$cliPath = 'cli test path'; |
99
|
|
|
$ffiPath = 'ffi test path'; |
100
|
|
|
|
101
|
|
|
$this |
102
|
|
|
->serviceDefMock |
103
|
|
|
->expects(self::once()) |
104
|
|
|
->method('replaceArgument') |
105
|
|
|
->with(0, ['binary_path' => $cliPath, 'library_path' => $ffiPath]); |
106
|
|
|
|
107
|
|
|
$this->containerMock->expects(self::once())->method('fileExists')->willReturn(false); |
108
|
|
|
$this->containerMock |
109
|
|
|
->expects(self::once()) |
110
|
|
|
->method('getDefinition') |
111
|
|
|
->with(Configuration::class) |
112
|
|
|
->willReturn($this->serviceDefMock); |
113
|
|
|
|
114
|
|
|
self::assertInstanceOf(DependencyInjection\Extension\Extension::class, $this->testInstance); |
115
|
|
|
$config = [ |
116
|
|
|
'bicycle_tesseract_bridge' => [ |
117
|
|
|
'integrations' => [ |
118
|
|
|
'cli' => [ |
119
|
|
|
'enabled' => true, |
120
|
|
|
'path' => $cliPath, |
121
|
|
|
], |
122
|
|
|
'ffi' => [ |
123
|
|
|
'enabled' => true, |
124
|
|
|
'path' => $ffiPath, |
125
|
|
|
], |
126
|
|
|
], |
127
|
|
|
], |
128
|
|
|
]; |
129
|
|
|
$this->testInstance->load($config, $this->containerMock); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.