This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * This file is part of phpDocumentor. |
||
4 | * |
||
5 | * For the full copyright and license information, please view the LICENSE |
||
6 | * file that was distributed with this source code. |
||
7 | * |
||
8 | * @copyright 2010-2015 Mike van Riel<[email protected]> |
||
9 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
||
10 | * @link http://phpdoc.org |
||
11 | */ |
||
12 | |||
13 | namespace phpDocumentor\Configuration; |
||
14 | |||
15 | use Mockery\Adapter\Phpunit\MockeryTestCase; |
||
16 | use Mockery as m; |
||
17 | use org\bovigo\vfs\vfsStream; |
||
18 | use phpDocumentor\Configuration\Factory\Strategy; |
||
19 | use phpDocumentor\Configuration\Factory\Version2; |
||
20 | use phpDocumentor\Configuration\Factory\Version3; |
||
21 | use phpDocumentor\Configuration\Exception\InvalidConfigPathException; |
||
22 | use phpDocumentor\Uri; |
||
23 | |||
24 | /** |
||
25 | * Test case for ConfigurationFactory |
||
26 | * |
||
27 | * @coversDefaultClass \phpDocumentor\Configuration\ConfigurationFactory |
||
28 | * @covers ::<private> |
||
29 | * @covers ::__construct |
||
30 | */ |
||
31 | final class ConfigurationFactoryTest extends MockeryTestCase |
||
32 | { |
||
33 | /** |
||
34 | * @covers ::fromUri |
||
35 | */ |
||
36 | public function testItLoadsASpecificConfigurationFileUsingTheCorrectStrategy() |
||
37 | { |
||
38 | $configurationFactory = new ConfigurationFactory( |
||
39 | [ |
||
40 | new Version3('data/xsd/phpdoc.xsd'), |
||
41 | new Version2() |
||
42 | ], |
||
43 | [] |
||
44 | ); |
||
45 | |||
46 | $content = '<phpdocumentor><title>My title</title></phpdocumentor>'; |
||
47 | $configuration = $configurationFactory->fromUri( |
||
48 | new Uri($this->givenExampleConfigurationFileWithContent($content)) |
||
49 | ); |
||
50 | |||
51 | $this->assertSame('My title', $configuration['phpdocumentor']['title']); |
||
52 | } |
||
53 | /** |
||
54 | * @covers ::fromUri |
||
55 | */ |
||
56 | public function testLoadingFromUriFailsIfFileDoesNotExist() |
||
57 | { |
||
58 | $this->expectException(InvalidConfigPathException::class); |
||
59 | $this->expectExceptionMessage('File file:///does-not-exist could not be found'); |
||
60 | $configurationFactory = new ConfigurationFactory([new Version2()], []); |
||
61 | $configurationFactory->fromUri(new Uri('/does-not-exist')); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @covers ::fromDefaultLocations() |
||
66 | */ |
||
67 | public function testThatTheDefaultConfigurationFilesAreLoaded() |
||
68 | { |
||
69 | $file = $this->givenExampleConfigurationFileWithContent( |
||
70 | '<phpdocumentor><title>My title</title></phpdocumentor>' |
||
71 | ); |
||
72 | $configurationFactory = new ConfigurationFactory([new Version2()], [$file]); |
||
73 | |||
74 | $configuration = $configurationFactory->fromDefaultLocations(); |
||
75 | |||
76 | $this->assertSame('My title', $configuration['phpdocumentor']['title']); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @covers ::fromDefaultLocations() |
||
81 | */ |
||
82 | public function testWhenNoneOfTheDefaultsExistThatTheBakedConfigIsUsed() |
||
83 | { |
||
84 | $configurationFactory = new ConfigurationFactory([new Version2()], ['does_not_exist.xml']); |
||
85 | |||
86 | $configuration = $configurationFactory->fromDefaultLocations(); |
||
87 | |||
88 | $this->assertEquals(Version3::buildDefault(), $configuration->getArrayCopy()); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @covers ::fromDefaultLocations() |
||
93 | */ |
||
94 | public function testWhenDefaultFileIsInvalidXMLThenAnExceptionIsRaised() |
||
95 | { |
||
96 | $file = $this->givenExampleConfigurationFileWithContent( |
||
97 | '<?xml version="1.0" encoding="UTF-8" ?>' . |
||
98 | '<phpdocumentor xmlns="http://www.phpdoc.org" version="3">' . |
||
99 | '<foo/>' . |
||
100 | '</phpdocumentor>' |
||
101 | ); |
||
102 | $configurationFactory = new ConfigurationFactory( |
||
103 | [new Version3(__DIR__ . '/../../../../data/xsd/phpdoc.xsd')], |
||
104 | [$file] |
||
105 | ); |
||
106 | |||
107 | $this->expectException(\InvalidArgumentException::class); |
||
108 | $this->expectExceptionMessage( |
||
109 | "Element '{http://www.phpdoc.org}foo': This element is not expected. " |
||
110 | . "Expected is ( {http://www.phpdoc.org}paths )." |
||
111 | ); |
||
112 | $configurationFactory->fromDefaultLocations(); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @covers ::addMiddleware |
||
117 | */ |
||
118 | public function testThatMiddlewaresCanBeAddedAndAreThenApplied() |
||
119 | { |
||
120 | $inputValue = ['test']; |
||
121 | $afterMiddleware1Value = ['test', 'test2']; |
||
122 | $afterMiddleware2Value = ['test', 'test2', 'test3']; |
||
123 | |||
124 | $middleWare1 = $this->givenAMiddlewareThatReturns($inputValue, $afterMiddleware1Value); |
||
125 | $middleWare2 = $this->givenAMiddlewareThatReturns($afterMiddleware1Value, $afterMiddleware2Value); |
||
126 | |||
127 | $factory = new ConfigurationFactory([$this->givenAValidStrategyThatReturns($inputValue)], []); |
||
128 | $factory->addMiddleware($middleWare1); |
||
129 | $factory->addMiddleware($middleWare2); |
||
130 | |||
131 | $data = $factory->fromUri(new Uri($this->givenExampleConfigurationFileWithContent('<foo></foo>'))); |
||
132 | |||
133 | $this->assertSame($afterMiddleware2Value, $data->getArrayCopy()); |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * @covers ::fromUri |
||
138 | * @expectedException \Exception |
||
139 | * @expectedExceptionMessage No supported configuration files were found |
||
140 | */ |
||
141 | public function testItHaltsIfNoMatchingStrategyCanBeFound() |
||
142 | { |
||
143 | $strategies = []; // No strategy means nothing could match ;) |
||
144 | $configurationFactory = new ConfigurationFactory($strategies, []); |
||
145 | |||
146 | $configurationFactory->fromUri( |
||
147 | new Uri($this->givenExampleConfigurationFileWithContent('<foo></foo>')) |
||
148 | ); |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * @covers ::__construct |
||
153 | * @expectedException \TypeError |
||
154 | */ |
||
155 | public function testItErrorsWhenTryingToInitializeWithSomethingOtherThanAStrategy() |
||
156 | { |
||
157 | new ConfigurationFactory(['this_is_not_a_strategy'], []); |
||
0 ignored issues
–
show
|
|||
158 | } |
||
159 | |||
160 | private function givenExampleConfigurationFileWithContent($content): string |
||
161 | { |
||
162 | vfsStream::newFile('foo.xml') |
||
163 | ->at(vfsStream::setup('dir')) |
||
164 | ->withContent($content); |
||
165 | |||
166 | return vfsStream::url('dir/foo.xml'); |
||
167 | } |
||
168 | |||
169 | private function givenAMiddlewareThatReturns($expectedInputValue, $returnValue): \Closure |
||
170 | { |
||
171 | return function ($value) use ($expectedInputValue, $returnValue) { |
||
172 | $this->assertSame($expectedInputValue, $value); |
||
173 | |||
174 | return $returnValue; |
||
175 | }; |
||
176 | } |
||
177 | |||
178 | private function givenAValidStrategyThatReturns($result): Strategy |
||
179 | { |
||
180 | /** @var m\Mock $strategy */ |
||
181 | $strategy = m::mock(Strategy::class); |
||
182 | $strategy->shouldReceive('supports') |
||
183 | ->once() |
||
184 | ->with(m::type(\SimpleXMLElement::class)) |
||
185 | ->andReturn(true); |
||
186 | $strategy |
||
187 | ->shouldReceive('convert') |
||
188 | ->once() |
||
189 | ->with(m::type(\SimpleXMLElement::class))->andReturn($result); |
||
190 | |||
191 | return $strategy; |
||
192 | } |
||
193 | } |
||
194 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: