1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Ekino New Relic bundle. |
7
|
|
|
* |
8
|
|
|
* (c) Ekino - Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Ekino\NewRelicBundle\Tests\DependencyInjection; |
15
|
|
|
|
16
|
|
|
use Ekino\NewRelicBundle\DependencyInjection\Configuration; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
18
|
|
|
use Symfony\Component\Config\Definition\Processor; |
19
|
|
|
use Symfony\Component\Config\Definition\PrototypedArrayNode; |
20
|
|
|
|
21
|
|
|
class ConfigurationTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
public function testIgnoredRoutes() |
24
|
|
|
{ |
25
|
|
|
$configuration = new Configuration(); |
26
|
|
|
$rootNode = $configuration->getConfigTreeBuilder() |
27
|
|
|
->buildTree(); |
28
|
|
|
$children = $rootNode->getChildren(); |
29
|
|
|
|
30
|
|
|
/** @var PrototypedArrayNode $ignoredRoutesNode */ |
31
|
|
|
$ignoredRoutesNode = $children['http']->getChildren()['ignored_routes']; |
32
|
|
|
|
33
|
|
|
$this->assertInstanceOf('\Symfony\Component\Config\Definition\PrototypedArrayNode', $ignoredRoutesNode); |
34
|
|
|
$this->assertFalse($ignoredRoutesNode->isRequired()); |
35
|
|
|
$this->assertEmpty($ignoredRoutesNode->getDefaultValue()); |
36
|
|
|
|
37
|
|
|
$this->assertSame(['ignored_route1', 'ignored_route2'], $ignoredRoutesNode->normalize(['ignored_route1', 'ignored_route2'])); |
38
|
|
|
$this->assertSame(['ignored_route'], $ignoredRoutesNode->normalize('ignored_route')); |
39
|
|
|
$this->assertSame(['ignored_route1', 'ignored_route2'], $ignoredRoutesNode->merge(['ignored_route1'], ['ignored_route2'])); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testIgnoredPaths() |
43
|
|
|
{ |
44
|
|
|
$configuration = new Configuration(); |
45
|
|
|
$rootNode = $configuration->getConfigTreeBuilder() |
46
|
|
|
->buildTree(); |
47
|
|
|
$children = $rootNode->getChildren(); |
48
|
|
|
|
49
|
|
|
/** @var PrototypedArrayNode $ignoredPathsNode */ |
50
|
|
|
$ignoredPathsNode = $children['http']->getChildren()['ignored_paths']; |
51
|
|
|
|
52
|
|
|
$this->assertInstanceOf('\Symfony\Component\Config\Definition\PrototypedArrayNode', $ignoredPathsNode); |
53
|
|
|
$this->assertFalse($ignoredPathsNode->isRequired()); |
54
|
|
|
$this->assertEmpty($ignoredPathsNode->getDefaultValue()); |
55
|
|
|
|
56
|
|
|
$this->assertSame(['/ignored/path1', '/ignored/path2'], $ignoredPathsNode->normalize(['/ignored/path1', '/ignored/path2'])); |
57
|
|
|
$this->assertSame(['/ignored/path'], $ignoredPathsNode->normalize('/ignored/path')); |
58
|
|
|
$this->assertSame(['/ignored/path1', '/ignored/path2'], $ignoredPathsNode->merge(['/ignored/path1'], ['/ignored/path2'])); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testIgnoredCommands() |
62
|
|
|
{ |
63
|
|
|
$configuration = new Configuration(); |
64
|
|
|
$rootNode = $configuration->getConfigTreeBuilder() |
65
|
|
|
->buildTree(); |
66
|
|
|
$children = $rootNode->getChildren(); |
67
|
|
|
|
68
|
|
|
/** @var PrototypedArrayNode $ignoredCommandsNode */ |
69
|
|
|
$ignoredCommandsNode = $children['commands']->getChildren()['ignored_commands']; |
70
|
|
|
|
71
|
|
|
$this->assertInstanceOf('\Symfony\Component\Config\Definition\PrototypedArrayNode', $ignoredCommandsNode); |
72
|
|
|
$this->assertFalse($ignoredCommandsNode->isRequired()); |
73
|
|
|
$this->assertEmpty($ignoredCommandsNode->getDefaultValue()); |
74
|
|
|
|
75
|
|
|
$this->assertSame(['test:ignored-command1', 'test:ignored-command2'], $ignoredCommandsNode->normalize(['test:ignored-command1', 'test:ignored-command2'])); |
76
|
|
|
$this->assertSame(['test:ignored-command'], $ignoredCommandsNode->normalize('test:ignored-command')); |
77
|
|
|
$this->assertSame(['test:ignored-command1', 'test:ignored-command2'], $ignoredCommandsNode->merge(['test:ignored-command1'], ['test:ignored-command2'])); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testDefaults() |
81
|
|
|
{ |
82
|
|
|
$processor = new Processor(); |
83
|
|
|
|
84
|
|
|
$config = $processor->processConfiguration(new Configuration(), []); |
85
|
|
|
|
86
|
|
|
$this->assertEmpty($config['http']['ignored_routes']); |
87
|
|
|
$this->assertInternalType('array', $config['http']['ignored_routes']); |
88
|
|
|
$this->assertEmpty($config['http']['ignored_paths']); |
89
|
|
|
$this->assertInternalType('array', $config['http']['ignored_paths']); |
90
|
|
|
$this->assertEmpty($config['commands']['ignored_commands']); |
91
|
|
|
$this->assertInternalType('array', $config['commands']['ignored_commands']); |
92
|
|
|
$this->assertEmpty($config['deployment_names']); |
93
|
|
|
$this->assertInternalType('array', $config['deployment_names']); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public static function ignoredRoutesProvider() |
97
|
|
|
{ |
98
|
|
|
return [ |
99
|
|
|
['single_ignored_route', ['single_ignored_route']], |
100
|
|
|
[['single_ignored_route'], ['single_ignored_route']], |
101
|
|
|
[['ignored_route1', 'ignored_route2'], ['ignored_route1', 'ignored_route2']], |
102
|
|
|
]; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public static function ignoredPathsProvider() |
106
|
|
|
{ |
107
|
|
|
return [ |
108
|
|
|
['/single/ignored/path', ['/single/ignored/path']], |
109
|
|
|
[['/single/ignored/path'], ['/single/ignored/path']], |
110
|
|
|
[['/ignored/path1', '/ignored/path2'], ['/ignored/path1', '/ignored/path2']], |
111
|
|
|
]; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public static function ignoredCommandsProvider() |
115
|
|
|
{ |
116
|
|
|
return [ |
117
|
|
|
['single:ignored:command', ['single:ignored:command']], |
118
|
|
|
[['single:ignored:command'], ['single:ignored:command']], |
119
|
|
|
[['ignored:command1', 'ignored:command2'], ['ignored:command1', 'ignored:command2']], |
120
|
|
|
]; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public static function deploymentNamesProvider() |
124
|
|
|
{ |
125
|
|
|
return [ |
126
|
|
|
['App1', ['App1']], |
127
|
|
|
[['App1'], ['App1']], |
128
|
|
|
[['App1', 'App2'], ['App1', 'App2']], |
129
|
|
|
]; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @dataProvider deploymentNamesProvider |
134
|
|
|
*/ |
135
|
|
|
public function testDeploymentNames($deploymentNameConfig, $expected) |
136
|
|
|
{ |
137
|
|
|
$processor = new Processor(); |
138
|
|
|
|
139
|
|
|
$config1 = $processor->processConfiguration(new Configuration(), ['ekino_new_relic' => ['deployment_name' => $deploymentNameConfig]]); |
140
|
|
|
$config2 = $processor->processConfiguration(new Configuration(), ['ekino_new_relic' => ['deployment_names' => $deploymentNameConfig]]); |
141
|
|
|
|
142
|
|
|
$this->assertSame($expected, $config1['deployment_names']); |
143
|
|
|
$this->assertSame($expected, $config2['deployment_names']); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @dataProvider ignoredRoutesProvider |
148
|
|
|
*/ |
149
|
|
|
public function testIgnoreRoutes($ignoredRoutesConfig, $expected) |
150
|
|
|
{ |
151
|
|
|
$processor = new Processor(); |
152
|
|
|
|
153
|
|
|
$config = $processor->processConfiguration(new Configuration(), ['ekino_new_relic' => ['http' => ['ignored_routes' => $ignoredRoutesConfig]]]); |
154
|
|
|
|
155
|
|
|
$this->assertSame($expected, $config['http']['ignored_routes']); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @dataProvider ignoredPathsProvider |
160
|
|
|
*/ |
161
|
|
|
public function testIgnorePaths($ignoredPathsConfig, $expected) |
162
|
|
|
{ |
163
|
|
|
$processor = new Processor(); |
164
|
|
|
|
165
|
|
|
$config = $processor->processConfiguration(new Configuration(), ['ekino_new_relic' => ['http' => ['ignored_paths' => $ignoredPathsConfig]]]); |
166
|
|
|
|
167
|
|
|
$this->assertSame($expected, $config['http']['ignored_paths']); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @dataProvider ignoredCommandsProvider |
172
|
|
|
*/ |
173
|
|
|
public function testIgnoreCommands($ignoredCommandsConfig, $expected) |
174
|
|
|
{ |
175
|
|
|
$processor = new Processor(); |
176
|
|
|
|
177
|
|
|
$config = $processor->processConfiguration(new Configuration(), ['ekino_new_relic' => ['commands' => ['ignored_commands' => $ignoredCommandsConfig]]]); |
178
|
|
|
|
179
|
|
|
$this->assertSame($expected, $config['commands']['ignored_commands']); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths