mirror of
https://github.com/danog/psalm-plugin-phpunit.git
synced 2024-11-27 04:24:50 +01:00
Merge pull request #37 from weirdan/dont-crash-on-invalid-docblock
Don't crash on invalid docblocks
This commit is contained in:
commit
2215d64562
@ -7,6 +7,7 @@ use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Psalm\CodeLocation;
|
||||
use Psalm\Codebase;
|
||||
use Psalm\DocComment;
|
||||
use Psalm\Exception\DocblockParseException;
|
||||
use Psalm\FileSource;
|
||||
use Psalm\IssueBuffer;
|
||||
use Psalm\Issue;
|
||||
@ -528,7 +529,11 @@ class TestCaseHandler implements
|
||||
$docblock = $method->getDocComment();
|
||||
|
||||
if ($docblock) {
|
||||
try {
|
||||
$parsed_comment = DocComment::parse((string)$docblock->getReformattedText(), $docblock->getLine());
|
||||
} catch (DocblockParseException $e) {
|
||||
return [];
|
||||
}
|
||||
if (isset($parsed_comment['specials'])) {
|
||||
return $parsed_comment['specials'];
|
||||
}
|
||||
|
@ -1003,3 +1003,48 @@ Feature: TestCase
|
||||
"""
|
||||
When I run Psalm with dead code detection
|
||||
Then I see no errors
|
||||
|
||||
Scenario: Invalid psalm annotation on a class does not crash psalm
|
||||
Given I have the following code
|
||||
"""
|
||||
/** @psalm-ignore Everything */
|
||||
class MyTestCase extends TestCase {}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see these errors
|
||||
| Type | Message |
|
||||
| InvalidDocblock | %@psalm-ignore% |
|
||||
|
||||
Scenario: Invalid psalm annotation on an before initializer does not crash psalm
|
||||
Given I have the following code
|
||||
"""
|
||||
class MyTestCase extends TestCase {
|
||||
/**
|
||||
* @before
|
||||
* @psalm-rm-Rf-slash
|
||||
* @return void
|
||||
*/
|
||||
public function preparation() {}
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see these errors
|
||||
| Type | Message |
|
||||
| InvalidDocblock | %@psalm-rm-Rf-slash% |
|
||||
|
||||
Scenario: Invalid psalm annotation on a test does not crash psalm
|
||||
Given I have the following code
|
||||
"""
|
||||
class MyTestCase extends TestCase {
|
||||
/**
|
||||
* @test
|
||||
* @psalm-force-push-master
|
||||
* @return void
|
||||
*/
|
||||
public function doThings() {}
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see these errors
|
||||
| Type | Message |
|
||||
| InvalidDocblock | %@psalm-force-push-master% |
|
||||
|
Loading…
Reference in New Issue
Block a user