Skip to content

Commit

Permalink
Merge pull request #8 from php-soap/better-metadata-tests
Browse files Browse the repository at this point in the history
Make metadata tests more trustworthy over multiple implementations
  • Loading branch information
veewee authored Mar 31, 2023
2 parents 242a2f1 + b93001c commit 590febc
Showing 1 changed file with 97 additions and 47 deletions.
144 changes: 97 additions & 47 deletions src/AbstractMetadataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
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;
Expand All @@ -15,7 +17,6 @@ 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'));
Expand All @@ -24,17 +25,16 @@ public function test_it_can_load_wsdl_methods()
$methods = $metadata->getMethods();

static::assertCount(1, $methods);
$this->assertMethodExists(
self::assertMethodExists(
$methods,
'validate',
[
new Parameter('input', XsdType::create('string'))
new Parameter('input', XsdType::guess('string'))
],
XsdType::create('string')
XsdType::guess('string')
);
}


public function test_it_can_load_wsdl_method_with_multiple_response_arguments()
{
$this->configureForWsdl($this->locateFixture('/wsdl/functional/multiArgumentResponse.wsdl'));
Expand All @@ -43,30 +43,29 @@ public function test_it_can_load_wsdl_method_with_multiple_response_arguments()
$methods = $metadata->getMethods();

static::assertCount(1, $methods);
$this->assertMethodExists(
self::assertMethodExists(
$methods,
'validate',
[
new Parameter('input', XsdType::create('string'))
new Parameter('input', XsdType::guess('string'))
],
XsdType::create('array')
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::create('jeansSize')
$jeansType = XsdType::guess('jeansSize')
->withBaseType('anyType')
->withMemberTypes(['sizebyno', 'sizebystring']);

static::assertCount(1, $methods);
$this->assertMethodExists(
self::assertMethodExists(
$methods,
'validate',
[
Expand All @@ -76,20 +75,19 @@ public function test_it_can_load_union_types_in_methods()
);
}


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::create('valuelist')
$listType = XsdType::guess('valuelist')
->withBaseType('array')
->withMemberTypes(['integer']);

static::assertCount(1, $methods);
$this->assertMethodExists(
self::assertMethodExists(
$methods,
'validate',
[
Expand All @@ -99,26 +97,26 @@ public function test_it_can_load_list_types_in_methods()
);
}


public function test_it_can_load_simple_content_types()
{
$this->configureForWsdl($this->locateFixture('/wsdl/functional/simpleContent.wsdl'));

$metadata = $this->getMetadataProvider()->getMetadata();
$types = $metadata->getTypes();

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

static::assertCount(1, $types);
$this->assertTypeExists(
self::assertTypeExists(
$types,
XsdType::create('SimpleContent'),
XsdType::guess('SimpleContent'),
[
new Property('_', XsdType::create('integer')),
new Property('country', XsdType::create('string')),
new Property('_', XsdType::guess('integer')->withBaseType('float')->withMemberTypes(['decimal'])),
new Property('country', XsdType::guess('string')),
]
);
}


public function test_it_can_load_complex_types()
{
$this->configureForWsdl($this->locateFixture('/wsdl/functional/complex-type-request-response.wsdl'));
Expand All @@ -127,67 +125,63 @@ public function test_it_can_load_complex_types()
$types = $metadata->getTypes();

static::assertCount(2, $types);
$this->assertTypeExists(
self::assertTypeExists(
$types,
XsdType::create('ValidateRequest'),
XsdType::guess('ValidateRequest'),
[
new Property('input', XsdType::create('string'))
new Property('input', XsdType::guess('string')->withBaseType('anySimpleType'))
]
);
$this->assertTypeExists(
self::assertTypeExists(
$types,
XsdType::create('ValidateResponse'),
XsdType::guess('ValidateResponse'),
[
new Property('output', XsdType::create('string'))
new Property('output', XsdType::guess('string')->withBaseType('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::create('jeansSize')
$jeansType = XsdType::guess('jeansSize')
->withBaseType('anyType')
->withMemberTypes(['sizebyno', 'sizebystring']);

static::assertCount(1, $types);
$this->assertTypeExists(

self::assertTypeExists(
$types,
XsdType::create('jeansSizeContainer'),
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::create('valuelist')
$listType = XsdType::guess('valuelist')
->withBaseType('array')
->withMemberTypes(['integer']);

static::assertCount(1, $types);
$this->assertTypeExists(
self::assertTypeExists(
$types,
XsdType::create('valuelistContainer'),
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'));
Expand All @@ -199,28 +193,84 @@ public function test_it_can_handle_duplicate_type_declarations()

$type1 = $types->getIterator()[1];
static::assertSame('Store', $type1->getName());
static::assertEquals(XsdType::create('Store'), $type1->getXsdType());
static::assertEquals([new Property('Attribute2', XsdType::create('string'))], [...$type1->getProperties()]);
static::assertXsdTypeMatches(XsdType::guess('Store'), $type1->getXsdType());
static::assertPropertiesMatch(
new PropertyCollection(new Property('Attribute2', XsdType::guess('string')->withBaseType('anySimpleType'))),
$type1->getProperties()
);

$type2 = $types->getIterator()[1];
static::assertSame('Store', $type2->getName());
static::assertEquals(XsdType::create('Store'), $type2->getXsdType());
static::assertEquals([new Property('Attribute2', XsdType::create('string'))], [...$type2->getProperties()]);
static::assertXsdTypeMatches(XsdType::guess('Store'), $type2->getXsdType());
static::assertPropertiesMatch(
new PropertyCollection(new Property('Attribute2', XsdType::guess('string')->withBaseType('anySimpleType'))),
$type2->getProperties()
);
}
private function assertMethodExists(MethodCollection $methods, string $name, array $parameters, XsdType $returnType)

private static function assertMethodExists(MethodCollection $methods, string $name, array $parameters, XsdType $returnType)
{
$method = $methods->fetchByName($name);
static::assertSame($name, $method->getName());
static::assertEquals($parameters, [...$method->getParameters()]);
static::assertEquals($returnType, $method->getReturnType());
static::assertParametersMatch(new ParameterCollection(...$parameters), $method->getParameters());
static::assertXsdTypeMatches($returnType, $method->getReturnType());
}

private function assertTypeExists(TypeCollection $types, XsdType $xsdType, array $properties)
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::assertEquals($properties, [...$type->getProperties()]);
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 type will be checked optionally:
// ext-soap does not have an extended overview of all inherited types.
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.
}
}

0 comments on commit 590febc

Please sign in to comment.