Skip to content

Commit

Permalink
AnalyserTest - test matched and unmatched errors separately
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 8, 2024
1 parent 9dac90d commit c370cbf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
28 changes: 15 additions & 13 deletions tests/PHPStan/Analyser/AnalyserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,30 +465,32 @@ public function testDoNotReportUnmatchedIgnoredErrorsFromPathWithCountIfPathWasN
$this->assertNoErrors($result);
}

/**
* @dataProvider dataTrueAndFalse
*/
public function testIgnoreNextLine(bool $reportUnmatchedIgnoredErrors): void
public function testIgnoreNextLine(): void
{
$result = $this->runAnalyser([], $reportUnmatchedIgnoredErrors, [
$result = $this->runAnalyser([], true, [
__DIR__ . '/data/ignore-next-line.php',
], true);
$this->assertCount($reportUnmatchedIgnoredErrors ? 4 : 3, $result);
$this->assertCount(3, $result);
foreach ([10, 20, 24] as $i => $line) {
$this->assertArrayHasKey($i, $result);
$this->assertInstanceOf(Error::class, $result[$i]);
$this->assertSame('Fail.', $result[$i]->getMessage());
$this->assertSame($line, $result[$i]->getLine());
}
}

if (!$reportUnmatchedIgnoredErrors) {
return;
public function testIgnoreNextLineUnmatched(): void
{
$result = $this->runAnalyser([], true, [
__DIR__ . '/data/ignore-next-line-unmatched.php',
], true);
$this->assertCount(1, $result);
foreach ([11] as $i => $line) {
$this->assertArrayHasKey($i, $result);
$this->assertInstanceOf(Error::class, $result[$i]);
$this->assertStringContainsString('No error to ignore is reported on line', $result[$i]->getMessage());
$this->assertSame($line, $result[$i]->getLine());
}

$this->assertArrayHasKey(3, $result);
$this->assertInstanceOf(Error::class, $result[3]);
$this->assertSame('No error to ignore is reported on line 28.', $result[3]->getMessage());
$this->assertSame(28, $result[3]->getLine());
}

public function testIgnoreNextLineLegacyBehaviour(): void
Expand Down
14 changes: 14 additions & 0 deletions tests/PHPStan/Analyser/data/ignore-next-line-unmatched.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace IgnoreNextLineUnmatched;

class Foo
{

public function doFoo(): void
{
/** @phpstan-ignore-next-line */
succ(); // reported as unmatched
}

}
3 changes: 0 additions & 3 deletions tests/PHPStan/Analyser/data/ignore-next-line.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public function doFoo(): void
if (fail()) {
fail(); // reported
}

/** @phpstan-ignore-next-line */
succ(); // reported as unmatched
}

}

0 comments on commit c370cbf

Please sign in to comment.