|
@@ -47,7 +47,7 @@ final class TypeExpressionTest extends TestCase
|
|
null,
|
|
null,
|
|
[]
|
|
[]
|
|
);
|
|
);
|
|
- if (!$expression->isUnionType() || '|' === $expression->getTypesGlue()) {
|
|
|
|
|
|
+ if (!$expression->isCompositeType() || $expression->isUnionType()) {
|
|
self::assertSame(
|
|
self::assertSame(
|
|
[$unionTestNs.'\A', ...$expectedTypes, $unionTestNs.'\Z'],
|
|
[$unionTestNs.'\A', ...$expectedTypes, $unionTestNs.'\Z'],
|
|
[...$unionExpression->getTypes()]
|
|
[...$unionExpression->getTypes()]
|
|
@@ -55,6 +55,9 @@ final class TypeExpressionTest extends TestCase
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @return iterable<int|string, array{0: string, 1?: null|list<string>}>
|
|
|
|
+ */
|
|
public static function provideGetTypesCases(): iterable
|
|
public static function provideGetTypesCases(): iterable
|
|
{
|
|
{
|
|
yield ['int'];
|
|
yield ['int'];
|
|
@@ -451,30 +454,57 @@ final class TypeExpressionTest extends TestCase
|
|
/**
|
|
/**
|
|
* @dataProvider provideGetTypesGlueCases
|
|
* @dataProvider provideGetTypesGlueCases
|
|
*/
|
|
*/
|
|
- public function testGetTypesGlue(string $expectedTypesGlue, string $typesExpression): void
|
|
|
|
|
|
+ public function testGetTypesGlue(?string $expectedTypesGlue, string $typesExpression): void
|
|
{
|
|
{
|
|
$expression = new TypeExpression($typesExpression, null, []);
|
|
$expression = new TypeExpression($typesExpression, null, []);
|
|
self::assertSame($expectedTypesGlue, $expression->getTypesGlue());
|
|
self::assertSame($expectedTypesGlue, $expression->getTypesGlue());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @return iterable<array{0: '&'|'|', 1: string}>
|
|
|
|
|
|
+ * @return iterable<array{0: null|'&'|'|', 1: string}>
|
|
*/
|
|
*/
|
|
public static function provideGetTypesGlueCases(): iterable
|
|
public static function provideGetTypesGlueCases(): iterable
|
|
{
|
|
{
|
|
- yield ['|', 'string']; // for backward behaviour
|
|
|
|
|
|
+ yield [null, 'string'];
|
|
|
|
|
|
yield ['|', 'bool|string'];
|
|
yield ['|', 'bool|string'];
|
|
|
|
|
|
yield ['&', 'Foo&Bar'];
|
|
yield ['&', 'Foo&Bar'];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @dataProvider provideIsCompositeTypeCases
|
|
|
|
+ */
|
|
|
|
+ public function testIsCompositeType(bool $expectedIsCompositeType, string $typeExpression): void
|
|
|
|
+ {
|
|
|
|
+ $expression = new TypeExpression($typeExpression, null, []);
|
|
|
|
+
|
|
|
|
+ self::assertSame($expectedIsCompositeType, $expression->isCompositeType());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return iterable<array{0: bool, 1: string}>
|
|
|
|
+ */
|
|
|
|
+ public static function provideIsCompositeTypeCases(): iterable
|
|
|
|
+ {
|
|
|
|
+ yield [false, 'string'];
|
|
|
|
+
|
|
|
|
+ yield [false, 'iterable<Foo>'];
|
|
|
|
+
|
|
|
|
+ yield [true, 'iterable&stringable'];
|
|
|
|
+
|
|
|
|
+ yield [true, 'bool|string'];
|
|
|
|
+
|
|
|
|
+ yield [true, 'Foo|(Bar&Baz)'];
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @dataProvider provideIsUnionTypeCases
|
|
* @dataProvider provideIsUnionTypeCases
|
|
*/
|
|
*/
|
|
- public function testIsUnionType(bool $expectedIsUnionType, string $typesExpression): void
|
|
|
|
|
|
+ public function testIsUnionType(bool $expectedIsUnionType, string $typeExpression): void
|
|
{
|
|
{
|
|
- $expression = new TypeExpression($typesExpression, null, []);
|
|
|
|
|
|
+ $expression = new TypeExpression($typeExpression, null, []);
|
|
|
|
+
|
|
self::assertSame($expectedIsUnionType, $expression->isUnionType());
|
|
self::assertSame($expectedIsUnionType, $expression->isUnionType());
|
|
}
|
|
}
|
|
|
|
|
|
@@ -485,6 +515,8 @@ final class TypeExpressionTest extends TestCase
|
|
{
|
|
{
|
|
yield [false, 'string'];
|
|
yield [false, 'string'];
|
|
|
|
|
|
|
|
+ yield [false, 'iterable&stringable'];
|
|
|
|
+
|
|
yield [true, 'bool|string'];
|
|
yield [true, 'bool|string'];
|
|
|
|
|
|
yield [true, 'int|string|null'];
|
|
yield [true, 'int|string|null'];
|
|
@@ -496,10 +528,32 @@ final class TypeExpressionTest extends TestCase
|
|
yield [false, '?int'];
|
|
yield [false, '?int'];
|
|
|
|
|
|
yield [true, 'Foo|Bar'];
|
|
yield [true, 'Foo|Bar'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @dataProvider provideIsIntersectionTypeCases
|
|
|
|
+ */
|
|
|
|
+ public function testIsIntersectionType(bool $expectedIsIntersectionType, string $typeExpression): void
|
|
|
|
+ {
|
|
|
|
+ $expression = new TypeExpression($typeExpression, null, []);
|
|
|
|
+
|
|
|
|
+ self::assertSame($expectedIsIntersectionType, $expression->isIntersectionType());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return iterable<array{0: bool, 1: string}>
|
|
|
|
+ */
|
|
|
|
+ public static function provideIsIntersectionTypeCases(): iterable
|
|
|
|
+ {
|
|
|
|
+ yield [false, 'string'];
|
|
|
|
+
|
|
|
|
+ yield [false, 'string|int'];
|
|
|
|
|
|
yield [true, 'Foo&Bar'];
|
|
yield [true, 'Foo&Bar'];
|
|
|
|
|
|
yield [true, 'Foo&Bar&?Baz'];
|
|
yield [true, 'Foo&Bar&?Baz'];
|
|
|
|
+
|
|
|
|
+ yield [true, '\iterable&\Stringable'];
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|