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 config "integrations" under "bicycle_tesseract_bridge" must be configured.', |
50
|
|
|
], |
51
|
|
|
[ |
52
|
|
|
['integrations' => []], |
53
|
|
|
'The child config "integrations" under "bicycle_tesseract_bridge" must be configured.', |
54
|
|
|
], |
55
|
|
|
[ |
56
|
|
|
['bicycle_tesseract_bridge' => []], |
57
|
|
|
'The child config "integrations" under "bicycle_tesseract_bridge" must be configured.', |
58
|
|
|
], |
59
|
|
|
[ |
60
|
|
|
['bicycle_tesseract_bridge' => ['integrations' => []]], |
61
|
|
|
'Invalid configuration for path "bicycle_tesseract_bridge.integrations": ' . |
62
|
|
|
'At least one integration must be enabled', |
63
|
|
|
], |
64
|
|
|
[ |
65
|
|
|
['bicycle_tesseract_bridge' => ['integrations' => ['cli' => [], 'ffi' => []]]], |
66
|
|
|
'Invalid configuration for path "bicycle_tesseract_bridge.integrations": ' . |
67
|
|
|
'Enabled integrations must have configured path', |
68
|
|
|
], |
69
|
|
|
[ |
70
|
|
|
['bicycle_tesseract_bridge' => ['integrations' => ['cli' => ['path' => 'test'], 'ffi' => []]]], |
71
|
|
|
'Invalid configuration for path "bicycle_tesseract_bridge.integrations": ' . |
72
|
|
|
'Enabled integrations must have configured path', |
73
|
|
|
], |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @dataProvider incorrectConfigDataProvider |
79
|
|
|
* |
80
|
|
|
* @param array $configuration |
81
|
|
|
* @param string $exceptionMessage |
82
|
|
|
*/ |
83
|
|
|
public function testIncorrectConfiguration(array $configuration, string $exceptionMessage): void |
84
|
|
|
{ |
85
|
|
|
$this->expectException(InvalidConfigurationException::class); |
86
|
|
|
$this->expectExceptionMessage($exceptionMessage); |
87
|
|
|
$this->testInstance->load($configuration, $this->containerMock); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testLoad(): void |
91
|
|
|
{ |
92
|
|
|
$cliPath = 'cli test path'; |
93
|
|
|
$ffiPath = 'ffi test path'; |
94
|
|
|
|
95
|
|
|
$this |
96
|
|
|
->serviceDefMock |
97
|
|
|
->expects(self::once()) |
98
|
|
|
->method('replaceArgument') |
99
|
|
|
->with(0, ['binary_path' => $cliPath, 'library_path' => $ffiPath]); |
100
|
|
|
|
101
|
|
|
$this->containerMock->expects(self::once())->method('fileExists')->willReturn(false); |
102
|
|
|
$this->containerMock |
103
|
|
|
->expects(self::once()) |
104
|
|
|
->method('getDefinition') |
105
|
|
|
->with(Configuration::class) |
106
|
|
|
->willReturn($this->serviceDefMock); |
107
|
|
|
|
108
|
|
|
self::assertInstanceOf(DependencyInjection\Extension\Extension::class, $this->testInstance); |
109
|
|
|
$config = [ |
110
|
|
|
'bicycle_tesseract_bridge' => [ |
111
|
|
|
'integrations' => [ |
112
|
|
|
'cli' => [ |
113
|
|
|
'enabled' => true, |
114
|
|
|
'path' => $cliPath, |
115
|
|
|
], |
116
|
|
|
'ffi' => [ |
117
|
|
|
'enabled' => true, |
118
|
|
|
'path' => $ffiPath, |
119
|
|
|
], |
120
|
|
|
], |
121
|
|
|
], |
122
|
|
|
]; |
123
|
|
|
$this->testInstance->load($config, $this->containerMock); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|