Skip to content

Commit 0081710

Browse files
authored
Merge pull request #592 from veewee/fix-xsd-language-like-simple-types
Fix xsd:language-like simple type generations.
2 parents ebaf487 + 980c322 commit 0081710

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

src/Phpro/SoapClient/CodeGenerator/Model/Property.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ public function getType(): string
100100
return $this->type;
101101
}
102102

103+
if ($this->meta->isSimple()->unwrapOr(false)
104+
&& Normalizer::isKnownType($this->xsdType->getBaseType())
105+
) {
106+
return $this->xsdType->getBaseType();
107+
}
108+
103109
if (!$this->namespace) {
104110
return '\\'.Normalizer::normalizeClassname($this->type);
105111
}

test/PhproTest/SoapClient/Unit/CodeGenerator/Model/PropertyTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
namespace PhproTest\SoapClient\Unit\CodeGenerator\Model;
44

55
use Phpro\SoapClient\CodeGenerator\Model\Property;
6+
use PHPUnit\Framework\Attributes\DataProvider;
67
use PHPUnit\Framework\TestCase;
78
use PHPUnit\Framework\Attributes\Test;
89
use Psl\Option\Option;
910
use Soap\Engine\Metadata\Model\Property as EngineProperty;
11+
use Soap\Engine\Metadata\Model\TypeMeta;
1012
use Soap\Engine\Metadata\Model\XsdType;
1113

1214
/**
@@ -57,4 +59,62 @@ public function it_can_use_a_php_built_in_class_as_type_name(): void
5759
self::assertSame('DateInterval', $property->getXsdType()->getName());
5860
self::assertSame('DateInterval', $property->getXsdType()->getBaseType());
5961
}
62+
63+
#[Test]
64+
#[DataProvider('provideTypes')]
65+
public function it_can_figure_out_the_type(Property $property, string $expectedType): void
66+
{
67+
self::assertSame($expectedType, $property->getType());
68+
}
69+
70+
public static function provideTypes()
71+
{
72+
yield 'known_simple_type' => [
73+
Property::fromMetaData(
74+
'MyApp',
75+
new EngineProperty(
76+
'property',
77+
XsdType::create('string')
78+
)
79+
),
80+
'string'
81+
];
82+
yield 'known_simple_base_type' => [
83+
Property::fromMetaData(
84+
'MyApp',
85+
new EngineProperty(
86+
'property',
87+
XsdType::create('language')
88+
->withXmlNamespace('http://www.w3.org/2001/XMLSchema')
89+
->withXmlNamespaceName('xsd')
90+
->withBaseType('string')
91+
->withMemberTypes(['token'])
92+
->withMeta(static fn (TypeMeta $meta) => $meta->withIsSimple(true))
93+
)
94+
),
95+
'string'
96+
];
97+
98+
yield 'root namespace' => [
99+
Property::fromMetaData(
100+
'',
101+
new EngineProperty(
102+
'property',
103+
XsdType::create('MyType')
104+
)
105+
),
106+
'\\MyType'
107+
];
108+
109+
yield 'namespaced' => [
110+
Property::fromMetaData(
111+
'MyApp',
112+
new EngineProperty(
113+
'property',
114+
XsdType::create('MyType')
115+
)
116+
),
117+
'\\MyApp\\MyType'
118+
];
119+
}
60120
}

0 commit comments

Comments
 (0)