Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve simple type infers #9

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions src/AbstractMetadataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function test_it_can_load_union_types_in_methods()
$methods = $metadata->getMethods();

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

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

//var_dump($types->fetchFirstByName('SimpleContent'));exit;

static::assertCount(1, $types);
self::assertTypeExists(
$types,
XsdType::guess('SimpleContent'),
[
new Property('_', XsdType::guess('integer')->withMemberTypes(['decimal'])),
new Property('country', XsdType::guess('string')),
new Property(
'_',
XsdType::guess('integer')
->withBaseType('float')
->withMemberTypes(['decimal'])
),
new Property(
'country',
XsdType::guess('string')
->withBaseType('mixed')
),
]
);
}
Expand All @@ -128,14 +136,24 @@ public function test_it_can_load_complex_types()
$types,
XsdType::guess('ValidateRequest'),
[
new Property('input', XsdType::guess('string'))
new Property(
'input',
XsdType::guess('string')
->withBaseType('mixed')
->withMemberTypes(['anySimpleType'])
)
]
);
self::assertTypeExists(
$types,
XsdType::guess('ValidateResponse'),
[
new Property('output', XsdType::guess('string'))
new Property(
'output',
XsdType::guess('string')
->withBaseType('mixed')
->withMemberTypes(['anySimpleType'])
)
]
);
}
Expand All @@ -148,6 +166,7 @@ public function test_it_can_load_union_types()
$types = $metadata->getTypes();

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

self::assertTypeExists(
Expand Down Expand Up @@ -192,15 +211,25 @@ public function test_it_can_handle_duplicate_type_declarations()
static::assertSame('Store', $type1->getName());
static::assertXsdTypeMatches(XsdType::guess('Store'), $type1->getXsdType());
static::assertPropertiesMatch(
new PropertyCollection(new Property('Attribute2', XsdType::guess('string'))),
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'))),
new PropertyCollection(new Property(
'Attribute2',
XsdType::guess('string')
->withBaseType('mixed')
->withMemberTypes(['anySimpleType'])
)),
$type2->getProperties()
);
}
Expand Down Expand Up @@ -254,7 +283,12 @@ private static function assertPropertiesMatch(PropertyCollection $expected, Prop
private static function assertXsdTypeMatches(XsdType $expected, XsdType $actual)
{
static::assertSame($expected->getName(), $actual->getName());
static::assertSame($expected->getBaseType(), $actual->getBaseType());

// 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.
Expand Down