|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of phpDocumentor. |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + * |
| 11 | + * @link http://phpdoc.org |
| 12 | + */ |
| 13 | + |
| 14 | +namespace phpDocumentor\Reflection\PseudoTypes; |
| 15 | + |
| 16 | +use phpDocumentor\Reflection\Fqsen; |
| 17 | +use phpDocumentor\Reflection\Types\Compound; |
| 18 | +use phpDocumentor\Reflection\Types\Object_; |
| 19 | +use phpDocumentor\Reflection\Types\String_; |
| 20 | +use PHPUnit\Framework\TestCase; |
| 21 | + |
| 22 | +class EnumStringTest extends TestCase |
| 23 | +{ |
| 24 | + public function testCreate(): void |
| 25 | + { |
| 26 | + $genericType = new Object_(new Fqsen('\Foo\Bar')); |
| 27 | + $type = new EnumString($genericType); |
| 28 | + |
| 29 | + $this->assertSame($genericType, $type->getGenericType()); |
| 30 | + $this->assertEquals(new String_(), $type->underlyingType()); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @dataProvider provideToStringData |
| 35 | + */ |
| 36 | + public function testToString(EnumString $type, string $expectedString): void |
| 37 | + { |
| 38 | + $this->assertSame($expectedString, (string) $type); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @return array<string, array{EnumString, string}> |
| 43 | + */ |
| 44 | + public function provideToStringData(): array |
| 45 | + { |
| 46 | + return [ |
| 47 | + 'basic' => [new EnumString(), 'enum-string'], |
| 48 | + 'with generics' => [ |
| 49 | + new EnumString(new Object_(new Fqsen('\Foo\Bar'))), |
| 50 | + 'enum-string<\Foo\Bar>', |
| 51 | + ], |
| 52 | + 'more than one enum' => [ |
| 53 | + new EnumString( |
| 54 | + new Compound([ |
| 55 | + new Object_(new Fqsen('\Foo\Bar')), |
| 56 | + new Object_(new Fqsen('\Foo\Barrr')), |
| 57 | + ]) |
| 58 | + ), |
| 59 | + 'enum-string<\Foo\Bar|\Foo\Barrr>', |
| 60 | + ], |
| 61 | + ]; |
| 62 | + } |
| 63 | +} |
0 commit comments