File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed
Rule/Data/DisallowDivisionByLiteralZeroRule Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace DisallowDivisionByLiteralZeroRule ;
4+
5+ function testExtraError (): void
6+ {
7+ $ a = 10 ;
8+ $ invalidDivision = $ a / 0 ;
9+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments