-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAbstractMetadataProviderTest.php
More file actions
302 lines (255 loc) · 10.1 KB
/
Copy pathAbstractMetadataProviderTest.php
File metadata and controls
302 lines (255 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?php
declare(strict_types=1);
namespace Soap\EngineIntegrationTests;
use Soap\Engine\Metadata\Collection\MethodCollection;
use Soap\Engine\Metadata\Collection\ParameterCollection;
use Soap\Engine\Metadata\Collection\PropertyCollection;
use Soap\Engine\Metadata\Collection\TypeCollection;
use Soap\Engine\Metadata\MetadataProvider;
use Soap\Engine\Metadata\Model\Parameter;
use Soap\Engine\Metadata\Model\Property;
use Soap\Engine\Metadata\Model\XsdType;
abstract class AbstractMetadataProviderTest extends AbstractIntegrationTest
{
abstract protected function getMetadataProvider(): MetadataProvider;
public function test_it_can_load_wsdl_methods()
{
$this->configureForWsdl($this->locateFixture('/wsdl/functional/string.wsdl'));
$metadata = $this->getMetadataProvider()->getMetadata();
$methods = $metadata->getMethods();
static::assertCount(1, $methods);
self::assertMethodExists(
$methods,
'validate',
[
new Parameter('input', XsdType::guess('string'))
],
XsdType::guess('string')
);
}
public function test_it_can_load_wsdl_method_with_multiple_response_arguments()
{
$this->configureForWsdl($this->locateFixture('/wsdl/functional/multiArgumentResponse.wsdl'));
$metadata = $this->getMetadataProvider()->getMetadata();
$methods = $metadata->getMethods();
static::assertCount(1, $methods);
self::assertMethodExists(
$methods,
'validate',
[
new Parameter('input', XsdType::guess('string'))
],
XsdType::guess('array')
);
}
public function test_it_can_load_union_types_in_methods()
{
$this->configureForWsdl($this->locateFixture('/wsdl/functional/union.wsdl'));
$metadata = $this->getMetadataProvider()->getMetadata();
$methods = $metadata->getMethods();
$jeansType = XsdType::guess('jeansSize')
->withBaseType('anyType')
->withMemberTypes(['sizebyno', 'sizebystring']);
static::assertCount(1, $methods);
self::assertMethodExists(
$methods,
'validate',
[
new Parameter('input', $jeansType)
],
$jeansType
);
}
public function test_it_can_load_list_types_in_methods()
{
$this->configureForWsdl($this->locateFixture('/wsdl/functional/list.wsdl'));
$metadata = $this->getMetadataProvider()->getMetadata();
$methods = $metadata->getMethods();
$listType = XsdType::guess('valuelist')
->withBaseType('array')
->withMemberTypes(['integer']);
static::assertCount(1, $methods);
self::assertMethodExists(
$methods,
'validate',
[
new Parameter('input', $listType)
],
$listType
);
}
public function test_it_can_load_simple_content_types()
{
$this->configureForWsdl($this->locateFixture('/wsdl/functional/simpleContent.wsdl'));
$metadata = $this->getMetadataProvider()->getMetadata();
$types = $metadata->getTypes();
static::assertCount(1, $types);
self::assertTypeExists(
$types,
XsdType::guess('SimpleContent'),
[
new Property(
'_',
XsdType::guess('integer')
->withBaseType('float')
->withMemberTypes(['decimal'])
),
new Property(
'country',
XsdType::guess('string')
->withBaseType('mixed')
),
]
);
}
public function test_it_can_load_complex_types()
{
$this->configureForWsdl($this->locateFixture('/wsdl/functional/complex-type-request-response.wsdl'));
$metadata = $this->getMetadataProvider()->getMetadata();
$types = $metadata->getTypes();
static::assertCount(2, $types);
self::assertTypeExists(
$types,
XsdType::guess('ValidateRequest'),
[
new Property(
'input',
XsdType::guess('string')
->withBaseType('mixed')
->withMemberTypes(['anySimpleType'])
)
]
);
self::assertTypeExists(
$types,
XsdType::guess('ValidateResponse'),
[
new Property(
'output',
XsdType::guess('string')
->withBaseType('mixed')
->withMemberTypes(['anySimpleType'])
)
]
);
}
public function test_it_can_load_union_types()
{
$this->configureForWsdl($this->locateFixture('/wsdl/functional/union.wsdl'));
$metadata = $this->getMetadataProvider()->getMetadata();
$types = $metadata->getTypes();
$jeansType = XsdType::guess('jeansSize')
->withBaseType('anyType')
->withMemberTypes(['sizebyno', 'sizebystring']);
self::assertTypeExists(
$types,
XsdType::guess('jeansSizeContainer'),
[
new Property('jeansSize', $jeansType)
]
);
}
public function test_it_can_load_list_types()
{
$this->configureForWsdl($this->locateFixture('/wsdl/functional/list.wsdl'));
$metadata = $this->getMetadataProvider()->getMetadata();
$types = $metadata->getTypes();
$listType = XsdType::guess('valuelist')
->withBaseType('array')
->withMemberTypes(['integer']);
self::assertTypeExists(
$types,
XsdType::guess('valuelistContainer'),
[
new Property('valuelist', $listType)
]
);
}
public function test_it_can_handle_duplicate_type_declarations()
{
$this->configureForWsdl($this->locateFixture('/wsdl/functional/duplicate-typenames.wsdl'));
$metadata = $this->getMetadataProvider()->getMetadata();
$types = $metadata->getTypes();
static::assertCount(2, $types);
$type1 = $types->getIterator()[1];
static::assertSame('Store', $type1->getName());
static::assertXsdTypeMatches(XsdType::guess('Store'), $type1->getXsdType());
static::assertPropertiesMatch(
new PropertyCollection(new Property(
'Attribute2',
XsdType::guess('string')
->withBaseType('mixed')
->withMemberTypes(['anySimpleType'])
)),
$type1->getProperties()
);
$type2 = $types->getIterator()[1];
static::assertSame('Store', $type2->getName());
static::assertXsdTypeMatches(XsdType::guess('Store'), $type2->getXsdType());
static::assertPropertiesMatch(
new PropertyCollection(new Property(
'Attribute2',
XsdType::guess('string')
->withBaseType('mixed')
->withMemberTypes(['anySimpleType'])
)),
$type2->getProperties()
);
}
private static function assertMethodExists(MethodCollection $methods, string $name, array $parameters, XsdType $returnType)
{
$method = $methods->fetchByName($name);
static::assertSame($name, $method->getName());
static::assertParametersMatch(new ParameterCollection(...$parameters), $method->getParameters());
static::assertXsdTypeMatches($returnType, $method->getReturnType());
}
private static function assertTypeExists(TypeCollection $types, XsdType $xsdType, array $properties)
{
$type = $types->fetchFirstByName($xsdType->getName());
static::assertSame($xsdType->getName(), $type->getName());
static::assertEquals($xsdType->getName(), $type->getXsdType());
static::assertPropertiesMatch(new PropertyCollection(...$properties), $type->getProperties());
}
private static function assertParametersMatch(ParameterCollection $expected, ParameterCollection $actual)
{
$expectedList = [...$expected];
static::assertCount(count($expectedList), $actual);
foreach ($actual as $index => $current) {
self::assertParameterMatch($expectedList[$index], $current);
}
}
private static function assertParameterMatch(Parameter $expected, Parameter $actual)
{
static::assertSame($expected->getName(), $actual->getName());
self::assertXsdTypeMatches($expected->getType(), $actual->getType());
}
private static function assertPropertyMatch(Property $expected, Property $actual)
{
static::assertSame($expected->getName(), $actual->getName());
self::assertXsdTypeMatches($expected->getType(), $actual->getType());
}
private static function assertPropertiesMatch(PropertyCollection $expected, PropertyCollection $actual)
{
$expectedList = [...$expected];
static::assertCount(count($expectedList), $actual);
foreach ($actual as $index => $current) {
self::assertPropertyMatch($expectedList[$index], $current);
}
}
private static function assertXsdTypeMatches(XsdType $expected, XsdType $actual)
{
static::assertSame($expected->getName(), $actual->getName());
// Base-types might not be inferable from ext-soap.
// More detailed implementations might provide more.
if ($actual->getBaseType()) {
static::assertSame($expected->getBaseType(), $actual->getBaseType());
}
// Member types will be checked optionally:
// ext-soap does not have an extended overview of all inherited types.
if ($actual->getMemberTypes()) {
static::assertSame($expected->getMemberTypes(), $actual->getMemberTypes());
}
// Not validating namespace info + metadata in here.
// Since implementations like ext-soap cannot provide this information.
}
}