Skip to content

Commit

Permalink
Unmatched ignored error for a specific file reported in that file
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 14, 2020
1 parent 7955fb5 commit 3b0c6a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/Analyser/IgnoredErrorHelperResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ public function process(array $errors, bool $onlyFiles, bool $reachedInternalErr
$unmatchedIgnoredError['realCount'] === 1 ? 'time' : 'times'
), $unmatchedIgnoredError['file'], $unmatchedIgnoredError['line'], false);
}
} elseif (isset($unmatchedIgnoredError['realPath'])) {
$errors[] = new Error(
sprintf(
'Ignored error pattern %s was not matched in reported errors.',
IgnoredError::stringifyPattern($unmatchedIgnoredError)
),
$unmatchedIgnoredError['realPath'],
null,
false
);
} elseif (!$onlyFiles) {
$errors[] = sprintf(
'Ignored error pattern %s was not matched in reported errors.',
Expand Down
7 changes: 4 additions & 3 deletions tests/PHPStan/Analyser/AnalyserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ public function testIgnoreErrorByPathAndCountMissing(): void
$this->assertSame(7, $result[2]->getLine());
$this->assertSamePaths(__DIR__ . '/data/two-fails.php', $result[2]->getFile());

$this->assertIsString($result[3]);
$this->assertStringContainsString('Ignored error pattern #Some custom error\.# in path', $result[3]);
$this->assertStringContainsString('was not matched in reported errors.', $result[3]);
$this->assertInstanceOf(Error::class, $result[3]);
$this->assertStringContainsString('Ignored error pattern #Some custom error\.# in path', $result[3]->getMessage());
$this->assertStringContainsString('was not matched in reported errors.', $result[3]->getMessage());
$this->assertSamePaths(__DIR__ . '/data/two-fails.php', $result[2]->getFile());
}

public function testIgnoreErrorByPaths(): void
Expand Down

0 comments on commit 3b0c6a2

Please sign in to comment.