Skip to content

Commit

Permalink
Update ForbiddenPublicPropertySniffTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrommen authored Oct 21, 2024
1 parent 5274309 commit 2e7bd13
Showing 1 changed file with 46 additions and 15 deletions.
61 changes: 46 additions & 15 deletions tests/Sniffs/Classes/ForbiddenPublicPropertySniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 2e7bd13

Please sign in to comment.