Skip to content

Commit 5502f07

Browse files
committed
Add simple test
1 parent 2eaa920 commit 5502f07

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace DisallowDivisionByLiteralZeroRule;
4+
5+
function testExtraError(): void
6+
{
7+
$a = 10;
8+
$invalidDivision = $a / 0;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace DisallowDivisionByLiteralZeroRule;
4+
5+
function testMissingError(): void
6+
{
7+
$a = 10;
8+
$validDivision = $a / 2; // error: Division by literal zero is not allowed
9+
}

tests/RuleTestCaseTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,30 @@ public function testAutofix(): void
5353
self::assertFileEquals($expectedFile, $tmpFile);
5454
}
5555

56+
public function testErrorMessageWithExtraError(): void
57+
{
58+
$testFile = __DIR__ . '/Rule/Data/DisallowDivisionByLiteralZeroRule/extra-error.php';
59+
60+
try {
61+
$this->analyzeFiles([$testFile]);
62+
self::fail('Expected assertion to fail due to extra error');
63+
} catch (AssertionFailedError $e) { // @phpstan-ignore catch.internalClass
64+
self::assertStringContainsString('New errors reported:', $e->getMessage());
65+
self::assertStringContainsString('Division by literal zero is not allowed', $e->getMessage());
66+
}
67+
}
68+
69+
public function testErrorMessageWithMissingError(): void
70+
{
71+
$testFile = __DIR__ . '/Rule/Data/DisallowDivisionByLiteralZeroRule/missing-error.php';
72+
73+
try {
74+
$this->analyzeFiles([$testFile]);
75+
self::fail('Expected assertion to fail due to missing error');
76+
} catch (AssertionFailedError $e) { // @phpstan-ignore catch.internalClass
77+
self::assertStringContainsString('Errors not reported:', $e->getMessage());
78+
self::assertStringContainsString('Division by literal zero is not allowed', $e->getMessage());
79+
}
80+
}
81+
5682
}

0 commit comments

Comments
 (0)