1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
<?php
declare(strict_types=1);
namespace phpDocumentor\Reflection\PseudoTypes;
use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\Object_;
use phpDocumentor\Reflection\Types\String_;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
final class GenericTest extends TestCase
{
public function testCreate(): void
{
$fqsen = new Fqsen('\\Foo\\Bar');
$types = [new Object_(new Fqsen('\\Foo\\SomeClass')), new List_(new Integer())];
$type = new Generic($fqsen, $types);
$this->assertSame($fqsen, $type->getFqsen());
$this->assertSame($types, $type->getTypes());
}
#[DataProvider('provideToStringData')]
public function testToString(string $expectedResult, Generic $type): void
{
$this->assertSame($expectedResult, (string) $type);
}
/**
* @return array<string, array{string, Generic}>
*/
public static function provideToStringData(): array
{
return [
'without fqsen' => [
'object<string>',
new Generic(
null,
[
new String_(),
]
),
],
'collection without key' => [
'\\ArrayObject<string>',
new Generic(new Fqsen('\\ArrayObject'), [new String_()]),
],
'collection with key' => [
'\\ArrayObject<string[], \\Iterator>',
new Generic(
new Fqsen('\\ArrayObject'),
[new Array_(new String_()), new Object_(new Fqsen('\\Iterator'))]
),
],
'more than two generics' => [
'\\MyClass<\\T, \\SomeClassSecond, \\SomeClassThird>',
new Generic(
new Fqsen('\\MyClass'),
[
new Object_(new Fqsen('\\T')),
new Object_(new Fqsen('\\SomeClassSecond')),
new Object_(new Fqsen('\\SomeClassThird')),
]
),
],
];
}
}
|