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 | * phpDocumentor |
||
5 | * |
||
6 | * PHP Version 5.3 |
||
7 | * |
||
8 | * @author Mike van Riel <[email protected]> |
||
9 | * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
||
10 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
||
11 | * @link http://phpdoc.org |
||
12 | */ |
||
13 | |||
14 | namespace phpDocumentor\Transformer\Writer; |
||
15 | |||
16 | use Mockery as m; |
||
17 | use org\bovigo\vfs\vfsStream; |
||
18 | |||
19 | use org\bovigo\vfs\vfsStreamDirectory; |
||
20 | use phpDocumentor\Descriptor\ProjectDescriptor; |
||
21 | use phpDocumentor\Transformer\Router\RouterAbstract; |
||
22 | |||
23 | /** |
||
24 | * Test class for \phpDocumentor\Transformer\Writer\Xml. |
||
25 | * |
||
26 | * @covers phpDocumentor\Transformer\Writer\Xml |
||
27 | */ |
||
28 | class XmlTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
||
29 | { |
||
30 | /** @var Xml $xml */ |
||
31 | protected $xml; |
||
32 | |||
33 | /** @var m\MockInterface|RouterAbstract */ |
||
34 | protected $routerMock; |
||
35 | |||
36 | /** @var m\MockInterface|ProjectDescriptor */ |
||
37 | protected $projectDescriptor; |
||
38 | |||
39 | /** @var vfsStreamDirectory */ |
||
40 | protected $fs; |
||
41 | |||
42 | /** |
||
43 | * Sets up the test suite |
||
44 | */ |
||
45 | protected function setUp() |
||
46 | { |
||
47 | $this->fs = vfsStream::setup('XmlTest'); |
||
48 | $this->projectDescriptor = m::mock('phpDocumentor\Descriptor\ProjectDescriptor'); |
||
49 | $this->routerMock = m::mock('phpDocumentor\Transformer\Router\RouterAbstract'); |
||
50 | $this->xml = new Xml($this->routerMock); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @covers phpDocumentor\Transformer\Writer\Xml::transform |
||
55 | */ |
||
56 | public function testTransformWithoutFiles() |
||
57 | { |
||
58 | $transformer = m::mock('phpDocumentor\Transformer\Transformer'); |
||
59 | $transformation = m::mock('phpDocumentor\Transformer\Transformation'); |
||
60 | $transformation->shouldReceive('getTransformer->getTarget')->andReturn(vfsStream::url('XmlTest')); |
||
0 ignored issues
–
show
|
|||
61 | $transformation->shouldReceive('getArtifact')->andReturn('artifact.xml'); |
||
62 | $transformation->shouldReceive('getTransformer')->andReturn($transformer); |
||
63 | |||
64 | $this->projectDescriptor->shouldReceive('getFiles')->andReturn([]); |
||
0 ignored issues
–
show
The method
shouldReceive does only exist in Mockery\MockInterface , but not in phpDocumentor\Descriptor\ProjectDescriptor .
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...
|
|||
65 | $this->projectDescriptor->shouldReceive('getName')->andReturn('project'); |
||
66 | $this->projectDescriptor->shouldReceive('getPartials')->andReturn([]); |
||
67 | |||
68 | $this->implementProtectedFinalize($this->projectDescriptor); |
||
69 | |||
70 | // Call the actual method |
||
71 | $this->xml->transform($this->projectDescriptor, $transformation); |
||
72 | |||
73 | // Check file exists |
||
74 | $this->assertTrue($this->fs->hasChild('artifact.xml')); |
||
75 | |||
76 | // Inspect XML |
||
77 | $xml = <<<XML |
||
78 | <?xml version="1.0" encoding="utf-8"?> |
||
79 | <project version="2.0.0b8 " title="project"> |
||
80 | <partials/> |
||
81 | <package name="global" full_name="global"/> |
||
82 | <deprecated count="0"/> |
||
83 | </project> |
||
84 | XML; |
||
85 | $expectedXml = new \DOMDocument(); |
||
86 | $expectedXml->loadXML($xml); |
||
87 | |||
88 | $actualXml = new \DOMDocument(); |
||
89 | $actualXml->load(vfsStream::url('XmlTest/artifact.xml')); |
||
90 | |||
91 | $this->assertEqualXMLStructure($expectedXml->firstChild, $actualXml->firstChild, true); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @covers phpDocumentor\Transformer\Writer\Xml::transform |
||
96 | */ |
||
97 | public function testTransformWithEmptyFileDescriptor() |
||
98 | { |
||
99 | $transformer = m::mock('phpDocumentor\Transformer\Transformer'); |
||
100 | $transformer->shouldReceive('getTarget')->andReturn(vfsStream::url('XmlTest')); |
||
0 ignored issues
–
show
The method
andReturn does only exist in Mockery\ExpectationInterface , but not in Mockery\HigherOrderMessage .
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...
|
|||
101 | |||
102 | $transformation = m::mock('phpDocumentor\Transformer\Transformation'); |
||
103 | $transformation->shouldReceive('getArtifact')->andReturn('artifact.xml'); |
||
104 | $transformation->shouldReceive('getTransformer')->andReturn($transformer); |
||
105 | |||
106 | $fileDescriptor = m::mock('phpDocumentor\Descriptor\FileDescriptor'); |
||
107 | $fileDescriptor->shouldReceive('getPath')->andReturn('foo.php'); |
||
108 | $fileDescriptor->shouldReceive('getInheritedElement')->andReturn(null); |
||
109 | $transformer->shouldReceive('generateFilename')->with('foo.php')->andReturn('generated-foo.php'); |
||
110 | $fileDescriptor->shouldReceive('getHash')->andReturn('hash'); |
||
111 | $fileDescriptor->shouldReceive('getAllErrors')->andReturn([]); |
||
112 | |||
113 | $this->projectDescriptor->shouldReceive('getFiles')->andReturn([$fileDescriptor]); |
||
0 ignored issues
–
show
The method
shouldReceive does only exist in Mockery\MockInterface , but not in phpDocumentor\Descriptor\ProjectDescriptor .
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...
|
|||
114 | $this->projectDescriptor->shouldReceive('getName')->andReturn('project'); |
||
115 | $this->projectDescriptor->shouldReceive('getPartials')->andReturn([]); |
||
116 | |||
117 | $this->implementProtectedFinalize($this->projectDescriptor); |
||
118 | $this->implementProtectedBuildDocBlock($fileDescriptor); |
||
119 | |||
120 | $fileDescriptor->shouldReceive('getNamespaceAliases')->andReturn(['foo', 'bar']); |
||
121 | $fileDescriptor->shouldReceive('getConstants')->andReturn([]); |
||
122 | $fileDescriptor->shouldReceive('getFunctions')->andReturn([]); |
||
123 | $fileDescriptor->shouldReceive('getInterfaces')->andReturn([]); |
||
124 | $fileDescriptor->shouldReceive('getClasses')->andReturn([]); |
||
125 | $fileDescriptor->shouldReceive('getTraits')->andReturn([]); |
||
126 | $fileDescriptor->shouldReceive('getMarkers')->andReturn([]); |
||
127 | $fileDescriptor->shouldReceive('getErrors')->andReturn([]); |
||
128 | $fileDescriptor->shouldReceive('getPartials')->andReturn([]); |
||
129 | $fileDescriptor->shouldReceive('getSource')->andReturn(null); |
||
130 | |||
131 | // Call the actual method |
||
132 | $this->xml->transform($this->projectDescriptor, $transformation); |
||
133 | |||
134 | // Check file exists |
||
135 | $this->assertTrue($this->fs->hasChild('artifact.xml')); |
||
136 | |||
137 | // Inspect XML |
||
138 | $xml = <<<XML |
||
139 | <?xml version="1.0" encoding="utf-8"?> |
||
140 | <project version="2.0.0b8" title="project"> |
||
141 | <partials/> |
||
142 | <file path="foo.php" generated-path="generated-foo.php" hash="hash" package="myPackage"> |
||
143 | <docblock line="666"> |
||
144 | <description>my summary</description> |
||
145 | <long-description>my description</long-description> |
||
146 | </docblock> |
||
147 | <namespace-alias name="0">foo</namespace-alias> |
||
148 | <namespace-alias name="1">bar</namespace-alias> |
||
149 | </file> |
||
150 | <package name="global" full_name="global"/> |
||
151 | <package name="myPackage" full_name="myPackage"/> |
||
152 | <deprecated count="0"/> |
||
153 | </project> |
||
154 | XML; |
||
155 | $expectedXml = new \DOMDocument(); |
||
156 | $expectedXml->loadXML($xml); |
||
157 | |||
158 | $actualXml = new \DOMDocument(); |
||
159 | $actualXml->load(vfsStream::url('XmlTest/artifact.xml')); |
||
160 | |||
161 | $this->assertEqualXMLStructure($expectedXml->firstChild, $actualXml->firstChild, true); |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * This implements testing of the protected finalize method. |
||
166 | */ |
||
167 | protected function implementProtectedFinalize(ProjectDescriptor $projectDescriptor) |
||
168 | { |
||
169 | $this->projectDescriptor->shouldReceive('isVisibilityAllowed') |
||
0 ignored issues
–
show
The method
shouldReceive does only exist in Mockery\MockInterface , but not in phpDocumentor\Descriptor\ProjectDescriptor .
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...
|
|||
170 | ->with(ProjectDescriptor\Settings::VISIBILITY_INTERNAL) |
||
171 | ->andReturn(true); |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * This implements testing of the protected buildDocBlock method |
||
176 | */ |
||
177 | protected function implementProtectedBuildDocBlock(m\MockInterface $descriptor) |
||
178 | { |
||
179 | $descriptor->shouldReceive('getLine')->andReturn(666); |
||
0 ignored issues
–
show
The method
andReturn does only exist in Mockery\ExpectationInterface , but not in Mockery\HigherOrderMessage .
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...
|
|||
180 | $descriptor->shouldReceive('getPackage')->andReturn('myPackage'); |
||
181 | $descriptor->shouldReceive('getSummary')->andReturn('my summary'); |
||
182 | $descriptor->shouldReceive('getDescription')->andReturn('my description'); |
||
183 | $descriptor->shouldReceive('getTags')->andReturn([]); |
||
184 | } |
||
185 | } |
||
186 |
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: