Skip to content

Commit df9143d

Browse files
committed
Added unit test for stringifying ClassString
1 parent d512e9b commit df9143d

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/TypeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ private function resolveCollection(ArrayIterator $tokens, Type $classType, Conte
432432
$isArray = ((string) $classType === 'array');
433433
$isIterable = ((string) $classType === 'iterable');
434434

435-
// allow only "array", "iterable", "class-string" or class name before "<"
435+
// allow only "array", "iterable" or class name before "<"
436436
if (!$isArray && !$isIterable
437437
&& (!$classType instanceof Object_ || $classType->getFqsen() === null)) {
438438
throw new RuntimeException(

tests/unit/Types/ClassStringTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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\Types;
15+
16+
use phpDocumentor\Reflection\Fqsen;
17+
use PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* @coversDefaultClass \phpDocumentor\Reflection\Types\ClassString
21+
*/
22+
class ClassStringTest extends TestCase
23+
{
24+
/**
25+
* @dataProvider provideClassStrings
26+
* @covers ::__toString
27+
*/
28+
public function testClassStringStringifyCorrectly(ClassString $array, string $expectedString) : void
29+
{
30+
$this->assertSame($expectedString, (string) $array);
31+
}
32+
33+
/**
34+
* @return mixed[]
35+
*/
36+
public function provideClassStrings() : array
37+
{
38+
return [
39+
'generic clss string' => [new ClassString(), 'class-string'],
40+
'typed class string' => [new ClassString(new Fqsen('\Foo\Bar')), 'class-string<\Foo\Bar>'],
41+
];
42+
}
43+
}

0 commit comments

Comments
 (0)