|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace integration\PHP8; |
| 6 | + |
| 7 | +use phpDocumentor\Reflection\File\LocalFile; |
| 8 | +use phpDocumentor\Reflection\Fqsen; |
| 9 | +use phpDocumentor\Reflection\Php\Project; |
| 10 | +use phpDocumentor\Reflection\Php\ProjectFactory; |
| 11 | +use phpDocumentor\Reflection\PseudoTypes\False_; |
| 12 | +use phpDocumentor\Reflection\Types\Compound; |
| 13 | +use phpDocumentor\Reflection\Types\Integer; |
| 14 | +use phpDocumentor\Reflection\Types\Mixed_; |
| 15 | +use phpDocumentor\Reflection\Types\Null_; |
| 16 | +use phpDocumentor\Reflection\Types\Object_; |
| 17 | +use phpDocumentor\Reflection\Types\Static_; |
| 18 | +use phpDocumentor\Reflection\Types\String_; |
| 19 | +use PHPUnit\Framework\TestCase; |
| 20 | + |
| 21 | +/** |
| 22 | + * @coversNothing |
| 23 | + */ |
| 24 | +final class UnionTypesTest extends TestCase |
| 25 | +{ |
| 26 | + const FILE = __DIR__ . '/../data/PHP8/UnionTypes.php'; |
| 27 | + /** @var ProjectFactory */ |
| 28 | + private $fixture; |
| 29 | + |
| 30 | + public function testUnionTypes() : void |
| 31 | + { |
| 32 | + $this->fixture = ProjectFactory::createInstance(); |
| 33 | + |
| 34 | + /** @var Project $project */ |
| 35 | + $project = $this->fixture->create( |
| 36 | + 'PHP8', |
| 37 | + [ |
| 38 | + new LocalFile(self::FILE), |
| 39 | + ] |
| 40 | + ); |
| 41 | + |
| 42 | + $file = $project->getFiles()[self::FILE]; |
| 43 | + |
| 44 | + $class = $file->getClasses()['\PHP8\UnionTypes']; |
| 45 | + |
| 46 | + self::assertEquals(new Compound([new String_(), new Null_(), new Object_(new Fqsen('\Foo\Date'))]), $class->getMethods()['\PHP8\UnionTypes::union()']->getReturnType()); |
| 47 | + self::assertEquals(new Compound([new Integer(), new False_()]), $class->getMethods()['\PHP8\UnionTypes::union()']->getArguments()[0]->getType()); |
| 48 | + self::assertEquals(new Compound([new String_(), new Null_(), new False_()]), $class->getProperties()['\PHP8\UnionTypes::$property']->getType()); |
| 49 | + } |
| 50 | +} |
0 commit comments