|
9 | 9 | final class TypeTest extends TestCase |
10 | 10 | { |
11 | 11 | /** @dataProvider provide_types_to_strings */ |
12 | | - public function test_type_to_string(UnionType $type, string $expected) { |
| 12 | + public function test_type_to_string(UnionType $type, string $expected, ?string $expectedPhpString) { |
13 | 13 | $this->assertEquals($expected, $type->toString()); |
| 14 | + $this->assertEquals($expectedPhpString, $type->toPhpString()); |
14 | 15 | } |
15 | 16 |
|
16 | 17 | public function provide_types_to_strings() { |
17 | | - yield 'scalar' => [AtomicType::asUnion('string'), 'string']; |
18 | | - yield 'union scalar' => [new UnionType([new AtomicType('int'), new AtomicType('string')]), 'int|string']; |
19 | | - yield 'nullable' => [AtomicType::asUnion('string', [], true), '?string']; |
20 | | - yield 'scalar array' => [AtomicType::asUnion('string', [], false, true), 'string[]']; |
21 | | - yield 'generics' => [AtomicType::asUnion('array', [ |
22 | | - AtomicType::asUnion('string', []), |
23 | | - AtomicType::asUnion('int', [], true) |
24 | | - ]), 'array<string, ?int>']; |
| 18 | + yield 'scalar' => [ |
| 19 | + 'type' => AtomicType::asUnion('string'), |
| 20 | + 'toString' => 'string', |
| 21 | + 'toPhpString' => 'string' |
| 22 | + ]; |
| 23 | + yield 'union scalar' => [ |
| 24 | + 'type' => new UnionType([new AtomicType('int'), new AtomicType('string')]), |
| 25 | + 'toString' => 'int|string', |
| 26 | + 'toPhpString' => null, |
| 27 | + ]; |
| 28 | + yield 'nullable' => [ |
| 29 | + 'type' => AtomicType::asUnion('string', [], true), |
| 30 | + 'toString' => '?string', |
| 31 | + 'toPhpString' => '?string', |
| 32 | + ]; |
| 33 | + yield 'scalar array' => [ |
| 34 | + 'type' => AtomicType::asUnion('string', [], false, true), |
| 35 | + 'toString' => 'string[]', |
| 36 | + 'toPhpString' => 'array', |
| 37 | + ]; |
| 38 | + yield 'nullable scalar array' => [ |
| 39 | + 'type' => AtomicType::asUnion('string', [], true, true), |
| 40 | + 'toString' => '?string[]', |
| 41 | + 'toPhpString' => '?array', |
| 42 | + ]; |
| 43 | + yield 'generic array' => [ |
| 44 | + 'type' => AtomicType::asUnion('array', [ |
| 45 | + AtomicType::asUnion('string', []), |
| 46 | + AtomicType::asUnion('int', [], true) |
| 47 | + ]), |
| 48 | + 'toString' => 'array<string, ?int>', |
| 49 | + 'toPhpString' => 'array', |
| 50 | + ]; |
25 | 51 | } |
26 | 52 | } |
0 commit comments