From 2e7bd13b074f09fc42b6eb7618afa8ea8f9efc3d Mon Sep 17 00:00:00 2001 From: Thorsten Frommen Date: Mon, 21 Oct 2024 22:02:05 +0200 Subject: [PATCH] Update ForbiddenPublicPropertySniffTest.php --- .../ForbiddenPublicPropertySniffTest.php | 61 ++++++++++++++----- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/tests/Sniffs/Classes/ForbiddenPublicPropertySniffTest.php b/tests/Sniffs/Classes/ForbiddenPublicPropertySniffTest.php index cba0619a1..4238bfa74 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); } }