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\Writer\Xml; |
13
|
|
|
|
14
|
|
|
use Mockery as m; |
15
|
|
|
use phpDocumentor\Descriptor\ArgumentDescriptor; |
16
|
|
|
use phpDocumentor\Descriptor\DescriptorAbstract; |
17
|
|
|
use phpDocumentor\Descriptor\MethodDescriptor; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Test class for \phpDocumentor\Transformer\Writer\Xml\MethodConverter. |
21
|
|
|
* |
22
|
|
|
* @covers phpDocumentor\Transformer\Writer\Xml\MethodConverter |
23
|
|
|
*/ |
24
|
|
|
class MethodConverterTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Tests whether the XML Element representing a method is properly created. |
28
|
|
|
* |
29
|
|
|
* @covers phpDocumentor\Transformer\Writer\Xml\MethodConverter::convert |
30
|
|
|
*/ |
31
|
|
|
public function testMethodXmlElementIsCreated() |
32
|
|
|
{ |
33
|
|
|
// Arrange |
34
|
|
|
$parent = $this->prepareParentXMLElement(); |
35
|
|
|
$parent->setAttribute('namespace', 'phpDocumentor'); |
36
|
|
|
$argumentDescriptor = m::mock('phpDocumentor\Descriptor\ArgumentDescriptor'); |
37
|
|
|
$method = $this->createMethodDescriptorMock(); |
38
|
|
|
$method->shouldReceive('getArguments')->andReturn([$argumentDescriptor]); |
39
|
|
|
$methodConverter = $this->createFixture($method, $argumentDescriptor); |
40
|
|
|
|
41
|
|
|
// Act |
42
|
|
|
$convertedElement = $methodConverter->convert($parent, $method); |
|
|
|
|
43
|
|
|
|
44
|
|
|
// Assert |
45
|
|
|
$this->assertSame('false', $convertedElement->getAttribute('final')); |
46
|
|
|
$this->assertSame('true', $convertedElement->getAttribute('abstract')); |
47
|
|
|
$this->assertSame('false', $convertedElement->getAttribute('static')); |
48
|
|
|
$this->assertSame('protected', $convertedElement->getAttribute('visibility')); |
49
|
|
|
$this->assertSame('100', $convertedElement->getAttribute('line')); |
50
|
|
|
$this->assertSame('phpDocumentor', $convertedElement->getAttribute('namespace')); |
51
|
|
|
$this->assertSame('Method', $convertedElement->getElementsByTagName('name')->item(0)->nodeValue); |
52
|
|
|
$this->assertSame( |
53
|
|
|
'phpDocumentor\Class::Method()', |
54
|
|
|
$convertedElement->getElementsByTagName('full_name')->item(0)->nodeValue |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Tests whether the XML Element representing a method is properly created. |
60
|
|
|
* |
61
|
|
|
* @covers phpDocumentor\Transformer\Writer\Xml\MethodConverter::convert |
62
|
|
|
*/ |
63
|
|
|
public function testNamespaceNameIsTakenFromNamespaceDescriptorIfPresent() |
64
|
|
|
{ |
65
|
|
|
// Arrange |
66
|
|
|
$parent = $this->prepareParentXMLElement(); |
67
|
|
|
$namespaceDescriptor = m::mock('phpDocumentor\Descriptor\NamespaceDescriptor'); |
68
|
|
|
$namespaceDescriptor->shouldReceive('getFullyQualifiedStructuralElementName')->andReturn('MySpace'); |
69
|
|
|
$method = $this->createMethodDescriptorMock(); |
70
|
|
|
$method->shouldReceive('getArguments')->andReturn([]); |
71
|
|
|
$method->shouldReceive('getNamespace')->andReturn($namespaceDescriptor); |
72
|
|
|
$methodConverter = $this->createFixture($method); |
73
|
|
|
|
74
|
|
|
// Act |
75
|
|
|
$convertedElement = $methodConverter->convert($parent, $method); |
|
|
|
|
76
|
|
|
|
77
|
|
|
// Assert |
78
|
|
|
$this->assertSame('MySpace', $convertedElement->getAttribute('namespace')); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Creates an XML Element that can serve as parent. |
83
|
|
|
* |
84
|
|
|
* @return \DOMElement |
85
|
|
|
*/ |
86
|
|
|
protected function prepareParentXMLElement() |
87
|
|
|
{ |
88
|
|
|
$document = new \DOMDocument(); |
89
|
|
|
$parent = new \DOMElement('class'); |
90
|
|
|
$document->appendChild($parent); |
91
|
|
|
|
92
|
|
|
return $parent; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Creates a mock for the MethodDescriptor class. |
97
|
|
|
* |
98
|
|
|
* @return m\MockInterface|DescriptorAbstract |
99
|
|
|
*/ |
100
|
|
|
protected function createMethodDescriptorMock() |
101
|
|
|
{ |
102
|
|
|
$method = m::mock('phpDocumentor\\Descriptor\\MethodDescriptor'); |
103
|
|
|
$method->shouldReceive('getLine')->andReturn(100); |
104
|
|
|
$method->shouldReceive('isFinal')->andReturn(false); |
105
|
|
|
$method->shouldReceive('isAbstract')->andReturn(true); |
106
|
|
|
$method->shouldReceive('isStatic')->andReturn(false); |
107
|
|
|
$method->shouldReceive('getVisibility')->andReturn('protected'); |
108
|
|
|
$method->shouldReceive('getName')->andReturn('Method'); |
109
|
|
|
$method->shouldReceive('getFullyQualifiedStructuralElementName')->andReturn('phpDocumentor\Class::Method()'); |
110
|
|
|
$method->shouldIgnoreMissing(); |
111
|
|
|
|
112
|
|
|
return $method; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Creates the MethodConverter fixture with a DocBlock and ArgumentConverter mock. |
117
|
|
|
* |
118
|
|
|
* @return MethodConverter |
119
|
|
|
*/ |
120
|
|
|
protected function createFixture(MethodDescriptor $method, ArgumentDescriptor $argumentDescriptor = null) |
121
|
|
|
{ |
122
|
|
|
$docBlockConverter = m::mock('phpDocumentor\Transformer\Writer\Xml\DocBlockConverter'); |
123
|
|
|
$docBlockConverter->shouldReceive('convert')->with(m::type('DOMElement'), $method); |
124
|
|
|
$argumentConverter = m::mock('phpDocumentor\Transformer\Writer\Xml\ArgumentConverter'); |
125
|
|
|
if ($argumentDescriptor) { |
126
|
|
|
$argumentConverter->shouldReceive('convert')->with(m::type('DOMElement'), $argumentDescriptor); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
return new MethodConverter($argumentConverter, $docBlockConverter); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
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: