|
3 | 3 | namespace PhproTest\SoapClient\Unit\CodeGenerator\Model; |
4 | 4 |
|
5 | 5 | use Phpro\SoapClient\CodeGenerator\Model\Property; |
| 6 | +use PHPUnit\Framework\Attributes\DataProvider; |
6 | 7 | use PHPUnit\Framework\TestCase; |
7 | 8 | use PHPUnit\Framework\Attributes\Test; |
8 | 9 | use Psl\Option\Option; |
9 | 10 | use Soap\Engine\Metadata\Model\Property as EngineProperty; |
| 11 | +use Soap\Engine\Metadata\Model\TypeMeta; |
10 | 12 | use Soap\Engine\Metadata\Model\XsdType; |
11 | 13 |
|
12 | 14 | /** |
@@ -57,4 +59,62 @@ public function it_can_use_a_php_built_in_class_as_type_name(): void |
57 | 59 | self::assertSame('DateInterval', $property->getXsdType()->getName()); |
58 | 60 | self::assertSame('DateInterval', $property->getXsdType()->getBaseType()); |
59 | 61 | } |
| 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 | + } |
60 | 120 | } |
0 commit comments