Skip to content

Commit 0d033ff

Browse files
committed
Make 100% test coverage for PseudoTypes
1 parent baf8970 commit 0d033ff

34 files changed

+790
-27
lines changed

tests/unit/PseudoTypes/ArrayKeyTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@
1313

1414
namespace phpDocumentor\Reflection\PseudoTypes;
1515

16+
use phpDocumentor\Reflection\Types\Compound;
1617
use phpDocumentor\Reflection\Types\Integer;
1718
use phpDocumentor\Reflection\Types\String_;
1819
use PHPUnit\Framework\TestCase;
1920

2021
final class ArrayKeyTest extends TestCase
2122
{
22-
public function testArrayKeyCanBeConstructedAndStringifiedCorrectly(): void
23+
public function testCreate(): void
24+
{
25+
$type = new ArrayKey();
26+
27+
$this->assertEquals(new Compound([new String_(), new Integer()]), $type->underlyingType());
28+
}
29+
30+
public function testToString(): void
2331
{
2432
$this->assertSame('array-key', (string) (new ArrayKey()));
2533
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 PHPUnit\Framework\TestCase;
17+
18+
class ArrayShapeItemTest extends TestCase
19+
{
20+
public function testCreate(): void
21+
{
22+
$key = 'abc';
23+
$value = new IntegerValue(100);
24+
$item = new ArrayShapeItem($key, $value, true);
25+
26+
$this->assertSame($key, $item->getKey());
27+
$this->assertSame($value, $item->getValue());
28+
$this->assertTrue($item->isOptional());
29+
}
30+
}

tests/unit/PseudoTypes/ArrayShapeTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44

55
namespace phpDocumentor\Reflection\PseudoTypes;
66

7+
use phpDocumentor\Reflection\Types\Array_;
8+
use phpDocumentor\Reflection\Types\Mixed_;
79
use PHPUnit\Framework\TestCase;
810

911
class ArrayShapeTest extends TestCase
1012
{
11-
public function testExposeItems(): void
13+
public function testCreate(): void
1214
{
1315
$item1 = new ArrayShapeItem('foo', new True_(), false);
1416
$item2 = new ArrayShapeItem('bar', new False_(), true);
1517

1618
$arrayShape = new ArrayShape($item1, $item2);
1719

1820
$this->assertSame([$item1, $item2], $arrayShape->getItems());
21+
$this->assertEquals(new Array_(new Mixed_(), new ArrayKey()), $arrayShape->underlyingType());
1922
}
2023

2124
/**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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\Types\String_;
17+
use PHPUnit\Framework\TestCase;
18+
19+
class CallableStringTest extends TestCase
20+
{
21+
public function testCreate(): void
22+
{
23+
$type = new CallableString();
24+
25+
$this->assertEquals(new String_(), $type->underlyingType());
26+
}
27+
28+
public function testToString(): void
29+
{
30+
$this->assertSame('callable-string', (string) (new CallableString()));
31+
}
32+
}

tests/unit/PseudoTypes/ClassStringTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,32 @@
1616
use phpDocumentor\Reflection\Fqsen;
1717
use phpDocumentor\Reflection\Types\Compound;
1818
use phpDocumentor\Reflection\Types\Object_;
19+
use phpDocumentor\Reflection\Types\String_;
1920
use PHPUnit\Framework\TestCase;
2021

2122
class ClassStringTest extends TestCase
2223
{
24+
public function testCreate(): void
25+
{
26+
$genericType = new Object_(new Fqsen('\Foo\Bar'));
27+
$type = new ClassString($genericType);
28+
29+
$this->assertSame($genericType, $type->getGenericType());
30+
$this->assertEquals(new String_(), $type->underlyingType());
31+
}
32+
2333
/**
24-
* @dataProvider provideClassStrings
34+
* @dataProvider provideToStringData
2535
*/
26-
public function testClassStringStringifyCorrectly(ClassString $type, string $expectedString): void
36+
public function testToString(ClassString $type, string $expectedString): void
2737
{
2838
$this->assertSame($expectedString, (string) $type);
2939
}
3040

3141
/**
3242
* @return array<string, array{ClassString, string}>
3343
*/
34-
public function provideClassStrings(): array
44+
public function provideToStringData(): array
3545
{
3646
return [
3747
'generic class string' => [new ClassString(), 'class-string'],

tests/unit/PseudoTypes/ConditionalForParameterTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use phpDocumentor\Reflection\Types\Array_;
88
use phpDocumentor\Reflection\Types\Integer;
9+
use phpDocumentor\Reflection\Types\Mixed_;
910
use phpDocumentor\Reflection\Types\Static_;
1011
use PHPUnit\Framework\TestCase;
1112

@@ -24,6 +25,7 @@ public function testCreate(): void
2425
$this->assertSame($targetType, $type->getTargetType());
2526
$this->assertSame($if, $type->getIf());
2627
$this->assertSame($else, $type->getElse());
28+
$this->assertEquals(new Mixed_(), $type->underlyingType());
2729
}
2830

2931
/**

tests/unit/PseudoTypes/ConditionalTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use phpDocumentor\Reflection\Fqsen;
88
use phpDocumentor\Reflection\Types\Array_;
99
use phpDocumentor\Reflection\Types\Integer;
10+
use phpDocumentor\Reflection\Types\Mixed_;
1011
use phpDocumentor\Reflection\Types\Object_;
1112
use phpDocumentor\Reflection\Types\Static_;
1213
use PHPUnit\Framework\TestCase;
@@ -26,6 +27,7 @@ public function testCreate(): void
2627
$this->assertSame($targetType, $type->getTargetType());
2728
$this->assertSame($if, $type->getIf());
2829
$this->assertSame($else, $type->getElse());
30+
$this->assertEquals(new Mixed_(), $type->underlyingType());
2931
}
3032

3133
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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\Mixed_;
18+
use phpDocumentor\Reflection\Types\Object_;
19+
use PHPUnit\Framework\TestCase;
20+
21+
class ConstExpressionTest extends TestCase
22+
{
23+
public function testCreate(): void
24+
{
25+
$owner = new Object_(new Fqsen('\Foo\Bar'));
26+
$expression = '*';
27+
$type = new ConstExpression($owner, $expression);
28+
29+
$this->assertSame($owner, $type->getOwner());
30+
$this->assertSame($expression, $type->getExpression());
31+
$this->assertEquals(new Mixed_(), $type->underlyingType());
32+
}
33+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\Types\Float_;
17+
use PHPUnit\Framework\TestCase;
18+
19+
class FloatValueTest extends TestCase
20+
{
21+
public function testCreate(): void
22+
{
23+
$value = 12.12;
24+
$type = new FloatValue($value);
25+
26+
$this->assertSame($value, $type->getValue());
27+
$this->assertEquals(new Float_(), $type->underlyingType());
28+
}
29+
30+
public function testToString(): void
31+
{
32+
$this->assertSame('12.12', (string) (new FloatValue(12.12)));
33+
}
34+
}

0 commit comments

Comments
 (0)