Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrommen committed Oct 21, 2024
1 parent 3338978 commit d17390b
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 70 deletions.
52 changes: 36 additions & 16 deletions tests/Sniffs/Classes/ForbiddenPublicPropertySniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,62 @@
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 testReadonly(): void
{
$report = self::checkFile(__DIR__ . '/data/forbiddenPublicPropertyErrors.php');

self::assertSame(3, $report->getErrorCount());
$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);
}

}
15 changes: 15 additions & 0 deletions tests/Sniffs/Classes/data/forbiddenPublicProperty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

class Test
{
var $var;
public $pub;
protected $prot;
private $priv;
}

class TestSniff
{
var $var;
public $pub;
}
8 changes: 0 additions & 8 deletions tests/Sniffs/Classes/data/forbiddenPublicPropertyErrors.php

This file was deleted.

20 changes: 0 additions & 20 deletions tests/Sniffs/Classes/data/forbiddenPublicPropertyNoErrors.php

This file was deleted.

This file was deleted.

This file was deleted.

24 changes: 24 additions & 0 deletions tests/Sniffs/Classes/data/forbiddenPublicPropertyReadonly.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php // lint >= 8.1

class Test
{
var $var;
public $pub;
readonly public string $rps;
public readonly string $prs;
public $pub2;

public function __construct(
public int $promoted1,
readonly public string $promoted2
)
{
}
}

class Test2
{
public function __construct(protected int $promoted1, readonly private string $promoted2)
{
}
}

0 comments on commit d17390b

Please sign in to comment.