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 | /* |
||
4 | * This file is part of the php-phantomjs. |
||
5 | * |
||
6 | * For the full copyright and license information, please view the LICENSE |
||
7 | * file that was distributed with this source code. |
||
8 | */ |
||
9 | namespace JonnyW\PhantomJs\Tests\Unit\Procedure; |
||
10 | |||
11 | use Twig_Environment; |
||
12 | use Twig_Loader_String; |
||
13 | use Symfony\Component\Config\FileLocatorInterface; |
||
14 | use JonnyW\PhantomJs\Engine; |
||
15 | use JonnyW\PhantomJs\Cache\FileCache; |
||
16 | use JonnyW\PhantomJs\Cache\CacheInterface; |
||
17 | use JonnyW\PhantomJs\Parser\JsonParser; |
||
18 | use JonnyW\PhantomJs\Parser\ParserInterface; |
||
19 | use JonnyW\PhantomJs\Template\TemplateRenderer; |
||
20 | use JonnyW\PhantomJs\Template\TemplateRendererInterface; |
||
21 | use JonnyW\PhantomJs\Procedure\ProcedureFactory; |
||
22 | use JonnyW\PhantomJs\Procedure\ProcedureFactoryInterface; |
||
23 | use JonnyW\PhantomJs\Procedure\ProcedureLoader; |
||
24 | |||
25 | /** |
||
26 | * PHP PhantomJs |
||
27 | * |
||
28 | * @author Jon Wenmoth <[email protected]> |
||
29 | */ |
||
30 | class ProcedureLoaderTest extends \PHPUnit_Framework_TestCase |
||
31 | { |
||
32 | /** |
||
33 | * Test filename |
||
34 | * |
||
35 | * @var string |
||
36 | * @access protected |
||
37 | */ |
||
38 | protected $filename; |
||
39 | |||
40 | /** |
||
41 | * Test directory |
||
42 | * |
||
43 | * @var string |
||
44 | * @access protected |
||
45 | */ |
||
46 | protected $directory; |
||
47 | |||
48 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
49 | /** ++++++++++++++ TESTS ++++++++++++++ **/ |
||
50 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
51 | |||
52 | /** |
||
53 | * Test invalid argument exception is thrown if procedure |
||
54 | * file is not local. |
||
55 | * |
||
56 | * @access public |
||
57 | * @return void |
||
58 | */ |
||
59 | public function testInvalidArgumentExceptionIsThrownIfProcedureFileIsNotLocal() |
||
60 | { |
||
61 | $this->setExpectedException('\InvalidArgumentException'); |
||
62 | |||
63 | $procedureFactory = $this->getProcedureFactory(); |
||
64 | $fileLocator = $this->getFileLocator(); |
||
65 | |||
66 | $fileLocator->method('locate') |
||
0 ignored issues
–
show
|
|||
67 | ->will($this->returnValue('http://example.com/index.html')); |
||
68 | |||
69 | $procedureLoader = $this->getProcedureLoader($procedureFactory, $fileLocator); |
||
70 | $procedureLoader->load('test'); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Test load throws not exists exception if |
||
75 | * if procedure file does not exist. |
||
76 | * |
||
77 | * @access public |
||
78 | * @return void |
||
79 | */ |
||
80 | public function testNotExistsExceptionIsThrownIfProcedureFileDoesNotExist() |
||
81 | { |
||
82 | $this->setExpectedException('\JonnyW\PhantomJs\Exception\NotExistsException'); |
||
83 | |||
84 | $procedureFactory = $this->getProcedureFactory(); |
||
85 | $fileLocator = $this->getFileLocator(); |
||
86 | |||
87 | $fileLocator->method('locate') |
||
0 ignored issues
–
show
The method
method() does not seem to exist on object<Symfony\Component...g\FileLocatorInterface> .
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.
Loading history...
|
|||
88 | ->will($this->returnValue('/invalid/file.proc')); |
||
89 | |||
90 | $procedureLoader = $this->getProcedureLoader($procedureFactory, $fileLocator); |
||
91 | $procedureLoader->load('test'); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Test procedure can be laoded. |
||
96 | * |
||
97 | * @access public |
||
98 | * @return void |
||
99 | */ |
||
100 | public function testProcedureCanBeLoaded() |
||
101 | { |
||
102 | $body = 'TEST_PROCEDURE'; |
||
103 | $file = $this->writeProcedure($body); |
||
104 | |||
105 | $procedureFactory = $this->getProcedureFactory(); |
||
106 | $fileLocator = $this->getFileLocator(); |
||
107 | |||
108 | $fileLocator->method('locate') |
||
0 ignored issues
–
show
The method
method() does not seem to exist on object<Symfony\Component...g\FileLocatorInterface> .
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.
Loading history...
|
|||
109 | ->will($this->returnValue($file)); |
||
110 | |||
111 | $procedureLoader = $this->getProcedureLoader($procedureFactory, $fileLocator); |
||
112 | |||
113 | $this->assertInstanceOf('\JonnyW\PhantomJs\Procedure\ProcedureInterface', $procedureLoader->load('test')); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Test procedure template is set in procedure |
||
118 | * instance. |
||
119 | * |
||
120 | * @access public |
||
121 | * @return void |
||
122 | */ |
||
123 | public function testProcedureTemplateIsSetInProcedureInstance() |
||
124 | { |
||
125 | $body = 'TEST_PROCEDURE'; |
||
126 | $file = $this->writeProcedure($body); |
||
127 | |||
128 | $procedureFactory = $this->getProcedureFactory(); |
||
129 | $fileLocator = $this->getFileLocator(); |
||
130 | |||
131 | $fileLocator->method('locate') |
||
0 ignored issues
–
show
The method
method() does not seem to exist on object<Symfony\Component...g\FileLocatorInterface> .
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.
Loading history...
|
|||
132 | ->will($this->returnValue($file)); |
||
133 | |||
134 | $procedureLoader = $this->getProcedureLoader($procedureFactory, $fileLocator); |
||
135 | |||
136 | $this->assertSame($body, $procedureLoader->load('test')->getTemplate()); |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * Test procedure template can be loaded. |
||
141 | * |
||
142 | * @access public |
||
143 | * @return void |
||
144 | */ |
||
145 | public function testProcedureTemplateCanBeLoaded() |
||
146 | { |
||
147 | $body = 'TEST_PROCEDURE'; |
||
148 | $file = $this->writeProcedure($body); |
||
149 | |||
150 | $procedureFactory = $this->getProcedureFactory(); |
||
151 | $fileLocator = $this->getFileLocator(); |
||
152 | |||
153 | $fileLocator->method('locate') |
||
0 ignored issues
–
show
The method
method() does not seem to exist on object<Symfony\Component...g\FileLocatorInterface> .
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.
Loading history...
|
|||
154 | ->will($this->returnValue($file)); |
||
155 | |||
156 | $procedureLoader = $this->getProcedureLoader($procedureFactory, $fileLocator); |
||
157 | |||
158 | $this->assertNotNull($procedureLoader->loadTemplate('test')); |
||
159 | } |
||
160 | |||
161 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
162 | /** ++++++++++ TEST ENTITIES ++++++++++ **/ |
||
163 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
164 | |||
165 | /** |
||
166 | * Get procedure loader instance. |
||
167 | * |
||
168 | * @access public |
||
169 | * @param \JonnyW\PhantomJs\Procedure\ProcedureFactoryInterface $procedureFactory |
||
170 | * @param \Symfony\Component\Config\FileLocatorInterface $locator |
||
171 | * @return \JonnyW\PhantomJs\Procedure\ProcedureLoader |
||
172 | */ |
||
173 | protected function getProcedureLoader(ProcedureFactoryInterface $procedureFactory, FileLocatorInterface $locator) |
||
174 | { |
||
175 | $procedureLoader = new ProcedureLoader($procedureFactory, $locator); |
||
176 | |||
177 | return $procedureLoader; |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Get procedure factory instance. |
||
182 | * |
||
183 | * @access protected |
||
184 | * @param \JonnyW\PhantomJs\Parser\ParserInterface $parser |
||
0 ignored issues
–
show
There is no parameter named
$parser . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not.
Loading history...
|
|||
185 | * @param \JonnyW\PhantomJs\Cache\CacheInterface $cacheHandler |
||
0 ignored issues
–
show
There is no parameter named
$cacheHandler . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not.
Loading history...
|
|||
186 | * @param \JonnyW\PhantomJs\Template\TemplateRendererInterface $renderer |
||
0 ignored issues
–
show
There is no parameter named
$renderer . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not.
Loading history...
|
|||
187 | * @return \JonnyW\PhantomJs\Procedure\ProcedureFactory |
||
188 | */ |
||
189 | protected function getProcedureFactory() |
||
190 | { |
||
191 | $engine = $this->getEngine(); |
||
192 | $parser = $this->getParser(); |
||
193 | $cache = $this->getCache(); |
||
194 | $renderer = $this->getRenderer(); |
||
195 | |||
196 | $procedureFactory = new ProcedureFactory($engine, $parser, $cache, $renderer); |
||
197 | |||
198 | return $procedureFactory; |
||
199 | } |
||
200 | |||
201 | /** |
||
202 | * Get engine. |
||
203 | * |
||
204 | * @access protected |
||
205 | * @return \JonnyW\PhantomJs\Engine |
||
206 | */ |
||
207 | protected function getEngine() |
||
208 | { |
||
209 | $engine = new Engine(); |
||
210 | |||
211 | return $engine; |
||
212 | } |
||
213 | |||
214 | /** |
||
215 | * Get parser. |
||
216 | * |
||
217 | * @access protected |
||
218 | * @return \JonnyW\PhantomJs\Parser\JsonParser |
||
219 | */ |
||
220 | protected function getParser() |
||
221 | { |
||
222 | $parser = new JsonParser(); |
||
223 | |||
224 | return $parser; |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * Get cache. |
||
229 | * |
||
230 | * @access protected |
||
231 | * @param string $cacheDir (default: '') |
||
232 | * @param string $extension (default: 'proc') |
||
233 | * @return \JonnyW\PhantomJs\Cache\FileCache |
||
234 | */ |
||
235 | protected function getCache($cacheDir = '', $extension = 'proc') |
||
236 | { |
||
237 | $cache = new FileCache(($cacheDir ? $cacheDir : sys_get_temp_dir()), 'proc'); |
||
238 | |||
239 | return $cache; |
||
240 | } |
||
241 | |||
242 | /** |
||
243 | * Get template renderer. |
||
244 | * |
||
245 | * @access protected |
||
246 | * @return \JonnyW\PhantomJs\Template\TemplateRenderer |
||
247 | */ |
||
248 | protected function getRenderer() |
||
249 | { |
||
250 | $twig = new Twig_Environment( |
||
251 | new Twig_Loader_String() |
||
252 | ); |
||
253 | |||
254 | $renderer = new TemplateRenderer($twig); |
||
255 | |||
256 | return $renderer; |
||
257 | } |
||
258 | |||
259 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
260 | /** ++++++++++ MOCKS / STUBS ++++++++++ **/ |
||
261 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
262 | |||
263 | /** |
||
264 | * Get file locator. |
||
265 | * |
||
266 | * @access protected |
||
267 | * @return \Symfony\Component\Config\FileLocatorInterface |
||
268 | */ |
||
269 | protected function getFileLocator() |
||
270 | { |
||
271 | $fileLocator = $this->getMock('\Symfony\Component\Config\FileLocatorInterface'); |
||
272 | |||
273 | return $fileLocator; |
||
274 | } |
||
275 | |||
276 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
277 | /** ++++++++++++ UTILITIES ++++++++++++ **/ |
||
278 | /** +++++++++++++++++++++++++++++++++++ **/ |
||
279 | |||
280 | /** |
||
281 | * Set up test environment. |
||
282 | * |
||
283 | * @access public |
||
284 | * @return void |
||
285 | */ |
||
286 | public function setUp() |
||
287 | { |
||
288 | $this->filename = 'test.proc'; |
||
289 | $this->directory = sys_get_temp_dir(); |
||
290 | |||
291 | if (!is_writable($this->directory)) { |
||
292 | throw new \RuntimeException(sprintf('Test directory must be writable: %s', $this->directory)); |
||
293 | } |
||
294 | } |
||
295 | |||
296 | /** |
||
297 | * Tear down test environment. |
||
298 | * |
||
299 | * @access public |
||
300 | * @return void |
||
301 | */ |
||
302 | public function tearDown() |
||
303 | { |
||
304 | $filename = $this->getFilename(); |
||
305 | |||
306 | if (file_exists($filename)) { |
||
307 | unlink($filename); |
||
308 | } |
||
309 | } |
||
310 | |||
311 | /** |
||
312 | * Get test filename. |
||
313 | * |
||
314 | * @access public |
||
315 | * @return string |
||
316 | */ |
||
317 | public function getFilename() |
||
318 | { |
||
319 | return sprintf('%1$s/%2$s', $this->directory, $this->filename); |
||
320 | } |
||
321 | |||
322 | /** |
||
323 | * Write procedure body to file. |
||
324 | * |
||
325 | * @access public |
||
326 | * @param string $data |
||
0 ignored issues
–
show
There is no parameter named
$data . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not.
Loading history...
|
|||
327 | * @return string |
||
328 | */ |
||
329 | public function writeProcedure($procedure) |
||
330 | { |
||
331 | $filename = $this->getFilename(); |
||
332 | |||
333 | file_put_contents($filename, $procedure); |
||
334 | |||
335 | return $filename; |
||
336 | } |
||
337 | } |
||
338 |
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.