diff --git a/tests/unit/PseudoTypes/ArrayKeyTest.php b/tests/unit/PseudoTypes/ArrayKeyTest.php index c8ba5d8..21cefad 100644 --- a/tests/unit/PseudoTypes/ArrayKeyTest.php +++ b/tests/unit/PseudoTypes/ArrayKeyTest.php @@ -13,13 +13,21 @@ namespace phpDocumentor\Reflection\PseudoTypes; +use phpDocumentor\Reflection\Types\Compound; use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; final class ArrayKeyTest extends TestCase { - public function testArrayKeyCanBeConstructedAndStringifiedCorrectly(): void + public function testCreate(): void + { + $type = new ArrayKey(); + + $this->assertEquals(new Compound([new String_(), new Integer()]), $type->underlyingType()); + } + + public function testToString(): void { $this->assertSame('array-key', (string) (new ArrayKey())); } diff --git a/tests/unit/PseudoTypes/ArrayShapeItemTest.php b/tests/unit/PseudoTypes/ArrayShapeItemTest.php new file mode 100644 index 0000000..4bfd180 --- /dev/null +++ b/tests/unit/PseudoTypes/ArrayShapeItemTest.php @@ -0,0 +1,30 @@ +assertSame($key, $item->getKey()); + $this->assertSame($value, $item->getValue()); + $this->assertTrue($item->isOptional()); + } +} diff --git a/tests/unit/PseudoTypes/ArrayShapeTest.php b/tests/unit/PseudoTypes/ArrayShapeTest.php index 14f3af3..47488b0 100644 --- a/tests/unit/PseudoTypes/ArrayShapeTest.php +++ b/tests/unit/PseudoTypes/ArrayShapeTest.php @@ -4,11 +4,13 @@ namespace phpDocumentor\Reflection\PseudoTypes; +use phpDocumentor\Reflection\Types\Array_; +use phpDocumentor\Reflection\Types\Mixed_; use PHPUnit\Framework\TestCase; class ArrayShapeTest extends TestCase { - public function testExposeItems(): void + public function testCreate(): void { $item1 = new ArrayShapeItem('foo', new True_(), false); $item2 = new ArrayShapeItem('bar', new False_(), true); @@ -16,6 +18,7 @@ public function testExposeItems(): void $arrayShape = new ArrayShape($item1, $item2); $this->assertSame([$item1, $item2], $arrayShape->getItems()); + $this->assertEquals(new Array_(new Mixed_(), new ArrayKey()), $arrayShape->underlyingType()); } /** diff --git a/tests/unit/PseudoTypes/CallableStringTest.php b/tests/unit/PseudoTypes/CallableStringTest.php new file mode 100644 index 0000000..5134b5a --- /dev/null +++ b/tests/unit/PseudoTypes/CallableStringTest.php @@ -0,0 +1,32 @@ +assertEquals(new String_(), $type->underlyingType()); + } + + public function testToString(): void + { + $this->assertSame('callable-string', (string) (new CallableString())); + } +} diff --git a/tests/unit/PseudoTypes/ClassStringTest.php b/tests/unit/PseudoTypes/ClassStringTest.php index fe5cbe2..3e578c2 100644 --- a/tests/unit/PseudoTypes/ClassStringTest.php +++ b/tests/unit/PseudoTypes/ClassStringTest.php @@ -16,14 +16,24 @@ use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\Types\Compound; use phpDocumentor\Reflection\Types\Object_; +use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; class ClassStringTest extends TestCase { + public function testCreate(): void + { + $genericType = new Object_(new Fqsen('\Foo\Bar')); + $type = new ClassString($genericType); + + $this->assertSame($genericType, $type->getGenericType()); + $this->assertEquals(new String_(), $type->underlyingType()); + } + /** - * @dataProvider provideClassStrings + * @dataProvider provideToStringData */ - public function testClassStringStringifyCorrectly(ClassString $type, string $expectedString): void + public function testToString(ClassString $type, string $expectedString): void { $this->assertSame($expectedString, (string) $type); } @@ -31,7 +41,7 @@ public function testClassStringStringifyCorrectly(ClassString $type, string $exp /** * @return array */ - public function provideClassStrings(): array + public function provideToStringData(): array { return [ 'generic class string' => [new ClassString(), 'class-string'], diff --git a/tests/unit/PseudoTypes/ConditionalForParameterTest.php b/tests/unit/PseudoTypes/ConditionalForParameterTest.php index bedae07..5a82240 100644 --- a/tests/unit/PseudoTypes/ConditionalForParameterTest.php +++ b/tests/unit/PseudoTypes/ConditionalForParameterTest.php @@ -6,6 +6,7 @@ use phpDocumentor\Reflection\Types\Array_; use phpDocumentor\Reflection\Types\Integer; +use phpDocumentor\Reflection\Types\Mixed_; use phpDocumentor\Reflection\Types\Static_; use PHPUnit\Framework\TestCase; @@ -24,6 +25,7 @@ public function testCreate(): void $this->assertSame($targetType, $type->getTargetType()); $this->assertSame($if, $type->getIf()); $this->assertSame($else, $type->getElse()); + $this->assertEquals(new Mixed_(), $type->underlyingType()); } /** diff --git a/tests/unit/PseudoTypes/ConditionalTest.php b/tests/unit/PseudoTypes/ConditionalTest.php index 3e6f585..0093868 100644 --- a/tests/unit/PseudoTypes/ConditionalTest.php +++ b/tests/unit/PseudoTypes/ConditionalTest.php @@ -7,6 +7,7 @@ use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\Types\Array_; use phpDocumentor\Reflection\Types\Integer; +use phpDocumentor\Reflection\Types\Mixed_; use phpDocumentor\Reflection\Types\Object_; use phpDocumentor\Reflection\Types\Static_; use PHPUnit\Framework\TestCase; @@ -26,6 +27,7 @@ public function testCreate(): void $this->assertSame($targetType, $type->getTargetType()); $this->assertSame($if, $type->getIf()); $this->assertSame($else, $type->getElse()); + $this->assertEquals(new Mixed_(), $type->underlyingType()); } /** diff --git a/tests/unit/PseudoTypes/ConstExpressionTest.php b/tests/unit/PseudoTypes/ConstExpressionTest.php new file mode 100644 index 0000000..b26ca28 --- /dev/null +++ b/tests/unit/PseudoTypes/ConstExpressionTest.php @@ -0,0 +1,33 @@ +assertSame($owner, $type->getOwner()); + $this->assertSame($expression, $type->getExpression()); + $this->assertEquals(new Mixed_(), $type->underlyingType()); + } +} diff --git a/tests/unit/PseudoTypes/EnumStringTest.php b/tests/unit/PseudoTypes/EnumStringTest.php new file mode 100644 index 0000000..9645e5d --- /dev/null +++ b/tests/unit/PseudoTypes/EnumStringTest.php @@ -0,0 +1,63 @@ +assertSame($genericType, $type->getGenericType()); + $this->assertEquals(new String_(), $type->underlyingType()); + } + + /** + * @dataProvider provideToStringData + */ + public function testToString(EnumString $type, string $expectedString): void + { + $this->assertSame($expectedString, (string) $type); + } + + /** + * @return array + */ + public function provideToStringData(): array + { + return [ + 'basic' => [new EnumString(), 'enum-string'], + 'with generics' => [ + new EnumString(new Object_(new Fqsen('\Foo\Bar'))), + 'enum-string<\Foo\Bar>', + ], + 'more than one enum' => [ + new EnumString( + new Compound([ + new Object_(new Fqsen('\Foo\Bar')), + new Object_(new Fqsen('\Foo\Barrr')), + ]) + ), + 'enum-string<\Foo\Bar|\Foo\Barrr>', + ], + ]; + } +} diff --git a/tests/unit/PseudoTypes/FloatValueTest.php b/tests/unit/PseudoTypes/FloatValueTest.php new file mode 100644 index 0000000..1d5db38 --- /dev/null +++ b/tests/unit/PseudoTypes/FloatValueTest.php @@ -0,0 +1,34 @@ +assertSame($value, $type->getValue()); + $this->assertEquals(new Float_(), $type->underlyingType()); + } + + public function testToString(): void + { + $this->assertSame('12.12', (string) (new FloatValue(12.12))); + } +} diff --git a/tests/unit/PseudoTypes/HtmlEscapedStringTest.php b/tests/unit/PseudoTypes/HtmlEscapedStringTest.php new file mode 100644 index 0000000..eeb635a --- /dev/null +++ b/tests/unit/PseudoTypes/HtmlEscapedStringTest.php @@ -0,0 +1,32 @@ +assertEquals(new String_(), $type->underlyingType()); + } + + public function testToString(): void + { + $this->assertSame('html-escaped-string', (string) (new HtmlEscapedString())); + } +} diff --git a/tests/unit/PseudoTypes/IntMaskOfTest.php b/tests/unit/PseudoTypes/IntMaskOfTest.php index b48edfc..68eaa01 100644 --- a/tests/unit/PseudoTypes/IntMaskOfTest.php +++ b/tests/unit/PseudoTypes/IntMaskOfTest.php @@ -5,6 +5,7 @@ namespace phpDocumentor\Reflection\PseudoTypes; use phpDocumentor\Reflection\Types\Compound; +use phpDocumentor\Reflection\Types\Integer; use PHPUnit\Framework\TestCase; class IntMaskOfTest extends TestCase @@ -15,6 +16,7 @@ public function testCreate(): void $type = new IntMaskOf($childType); $this->assertSame($childType, $type->getType()); + $this->assertEquals(new Integer(), $type->underlyingType()); } public function testToString(): void diff --git a/tests/unit/PseudoTypes/IntMaskTest.php b/tests/unit/PseudoTypes/IntMaskTest.php index e2e0881..cdeaee8 100644 --- a/tests/unit/PseudoTypes/IntMaskTest.php +++ b/tests/unit/PseudoTypes/IntMaskTest.php @@ -4,6 +4,7 @@ namespace phpDocumentor\Reflection\PseudoTypes; +use phpDocumentor\Reflection\Types\Integer; use PHPUnit\Framework\TestCase; class IntMaskTest extends TestCase @@ -14,6 +15,7 @@ public function testCreate(): void $type = new IntMask(...$childTypes); $this->assertSame($childTypes, $type->getTypes()); + $this->assertEquals(new Integer(), $type->underlyingType()); } public function testToString(): void diff --git a/tests/unit/PseudoTypes/IntRangeTest.php b/tests/unit/PseudoTypes/IntegerRangeTest.php similarity index 53% rename from tests/unit/PseudoTypes/IntRangeTest.php rename to tests/unit/PseudoTypes/IntegerRangeTest.php index cf32440..09bf27f 100644 --- a/tests/unit/PseudoTypes/IntRangeTest.php +++ b/tests/unit/PseudoTypes/IntegerRangeTest.php @@ -13,22 +13,34 @@ namespace phpDocumentor\Reflection\PseudoTypes; +use phpDocumentor\Reflection\Types\Integer; use PHPUnit\Framework\TestCase; -class IntRangeTest extends TestCase +class IntegerRangeTest extends TestCase { + public function testCreate(): void + { + $minValue = '-5'; + $maxValue = '5'; + $type = new IntegerRange($minValue, $maxValue); + + $this->assertSame($minValue, $type->getMinValue()); + $this->assertSame($maxValue, $type->getMaxValue()); + $this->assertEquals(new Integer(), $type->underlyingType()); + } + /** - * @dataProvider provideArrays + * @dataProvider provideToStringData */ - public function testArrayStringifyCorrectly(IntegerRange $array, string $expectedString): void + public function testToString(IntegerRange $type, string $expectedString): void { - $this->assertSame($expectedString, (string) $array); + $this->assertSame($expectedString, (string) $type); } /** - * @return mixed[] + * @return array */ - public function provideArrays(): array + public function provideToStringData(): array { return [ 'simple int range' => [new IntegerRange('-5', '5'), 'int<-5, 5>'], diff --git a/tests/unit/PseudoTypes/IntegerValueTest.php b/tests/unit/PseudoTypes/IntegerValueTest.php new file mode 100644 index 0000000..fcc441f --- /dev/null +++ b/tests/unit/PseudoTypes/IntegerValueTest.php @@ -0,0 +1,34 @@ +assertSame($value, $type->getValue()); + $this->assertEquals(new Integer(), $type->underlyingType()); + } + + public function testToString(): void + { + $this->assertSame('12', (string) (new IntegerValue(12))); + } +} diff --git a/tests/unit/PseudoTypes/InterfaceStringTest.php b/tests/unit/PseudoTypes/InterfaceStringTest.php index 5a6becc..a56823e 100644 --- a/tests/unit/PseudoTypes/InterfaceStringTest.php +++ b/tests/unit/PseudoTypes/InterfaceStringTest.php @@ -16,14 +16,24 @@ use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\Types\Compound; use phpDocumentor\Reflection\Types\Object_; +use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; class InterfaceStringTest extends TestCase { + public function testCreate(): void + { + $genericType = new Object_(new Fqsen('\Foo\Bar')); + $type = new InterfaceString($genericType); + + $this->assertSame($genericType, $type->getGenericType()); + $this->assertEquals(new String_(), $type->underlyingType()); + } + /** - * @dataProvider provideInterfaceStrings + * @dataProvider provideToStringData */ - public function testInterfaceStringStringifyCorrectly(InterfaceString $type, string $expectedString): void + public function testToString(InterfaceString $type, string $expectedString): void { $this->assertSame($expectedString, (string) $type); } @@ -31,7 +41,7 @@ public function testInterfaceStringStringifyCorrectly(InterfaceString $type, str /** * @return array */ - public function provideInterfaceStrings(): array + public function provideToStringData(): array { return [ 'generic interface string' => [new InterfaceString(), 'interface-string'], diff --git a/tests/unit/PseudoTypes/KeyOfTest.php b/tests/unit/PseudoTypes/KeyOfTest.php index c96d837..001d0ab 100644 --- a/tests/unit/PseudoTypes/KeyOfTest.php +++ b/tests/unit/PseudoTypes/KeyOfTest.php @@ -16,6 +16,7 @@ public function testCreate(): void $type = new KeyOf($childType); $this->assertSame($childType, $type->getType()); + $this->assertEquals(new ArrayKey(), $type->underlyingType()); } public function testToString(): void diff --git a/tests/unit/PseudoTypes/ListShapeTest.php b/tests/unit/PseudoTypes/ListShapeTest.php new file mode 100644 index 0000000..034acd6 --- /dev/null +++ b/tests/unit/PseudoTypes/ListShapeTest.php @@ -0,0 +1,26 @@ +assertSame('list{1}', (string) $type); + } +} diff --git a/tests/unit/PseudoTypes/ListTest.php b/tests/unit/PseudoTypes/ListTest.php index 6fb313e..8f51c51 100644 --- a/tests/unit/PseudoTypes/ListTest.php +++ b/tests/unit/PseudoTypes/ListTest.php @@ -13,6 +13,7 @@ namespace phpDocumentor\Reflection\PseudoTypes; +use phpDocumentor\Reflection\Types\Array_; use phpDocumentor\Reflection\Types\Compound; use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\Mixed_; @@ -21,18 +22,29 @@ class ListTest extends TestCase { + public function testCreateWithoutParams(): void + { + $type = new List_(); + + $this->assertEquals(new Integer(), $type->getOriginalKeyType()); + $this->assertNull($type->getOriginalValueType()); + $this->assertEquals(new Integer(), $type->getKeyType()); + $this->assertEquals(new Mixed_(), $type->getValueType()); + $this->assertEquals(new Array_(), $type->underlyingType()); + } + /** - * @dataProvider provideArrays + * @dataProvider provideToStringData */ - public function testArrayStringifyCorrectly(List_ $array, string $expectedString): void + public function testToString(List_ $array, string $expectedString): void { $this->assertSame($expectedString, (string) $array); } /** - * @return mixed[] + * @return array */ - public function provideArrays(): array + public function provideToStringData(): array { return [ 'simple list' => [new List_(), 'list'], diff --git a/tests/unit/PseudoTypes/LiteralStringTest.php b/tests/unit/PseudoTypes/LiteralStringTest.php new file mode 100644 index 0000000..ef5131f --- /dev/null +++ b/tests/unit/PseudoTypes/LiteralStringTest.php @@ -0,0 +1,32 @@ +assertEquals(new String_(), $type->underlyingType()); + } + + public function testToString(): void + { + $this->assertSame('literal-string', (string) (new LiteralString())); + } +} diff --git a/tests/unit/PseudoTypes/LowercaseStringTest.php b/tests/unit/PseudoTypes/LowercaseStringTest.php new file mode 100644 index 0000000..8f358fd --- /dev/null +++ b/tests/unit/PseudoTypes/LowercaseStringTest.php @@ -0,0 +1,32 @@ +assertEquals(new String_(), $type->underlyingType()); + } + + public function testToString(): void + { + $this->assertSame('lowercase-string', (string) (new LowercaseString())); + } +} diff --git a/tests/unit/PseudoTypes/NegativeIntegerTest.php b/tests/unit/PseudoTypes/NegativeIntegerTest.php new file mode 100644 index 0000000..8c889d3 --- /dev/null +++ b/tests/unit/PseudoTypes/NegativeIntegerTest.php @@ -0,0 +1,32 @@ +assertEquals(new Integer(), $type->underlyingType()); + } + + public function testToString(): void + { + $this->assertSame('negative-int', (string) (new NegativeInteger())); + } +} diff --git a/tests/unit/PseudoTypes/NonEmptyArrayTest.php b/tests/unit/PseudoTypes/NonEmptyArrayTest.php index 0ae5acd..0531179 100644 --- a/tests/unit/PseudoTypes/NonEmptyArrayTest.php +++ b/tests/unit/PseudoTypes/NonEmptyArrayTest.php @@ -13,6 +13,7 @@ namespace phpDocumentor\Reflection\PseudoTypes; +use phpDocumentor\Reflection\Types\Array_; use phpDocumentor\Reflection\Types\Compound; use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\Mixed_; @@ -21,18 +22,29 @@ class NonEmptyArrayTest extends TestCase { + public function testCreateWithoutParams(): void + { + $type = new NonEmptyArray(); + + $this->assertNull($type->getOriginalKeyType()); + $this->assertNull($type->getOriginalValueType()); + $this->assertEquals(new Compound([new String_(), new Integer()]), $type->getKeyType()); + $this->assertEquals(new Mixed_(), $type->getValueType()); + $this->assertEquals(new Array_(), $type->underlyingType()); + } + /** - * @dataProvider provideArrays + * @dataProvider provideToStringData */ - public function testArrayStringifyCorrectly(NonEmptyArray $array, string $expectedString): void + public function testToString(NonEmptyArray $type, string $expectedString): void { - $this->assertSame($expectedString, (string) $array); + $this->assertSame($expectedString, (string) $type); } /** - * @return mixed[] + * @return array */ - public function provideArrays(): array + public function provideToStringData(): array { return [ 'simple non-empty-array' => [new NonEmptyArray(), 'non-empty-array'], diff --git a/tests/unit/PseudoTypes/NonEmptyListTest.php b/tests/unit/PseudoTypes/NonEmptyListTest.php index 69dedd7..75cd2f6 100644 --- a/tests/unit/PseudoTypes/NonEmptyListTest.php +++ b/tests/unit/PseudoTypes/NonEmptyListTest.php @@ -13,6 +13,7 @@ namespace phpDocumentor\Reflection\PseudoTypes; +use phpDocumentor\Reflection\Types\Array_; use phpDocumentor\Reflection\Types\Compound; use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\Mixed_; @@ -21,18 +22,29 @@ class NonEmptyListTest extends TestCase { + public function testCreateWithoutParams(): void + { + $type = new NonEmptyList(); + + $this->assertEquals(new Integer(), $type->getOriginalKeyType()); + $this->assertNull($type->getOriginalValueType()); + $this->assertEquals(new Integer(), $type->getKeyType()); + $this->assertEquals(new Mixed_(), $type->getValueType()); + $this->assertEquals(new Array_(null, new Integer()), $type->underlyingType()); + } + /** - * @dataProvider provideArrays + * @dataProvider provideToStringData */ - public function testArrayStringifyCorrectly(NonEmptyList $array, string $expectedString): void + public function testToString(NonEmptyList $array, string $expectedString): void { $this->assertSame($expectedString, (string) $array); } /** - * @return mixed[] + * @return array */ - public function provideArrays(): array + public function provideToStringData(): array { return [ 'simple non-empty-list' => [new NonEmptyList(), 'non-empty-list'], diff --git a/tests/unit/PseudoTypes/NonEmptyLowercaseStringTest.php b/tests/unit/PseudoTypes/NonEmptyLowercaseStringTest.php new file mode 100644 index 0000000..291f856 --- /dev/null +++ b/tests/unit/PseudoTypes/NonEmptyLowercaseStringTest.php @@ -0,0 +1,32 @@ +assertEquals(new String_(), $type->underlyingType()); + } + + public function testToString(): void + { + $this->assertSame('non-empty-lowercase-string', (string) (new NonEmptyLowercaseString())); + } +} diff --git a/tests/unit/PseudoTypes/NonEmptyStringTest.php b/tests/unit/PseudoTypes/NonEmptyStringTest.php new file mode 100644 index 0000000..9dc9226 --- /dev/null +++ b/tests/unit/PseudoTypes/NonEmptyStringTest.php @@ -0,0 +1,32 @@ +assertEquals(new String_(), $type->underlyingType()); + } + + public function testToString(): void + { + $this->assertSame('non-empty-string', (string) (new NonEmptyString())); + } +} diff --git a/tests/unit/PseudoTypes/NumericStringTest.php b/tests/unit/PseudoTypes/NumericStringTest.php new file mode 100644 index 0000000..c3b9a8b --- /dev/null +++ b/tests/unit/PseudoTypes/NumericStringTest.php @@ -0,0 +1,32 @@ +assertEquals(new String_(), $type->underlyingType()); + } + + public function testToString(): void + { + $this->assertSame('numeric-string', (string) (new NumericString())); + } +} diff --git a/tests/unit/PseudoTypes/ObjectShapeTest.php b/tests/unit/PseudoTypes/ObjectShapeTest.php new file mode 100644 index 0000000..b5c6268 --- /dev/null +++ b/tests/unit/PseudoTypes/ObjectShapeTest.php @@ -0,0 +1,60 @@ +assertSame([$item1, $item2], $objectShape->getItems()); + $this->assertEquals(new Object_(), $objectShape->underlyingType()); + } + + /** + * @dataProvider provideToStringData + */ + public function testToString(string $expectedResult, ObjectShape $objectShape): void + { + $this->assertSame($expectedResult, (string) $objectShape); + } + + /** + * @return array + */ + public static function provideToStringData(): array + { + return [ + 'with keys' => [ + 'object{foo: true, bar?: false}', + new ObjectShape( + new ObjectShapeItem('foo', new True_(), false), + new ObjectShapeItem('bar', new False_(), true) + ), + ], + 'with empty keys' => [ + 'object{true, false}', + new ObjectShape( + new ObjectShapeItem('', new True_(), false), + new ObjectShapeItem('', new False_(), false) + ), + ], + 'without keys' => [ + 'object{true, false}', + new ObjectShape( + new ObjectShapeItem(null, new True_(), false), + new ObjectShapeItem(null, new False_(), false) + ), + ], + ]; + } +} diff --git a/tests/unit/PseudoTypes/OffsetAccessTest.php b/tests/unit/PseudoTypes/OffsetAccessTest.php index 44afa04..ccb354f 100644 --- a/tests/unit/PseudoTypes/OffsetAccessTest.php +++ b/tests/unit/PseudoTypes/OffsetAccessTest.php @@ -5,6 +5,7 @@ namespace phpDocumentor\Reflection\PseudoTypes; use phpDocumentor\Reflection\Fqsen; +use phpDocumentor\Reflection\Types\Mixed_; use phpDocumentor\Reflection\Types\Object_; use PHPUnit\Framework\TestCase; @@ -18,6 +19,7 @@ public function testCreate(): void $this->assertSame($mainType, $type->getType()); $this->assertSame($offset, $type->getOffset()); + $this->assertEquals(new Mixed_(), $type->underlyingType()); } /** diff --git a/tests/unit/PseudoTypes/PositiveIntegerTest.php b/tests/unit/PseudoTypes/PositiveIntegerTest.php new file mode 100644 index 0000000..385e02a --- /dev/null +++ b/tests/unit/PseudoTypes/PositiveIntegerTest.php @@ -0,0 +1,32 @@ +assertEquals(new Integer(), $type->underlyingType()); + } + + public function testToString(): void + { + $this->assertSame('positive-int', (string) (new PositiveInteger())); + } +} diff --git a/tests/unit/PseudoTypes/StringValueTest.php b/tests/unit/PseudoTypes/StringValueTest.php new file mode 100644 index 0000000..5c582de --- /dev/null +++ b/tests/unit/PseudoTypes/StringValueTest.php @@ -0,0 +1,34 @@ +assertSame($value, $type->getValue()); + $this->assertEquals(new String_(), $type->underlyingType()); + } + + public function testToString(): void + { + $this->assertSame('"abcd"', (string) (new StringValue('abcd'))); + } +} diff --git a/tests/unit/PseudoTypes/TraitStringTest.php b/tests/unit/PseudoTypes/TraitStringTest.php new file mode 100644 index 0000000..22ca0c1 --- /dev/null +++ b/tests/unit/PseudoTypes/TraitStringTest.php @@ -0,0 +1,63 @@ +assertSame($genericType, $type->getGenericType()); + $this->assertEquals(new String_(), $type->underlyingType()); + } + + /** + * @dataProvider provideToStringData + */ + public function testToString(TraitString $type, string $expectedString): void + { + $this->assertSame($expectedString, (string) $type); + } + + /** + * @return array + */ + public function provideToStringData(): array + { + return [ + 'basic' => [new TraitString(), 'trait-string'], + 'with generic' => [ + new TraitString(new Object_(new Fqsen('\Foo\Bar'))), + 'trait-string<\Foo\Bar>', + ], + 'with compound generic' => [ + new TraitString( + new Compound([ + new Object_(new Fqsen('\Foo\Bar')), + new Object_(new Fqsen('\Foo\Barrr')), + ]) + ), + 'trait-string<\Foo\Bar|\Foo\Barrr>', + ], + ]; + } +} diff --git a/tests/unit/PseudoTypes/ValueOfTest.php b/tests/unit/PseudoTypes/ValueOfTest.php index 2fc6f87..9a1b7d1 100644 --- a/tests/unit/PseudoTypes/ValueOfTest.php +++ b/tests/unit/PseudoTypes/ValueOfTest.php @@ -5,6 +5,7 @@ namespace phpDocumentor\Reflection\PseudoTypes; use phpDocumentor\Reflection\Fqsen; +use phpDocumentor\Reflection\Types\Mixed_; use phpDocumentor\Reflection\Types\Object_; use PHPUnit\Framework\TestCase; @@ -16,6 +17,7 @@ public function testCreate(): void $type = new ValueOf($childType); $this->assertSame($childType, $type->getType()); + $this->assertEquals(new Mixed_(), $type->underlyingType()); } public function testToString(): void diff --git a/tests/unit/TypeResolverTest.php b/tests/unit/TypeResolverTest.php index fadc9fe..7d6bfe8 100644 --- a/tests/unit/TypeResolverTest.php +++ b/tests/unit/TypeResolverTest.php @@ -880,6 +880,10 @@ public function typeProvider(): array new StringValue('bar') ), ], + [ + '100.5', + new FloatValue(100.5), + ], ]; }