Merge pull request #3199 from rectorphp/exception-annotation

[PHPUnit] Fix ExceptionAnnotationRector for null phpdoc
This commit is contained in:
Tomas Votruba 2020-04-20 09:47:05 +02:00 committed by GitHub
commit cc40d00c7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -83,8 +83,11 @@ PHP
return null;
}
/** @var PhpDocInfo $phpDocInfo */
/** @var PhpDocInfo|null $phpDocInfo */
$phpDocInfo = $node->getAttribute(AttributeKey::PHP_DOC_INFO);
if ($phpDocInfo === null) {
return null;
}
foreach (self::ANNOTATION_TO_METHOD as $annotation => $method) {
if (! $phpDocInfo->hasByName($annotation)) {

View File

@ -0,0 +1,21 @@
<?php
namespace Rector\PHPUnit\Tests\Rector\ExceptionAnnotationRector\Fixture;
use PHPUnit\Framework\TestCase;
class SkipMethodWithNullPhpDoc extends TestCase
{
public function testLiteralMessage(): void
{
$this->expectException('Exception');
throw new \Exception('A literal exception message');
}
// test
public function testPartialMessageBegin(): void
{
throw new \Exception('A partial exception message');
}
}