1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2013-2020 |
4
|
|
|
* Piotr Olaszewski <[email protected]> |
5
|
|
|
* |
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
8
|
|
|
* in the Software without restriction, including without limitation the rights |
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
11
|
|
|
* furnished to do so, subject to the following conditions: |
12
|
|
|
* |
13
|
|
|
* The above copyright notice and this permission notice shall be included in |
14
|
|
|
* all copies or substantial portions of the Software. |
15
|
|
|
* |
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22
|
|
|
* SOFTWARE. |
23
|
|
|
*/ |
24
|
|
|
namespace Tests\WSDL\Parser; |
25
|
|
|
|
26
|
|
|
use PHPUnit\Framework\TestCase; |
27
|
|
|
use WSDL\Parser\Node; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* NodeTest |
31
|
|
|
* |
32
|
|
|
* @author Piotr Olaszewski <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
class NodeTest extends TestCase |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @test |
38
|
|
|
*/ |
39
|
|
|
public function shouldGetTypeForSimpleType() |
40
|
|
|
{ |
41
|
|
|
//given |
42
|
|
|
$node = new Node('int', '$age', false); |
43
|
|
|
|
44
|
|
|
//when |
45
|
|
|
$type = $node->getType(); |
46
|
|
|
|
47
|
|
|
//then |
48
|
|
|
$this->assertEquals('int', $type); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @test |
53
|
|
|
*/ |
54
|
|
View Code Duplication |
public function shouldGetTypeForObjectType() |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
//given |
57
|
|
|
$elements = [ |
58
|
|
|
new Node('string', '$name', false) |
59
|
|
|
]; |
60
|
|
|
$node = new Node('object', '$user', false, $elements); |
61
|
|
|
|
62
|
|
|
//when |
63
|
|
|
$type = $node->getType(); |
64
|
|
|
|
65
|
|
|
//then |
66
|
|
|
$this->assertEquals('object', $type); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @test |
71
|
|
|
*/ |
72
|
|
View Code Duplication |
public function shouldReturnName() |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
//given |
75
|
|
|
$node = new Node('int', '$age', false); |
76
|
|
|
|
77
|
|
|
//when |
78
|
|
|
$name = $node->getName(); |
79
|
|
|
|
80
|
|
|
//then |
81
|
|
|
$this->assertEquals('$age', $name); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @test |
86
|
|
|
*/ |
87
|
|
View Code Duplication |
public function shouldGetSanitizedName() |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
//given |
90
|
|
|
$node = new Node('int', '$age', false); |
91
|
|
|
|
92
|
|
|
//when |
93
|
|
|
$name = $node->getSanitizedName(); |
94
|
|
|
|
95
|
|
|
//then |
96
|
|
|
$this->assertEquals('age', $name); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @test |
101
|
|
|
*/ |
102
|
|
|
public function shouldGetNameForArray() |
103
|
|
|
{ |
104
|
|
|
//given |
105
|
|
|
$node = new Node('int', '$age', true); |
106
|
|
|
|
107
|
|
|
//when |
108
|
|
|
$name = $node->getNameForArray(); |
109
|
|
|
|
110
|
|
|
//then |
111
|
|
|
$this->assertEquals('ArrayOfAge', $name); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @test |
116
|
|
|
*/ |
117
|
|
View Code Duplication |
public function shouldGetNameForObject() |
|
|
|
|
118
|
|
|
{ |
119
|
|
|
//given |
120
|
|
|
$elements = [ |
121
|
|
|
new Node('string', '$name', false) |
122
|
|
|
]; |
123
|
|
|
$node = new Node('object', '$user', false, $elements); |
124
|
|
|
|
125
|
|
|
//when |
126
|
|
|
$name = $node->getNameForObject(); |
127
|
|
|
|
128
|
|
|
//then |
129
|
|
|
$this->assertEquals('User', $name); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @test |
134
|
|
|
*/ |
135
|
|
View Code Duplication |
public function shouldSingularizeeNameForObject() |
|
|
|
|
136
|
|
|
{ |
137
|
|
|
//given |
138
|
|
|
$elements = [ |
139
|
|
|
new Node('string', '$name', false) |
140
|
|
|
]; |
141
|
|
|
$node = new Node('object', '$users', true, $elements); |
142
|
|
|
|
143
|
|
|
//when |
144
|
|
|
$name = $node->getNameForObject(); |
145
|
|
|
|
146
|
|
|
//then |
147
|
|
|
$this->assertEquals('User', $name); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @test |
152
|
|
|
*/ |
153
|
|
|
public function shouldReturnFalseWhenTypeIsNotArray() |
154
|
|
|
{ |
155
|
|
|
//given |
156
|
|
|
$node = new Node('string', '$name', false); |
157
|
|
|
|
158
|
|
|
//when |
159
|
|
|
$isArray = $node->isArray(); |
160
|
|
|
|
161
|
|
|
//then |
162
|
|
|
$this->assertFalse($isArray); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @test |
167
|
|
|
*/ |
168
|
|
|
public function shouldReturnTrueWhenTypeIsArray() |
169
|
|
|
{ |
170
|
|
|
//given |
171
|
|
|
$node = new Node('string', '$name', true); |
172
|
|
|
|
173
|
|
|
//when |
174
|
|
|
$isArray = $node->isArray(); |
175
|
|
|
|
176
|
|
|
//then |
177
|
|
|
$this->assertTrue($isArray); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @test |
182
|
|
|
*/ |
183
|
|
|
public function shouldReturnFalseWhenTypeIsNotObject() |
184
|
|
|
{ |
185
|
|
|
//given |
186
|
|
|
$node = new Node('string', '$name', true); |
187
|
|
|
|
188
|
|
|
//when |
189
|
|
|
$isArray = $node->isObject(); |
190
|
|
|
|
191
|
|
|
//then |
192
|
|
|
$this->assertFalse($isArray); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @test |
197
|
|
|
*/ |
198
|
|
View Code Duplication |
public function shouldReturnTrueWhenTypeIsObject() |
|
|
|
|
199
|
|
|
{ |
200
|
|
|
//given |
201
|
|
|
$elements = [ |
202
|
|
|
new Node('string', '$name', false) |
203
|
|
|
]; |
204
|
|
|
$node = new Node('object', '$users', true, $elements); |
205
|
|
|
|
206
|
|
|
//when |
207
|
|
|
$isArray = $node->isObject(); |
208
|
|
|
|
209
|
|
|
//then |
210
|
|
|
$this->assertTrue($isArray); |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.