Skip to content

Commit 6272b5e

Browse files
committed
Confirm uniontype support
1 parent 41d0f7c commit 6272b5e

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PHP8;
6+
7+
use Foo\Date;
8+
9+
class UnionTypes
10+
{
11+
private string|null|false $property;
12+
13+
public function union(int|false $test): string|null|Date
14+
{
15+
16+
}
17+
}

0 commit comments

Comments
 (0)