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 | * phpDocumentor |
||
4 | * |
||
5 | * PHP Version 5.3 |
||
6 | * |
||
7 | * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
||
8 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
||
9 | * @link http://phpdoc.org |
||
10 | */ |
||
11 | |||
12 | namespace phpDocumentor\Transformer\Template; |
||
13 | |||
14 | use Mockery as m; |
||
15 | use org\bovigo\vfs\vfsStream; |
||
16 | use phpDocumentor\Transformer\Template; |
||
17 | |||
18 | class FactoryTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
||
19 | { |
||
20 | /** @var m\MockInterface|PathResolver */ |
||
21 | private $pathResolverMock; |
||
22 | |||
23 | /** @var Factory */ |
||
24 | private $fixture; |
||
25 | |||
26 | /** |
||
27 | * Sets up the fixture with mocked dependencies. |
||
28 | */ |
||
29 | protected function setUp() |
||
30 | { |
||
31 | $this->pathResolverMock = m::mock('phpDocumentor\Transformer\Template\PathResolver'); |
||
32 | |||
33 | $this->fixture = new Factory($this->pathResolverMock); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @covers phpDocumentor\Transformer\Template\Factory::__construct |
||
38 | */ |
||
39 | public function testIfDependenciesAreCorrectlyRegisteredOnInitialization() |
||
40 | { |
||
41 | $this->assertAttributeSame($this->pathResolverMock, 'pathResolver', $this->fixture); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @covers phpDocumentor\Transformer\Template\Factory::get |
||
46 | * @covers phpDocumentor\Transformer\Template\Factory::fetchTemplateXmlFromPath |
||
47 | * @covers phpDocumentor\Transformer\Template\Factory::createTemplateFromXml |
||
48 | * @todo test parameters in template and transformations |
||
49 | */ |
||
50 | public function testRetrieveInstantiatedTemplate() |
||
51 | { |
||
52 | // Arrange |
||
53 | $templateName = 'clean'; |
||
54 | $xml = <<<'XML' |
||
55 | <?xml version="1.0" encoding="utf-8"?> |
||
56 | <template> |
||
57 | <name>clean</name> |
||
58 | <author>Mike van Riel</author> |
||
59 | <email>[email protected]</email> |
||
60 | <version>1.0.0</version> |
||
61 | <copyright>Mike van Riel 2013</copyright> |
||
62 | <description><![CDATA[This is the description]]></description> |
||
63 | <transformations> |
||
64 | <transformation query="copy" writer="FileIo" source="templates/clean/htaccess.dist" artifact=".htaccess"/> |
||
65 | <transformation query="copy" writer="FileIo" source="templates/clean/images" artifact="images"/> |
||
66 | <transformation query="copy" writer="FileIo" source="templates/clean/css" artifact="css"/> |
||
67 | <transformation query="copy" writer="FileIo" source="templates/clean/js" artifact="js"/> |
||
68 | <transformation query="copy" writer="FileIo" source="templates/clean/font" artifact="font"/> |
||
69 | <transformation writer="twig" query="namespace" source="templates/clean/namespace.html.twig" artifact="index.html"/> |
||
70 | <transformation writer="twig" query="indexes.namespaces" source="templates/clean/namespace.html.twig" /> |
||
71 | <transformation writer="twig" query="indexes.classes" source="templates/clean/class.html.twig" /> |
||
72 | <transformation writer="twig" query="indexes.interfaces" source="templates/clean/interface.html.twig" /> |
||
73 | <transformation writer="twig" query="indexes.traits" source="templates/clean/class.html.twig" /> |
||
74 | <transformation writer="twig" query="files" source="templates/clean/file.html.twig" /> |
||
75 | <transformation |
||
76 | writer="twig" |
||
77 | query="files" |
||
78 | source="templates/clean/file.source.txt.twig" |
||
79 | artifact="files/{{path}}.txt" |
||
80 | /> |
||
81 | <transformation writer="twig" source="templates/clean/reports/markers.html.twig" artifact="reports/markers.html"/> |
||
82 | <transformation writer="twig" source="templates/clean/reports/errors.html.twig" artifact="reports/errors.html"/> |
||
83 | <transformation |
||
84 | writer="twig" |
||
85 | source="templates/clean/reports/deprecated.html.twig" |
||
86 | artifact="reports/deprecated.html" |
||
87 | /> |
||
88 | <transformation writer="twig" source="templates/clean/graphs/class.html.twig" artifact="graphs/class.html"/> |
||
89 | <transformation writer="Graph" source="Class" artifact="graphs/classes.svg" /> |
||
90 | </transformations> |
||
91 | </template> |
||
92 | XML; |
||
93 | vfsStream::setup('exampleDir')->addChild(vfsStream::newFile('template.xml')->setContent($xml)); |
||
94 | $this->pathResolverMock->shouldReceive('resolve')->with($templateName)->andReturn(vfsStream::url('exampleDir')); |
||
0 ignored issues
–
show
|
|||
95 | |||
96 | // Act |
||
97 | $result = $this->fixture->get($templateName); |
||
98 | |||
99 | // Assert |
||
100 | $this->assertSame($templateName, $result->getName()); |
||
101 | $this->assertSame('Mike van Riel <[email protected]>', $result->getAuthor()); |
||
102 | $this->assertSame('1.0.0', $result->getVersion()); |
||
103 | $this->assertSame('Mike van Riel 2013', $result->getCopyright()); |
||
104 | $this->assertSame('This is the description', $result->getDescription()); |
||
105 | $this->assertSame(17, $result->count()); |
||
106 | $this->assertSame('copy', $result[0]->getQuery()); |
||
107 | $this->assertSame('FileIo', $result[0]->getWriter()); |
||
108 | $this->assertSame('templates/clean/htaccess.dist', $result[0]->getSource()); |
||
109 | $this->assertSame('.htaccess', $result[0]->getArtifact()); |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @covers phpDocumentor\Transformer\Template\Factory::getTemplatePath |
||
114 | */ |
||
115 | public function testReturnTemplatePathFromResolver() |
||
116 | { |
||
117 | // Arrange |
||
118 | $expected = 'test'; |
||
119 | $this->pathResolverMock->shouldReceive('getTemplatePath')->andReturn($expected); |
||
0 ignored issues
–
show
The method
shouldReceive does only exist in Mockery\MockInterface , but not in phpDocumentor\Transformer\Template\PathResolver .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
120 | |||
121 | // Act |
||
122 | $result = $this->fixture->getTemplatePath(); |
||
123 | |||
124 | // Assert |
||
125 | $this->assertSame($expected, $result); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * @covers phpDocumentor\Transformer\Template\Factory::getAllNames |
||
130 | */ |
||
131 | public function testRetrieveAllTemplateNames() |
||
132 | { |
||
133 | // Arrange |
||
134 | $expected = ['template1', 'template2']; |
||
135 | $root = vfsStream::setup('exampleDir'); |
||
136 | $root->addChild(vfsStream::newDirectory($expected[0])); |
||
137 | $root->addChild(vfsStream::newFile('aFile.txt')); |
||
138 | $root->addChild(vfsStream::newDirectory($expected[1])); |
||
139 | $this->pathResolverMock->shouldReceive('getTemplatePath')->andReturn(vfsStream::url('exampleDir')); |
||
0 ignored issues
–
show
The method
shouldReceive does only exist in Mockery\MockInterface , but not in phpDocumentor\Transformer\Template\PathResolver .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
140 | |||
141 | // Act |
||
142 | $result = $this->fixture->getAllNames(); |
||
143 | |||
144 | // Assert |
||
145 | $this->assertSame($expected, $result); |
||
146 | } |
||
147 | } |
||
148 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: