Skip to content

Commit

Permalink
Refactor detection of phpdocumentor V5
Browse files Browse the repository at this point in the history
`InvalidTag` was only introduced in phpdocumentor 5.0.0-alpha8, so fall
back to detecting return type hints added already in alpha1...
  • Loading branch information
DerManoMann committed Jun 12, 2020
1 parent a9eb0d7 commit 03a9614
Showing 1 changed file with 14 additions and 7 deletions.
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\PropertyInfo\Tests\Extractor;

use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
use phpDocumentor\Reflection\Types\Collection;
use PHPUnit\Framework\TestCase;
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
Expand Down Expand Up @@ -46,15 +47,23 @@ public function testParamTagTypeIsOmitted()
$this->assertNull($this->extractor->getTypes(OmittedParamTagTypeDocBlock::class, 'omittedType'));
}

public function invalidTypesProvider()
protected function isPhpDocumentorV5()
{
$phpDocumentorV5 = class_exists('\phpDocumentor\Reflection\DocBlock\Tags\InvalidTag');
if (class_exists('\phpDocumentor\Reflection\DocBlock\Tags\InvalidTag')) {
return true;
}

return (new \ReflectionMethod(StandardTagFactory::class, 'create'))
->hasReturnType();
}

public function invalidTypesProvider()
{
return [
'pub' => ['pub', null, null],
'stat' => ['stat', null, null],
'foo' => ['foo', $phpDocumentorV5 ? 'Foo.' : null, null],
'bar' => ['bar', $phpDocumentorV5 ? 'Bar.' : null, null],
'foo' => ['foo', $this->isPhpDocumentorV5() ? 'Foo.' : null, null],
'bar' => ['bar', $this->isPhpDocumentorV5() ? 'Bar.' : null, null],
];
}

Expand All @@ -80,8 +89,6 @@ public function testExtractTypesWithNoPrefixes($property, array $type = null)

public function typesProvider()
{
$phpDocumentorV5 = class_exists('\phpDocumentor\Reflection\DocBlock\Tags\InvalidTag');

return [
['foo', null, 'Short description.', 'Long description.'],
['bar', [new Type(Type::BUILTIN_TYPE_STRING)], 'This is bar', null],
Expand Down Expand Up @@ -118,7 +125,7 @@ public function typesProvider()
['donotexist', null, null, null],
['staticGetter', null, null, null],
['staticSetter', null, null, null],
['emptyVar', null, $phpDocumentorV5 ? 'This should not be removed.' : null, null],
['emptyVar', null, $this->isPhpDocumentorV5() ? 'This should not be removed.' : null, null],
];
}

Expand Down

0 comments on commit 03a9614

Please sign in to comment.