diff --git a/tests/Sniffs/Classes/ForbiddenPublicPropertySniffTest.php b/tests/Sniffs/Classes/ForbiddenPublicPropertySniffTest.php index cba0619a..4238bfa7 100644 --- a/tests/Sniffs/Classes/ForbiddenPublicPropertySniffTest.php +++ b/tests/Sniffs/Classes/ForbiddenPublicPropertySniffTest.php @@ -7,42 +7,73 @@ class ForbiddenPublicPropertySniffTest extends TestCase { - public function testNoErrors(): void + public function testDefault(): void { - $report = self::checkFile(__DIR__ . '/data/forbiddenPublicPropertyNoErrors.php'); - self::assertNoSniffErrorInFile($report); + $report = self::checkFile(__DIR__ . '/data/forbiddenPublicProperty.php'); + + self::assertSniffError($report, 5, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 6, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); } - public function testErrors(): void + public function testPromoted(): void { - $report = self::checkFile(__DIR__ . '/data/forbiddenPublicPropertyErrors.php'); + $report = self::checkFile(__DIR__ . '/data/forbiddenPublicProperty.php', [ + 'checkPromoted' => true, + ]); - self::assertSame(3, $report->getErrorCount()); + self::assertSniffError($report, 5, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 6, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 10, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + } + + public function testReadonly(): void + { + $report = self::checkFile(__DIR__ . '/data/forbiddenPublicPropertyReadonly.php'); self::assertSniffError($report, 5, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); self::assertSniffError($report, 6, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); self::assertSniffError($report, 7, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 8, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 9, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); } - public function testPromotedNoErrors(): void + public function testReadonlyPromoted(): void { - $report = self::checkFile(__DIR__ . '/data/forbiddenPublicPropertyPromotedNoErrors.php', [ + $report = self::checkFile(__DIR__ . '/data/forbiddenPublicPropertyReadonly.php', [ 'checkPromoted' => true, ]); - self::assertNoSniffErrorInFile($report); + + self::assertSniffError($report, 5, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 6, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 7, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 8, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 9, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 12, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 13, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); } - public function testPromotedErrors(): void + public function testReadonlyAllowed(): void { - $report = self::checkFile(__DIR__ . '/data/forbiddenPublicPropertyPromotedErrors.php', [ - 'checkPromoted' => true, + $report = self::checkFile(__DIR__ . '/data/forbiddenPublicPropertyReadonly.php', [ + 'allowReadonly' => true, ]); - self::assertSame(4, $report->getErrorCount()); + self::assertSniffError($report, 5, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 6, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 9, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + } + + public function testReadonlyAllowedPromoted(): void + { + $report = self::checkFile(__DIR__ . '/data/forbiddenPublicPropertyReadonly.php', [ + 'allowReadonly' => true, + 'checkPromoted' => true, + ]); self::assertSniffError($report, 5, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); - self::assertSniffError($report, 13, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); - self::assertSniffError($report, 14, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 6, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 9, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); + self::assertSniffError($report, 12, ForbiddenPublicPropertySniff::CODE_FORBIDDEN_PUBLIC_PROPERTY); } }