Skip to content

Commit 8cc90e8

Browse files
authored
Merge pull request #9 from php-soap/improved-simple-types-infering
Improve simple type infers
2 parents 6a0836c + 2c0fab2 commit 8cc90e8

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

src/AbstractMetadataProviderTest.php

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function test_it_can_load_union_types_in_methods()
6161
$methods = $metadata->getMethods();
6262

6363
$jeansType = XsdType::guess('jeansSize')
64+
->withBaseType('anyType')
6465
->withMemberTypes(['sizebyno', 'sizebystring']);
6566

6667
static::assertCount(1, $methods);
@@ -103,15 +104,22 @@ public function test_it_can_load_simple_content_types()
103104
$metadata = $this->getMetadataProvider()->getMetadata();
104105
$types = $metadata->getTypes();
105106

106-
//var_dump($types->fetchFirstByName('SimpleContent'));exit;
107-
108107
static::assertCount(1, $types);
109108
self::assertTypeExists(
110109
$types,
111110
XsdType::guess('SimpleContent'),
112111
[
113-
new Property('_', XsdType::guess('integer')->withMemberTypes(['decimal'])),
114-
new Property('country', XsdType::guess('string')),
112+
new Property(
113+
'_',
114+
XsdType::guess('integer')
115+
->withBaseType('float')
116+
->withMemberTypes(['decimal'])
117+
),
118+
new Property(
119+
'country',
120+
XsdType::guess('string')
121+
->withBaseType('mixed')
122+
),
115123
]
116124
);
117125
}
@@ -128,14 +136,24 @@ public function test_it_can_load_complex_types()
128136
$types,
129137
XsdType::guess('ValidateRequest'),
130138
[
131-
new Property('input', XsdType::guess('string'))
139+
new Property(
140+
'input',
141+
XsdType::guess('string')
142+
->withBaseType('mixed')
143+
->withMemberTypes(['anySimpleType'])
144+
)
132145
]
133146
);
134147
self::assertTypeExists(
135148
$types,
136149
XsdType::guess('ValidateResponse'),
137150
[
138-
new Property('output', XsdType::guess('string'))
151+
new Property(
152+
'output',
153+
XsdType::guess('string')
154+
->withBaseType('mixed')
155+
->withMemberTypes(['anySimpleType'])
156+
)
139157
]
140158
);
141159
}
@@ -148,6 +166,7 @@ public function test_it_can_load_union_types()
148166
$types = $metadata->getTypes();
149167

150168
$jeansType = XsdType::guess('jeansSize')
169+
->withBaseType('anyType')
151170
->withMemberTypes(['sizebyno', 'sizebystring']);
152171

153172
self::assertTypeExists(
@@ -192,15 +211,25 @@ public function test_it_can_handle_duplicate_type_declarations()
192211
static::assertSame('Store', $type1->getName());
193212
static::assertXsdTypeMatches(XsdType::guess('Store'), $type1->getXsdType());
194213
static::assertPropertiesMatch(
195-
new PropertyCollection(new Property('Attribute2', XsdType::guess('string'))),
214+
new PropertyCollection(new Property(
215+
'Attribute2',
216+
XsdType::guess('string')
217+
->withBaseType('mixed')
218+
->withMemberTypes(['anySimpleType'])
219+
)),
196220
$type1->getProperties()
197221
);
198222

199223
$type2 = $types->getIterator()[1];
200224
static::assertSame('Store', $type2->getName());
201225
static::assertXsdTypeMatches(XsdType::guess('Store'), $type2->getXsdType());
202226
static::assertPropertiesMatch(
203-
new PropertyCollection(new Property('Attribute2', XsdType::guess('string'))),
227+
new PropertyCollection(new Property(
228+
'Attribute2',
229+
XsdType::guess('string')
230+
->withBaseType('mixed')
231+
->withMemberTypes(['anySimpleType'])
232+
)),
204233
$type2->getProperties()
205234
);
206235
}
@@ -254,7 +283,12 @@ private static function assertPropertiesMatch(PropertyCollection $expected, Prop
254283
private static function assertXsdTypeMatches(XsdType $expected, XsdType $actual)
255284
{
256285
static::assertSame($expected->getName(), $actual->getName());
257-
static::assertSame($expected->getBaseType(), $actual->getBaseType());
286+
287+
// Base-types might not be inferable from ext-soap.
288+
// More detailed implementations might provide more.
289+
if ($actual->getBaseType()) {
290+
static::assertSame($expected->getBaseType(), $actual->getBaseType());
291+
}
258292

259293
// Member types will be checked optionally:
260294
// ext-soap does not have an extended overview of all inherited types.

0 commit comments

Comments
 (0)