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 phpDocumentor\Descriptor\ArgumentDescriptor; |
15
|
|
|
use phpDocumentor\Reflection\Types\Compound; |
16
|
|
|
use phpDocumentor\Reflection\Types\Integer; |
17
|
|
|
use phpDocumentor\Reflection\Types\String_; |
18
|
|
|
use PHPUnit\Framework\TestCase; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Test class for \phpDocumentor\Transformer\Writer\Xml\ArgumentConverter. |
22
|
|
|
* |
23
|
|
|
* @coversDefaultClass \phpDocumentor\Transformer\Writer\Xml\ArgumentConverter |
24
|
|
|
* @covers ::<private> |
25
|
|
|
*/ |
26
|
|
|
class ArgumentConverterTest extends TestCase |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Tests whether the XML Element representing an argument is properly created. |
30
|
|
|
* |
31
|
|
|
* @covers ::convert |
32
|
|
|
*/ |
33
|
|
|
public function testArgumentXmlElementIsCreated() |
34
|
|
|
{ |
35
|
|
|
// Arrange |
36
|
|
|
$tag = new ArgumentDescriptor(); |
37
|
|
|
$tag->setName('name'); |
38
|
|
|
$tag->setLine(100); |
39
|
|
|
$tag->setByReference(false); |
40
|
|
|
$tag->setDefault(null); |
41
|
|
|
$tag->setType(null); |
42
|
|
|
$parent = $this->prepareParentXMLElement(); |
43
|
|
|
$argumentConverter = new ArgumentConverter(); |
44
|
|
|
|
45
|
|
|
// Act |
46
|
|
|
$convertedElement = $argumentConverter->convert($parent, $tag); |
47
|
|
|
|
48
|
|
|
// Assert |
49
|
|
|
$this->assertSame('100', $convertedElement->getAttribute('line')); |
50
|
|
|
$this->assertSame('false', $convertedElement->getAttribute('by_reference')); |
51
|
|
|
$this->assertSame('name', $convertedElement->getElementsByTagName('name')->item(0)->nodeValue); |
52
|
|
|
$this->assertSame('', $convertedElement->getElementsByTagName('default')->item(0)->nodeValue); |
53
|
|
|
$this->assertSame('', $convertedElement->getElementsByTagName('type')->item(0)->nodeValue); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Tests whether it is documented when an argument is by reference. |
58
|
|
|
* |
59
|
|
|
* @covers ::convert |
60
|
|
|
*/ |
61
|
|
|
public function testIfByReferenceIsDocumented() |
62
|
|
|
{ |
63
|
|
|
// Arrange |
64
|
|
|
$argumentConverter = new ArgumentConverter(); |
65
|
|
|
$parent = $this->prepareParentXMLElement(); |
66
|
|
|
$tag = new ArgumentDescriptor(); |
67
|
|
|
$tag->setName('name'); |
68
|
|
|
$tag->setLine(100); |
69
|
|
|
$tag->setByReference(true); |
70
|
|
|
$tag->setDefault(null); |
71
|
|
|
$tag->setType(null); |
72
|
|
|
|
73
|
|
|
// Act |
74
|
|
|
$convertedElement = $argumentConverter->convert($parent, $tag); |
75
|
|
|
|
76
|
|
|
// Assert |
77
|
|
|
$this->assertSame('true', $convertedElement->getAttribute('by_reference')); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Tests whether the type information for an argument is documented. |
82
|
|
|
* |
83
|
|
|
* @covers ::convert |
84
|
|
|
*/ |
85
|
|
|
public function testIfTypeInformationIsDocumented() |
86
|
|
|
{ |
87
|
|
|
// Arrange |
88
|
|
|
$argumentConverter = new ArgumentConverter(); |
89
|
|
|
$parent = $this->prepareParentXMLElement(); |
90
|
|
|
$tag = new ArgumentDescriptor(); |
91
|
|
|
$tag->setName('name'); |
92
|
|
|
$tag->setLine(100); |
93
|
|
|
$tag->setByReference(true); |
94
|
|
|
$tag->setDefault(null); |
95
|
|
|
$tag->setType(new Compound([new String_(), new Integer()])); |
96
|
|
|
|
97
|
|
|
// Act |
98
|
|
|
$convertedElement = $argumentConverter->convert($parent, $tag); |
99
|
|
|
|
100
|
|
|
// Assert |
101
|
|
|
$this->assertSame('string|int', $convertedElement->getElementsByTagName('type')->item(0)->nodeValue); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Tests whether the default for an argument is documented. |
106
|
|
|
* |
107
|
|
|
* @covers ::convert |
108
|
|
|
*/ |
109
|
|
|
public function testIfDefaultValueIsDocumented() |
110
|
|
|
{ |
111
|
|
|
// Arrange |
112
|
|
|
$default = 'This is a default'; |
113
|
|
|
$argumentConverter = new ArgumentConverter(); |
114
|
|
|
$parent = $this->prepareParentXMLElement(); |
115
|
|
|
$tag = new ArgumentDescriptor(); |
116
|
|
|
$tag->setName('name'); |
117
|
|
|
$tag->setLine(100); |
118
|
|
|
$tag->setByReference(true); |
119
|
|
|
$tag->setDefault($default); |
120
|
|
|
$tag->setType(new Compound([new String_(), new Integer()])); |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
// Act |
124
|
|
|
$convertedElement = $argumentConverter->convert($parent, $tag); |
125
|
|
|
|
126
|
|
|
// Assert |
127
|
|
|
$this->assertSame($default, $convertedElement->getElementsByTagName('default')->item(0)->nodeValue); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Creates an XML Element that can serve as parent. |
132
|
|
|
* |
133
|
|
|
* @return \DOMElement |
134
|
|
|
*/ |
135
|
|
|
protected function prepareParentXMLElement() |
136
|
|
|
{ |
137
|
|
|
$document = new \DOMDocument(); |
138
|
|
|
$parent = new \DOMElement('function'); |
139
|
|
|
$document->appendChild($parent); |
140
|
|
|
|
141
|
|
|
return $parent; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|