Skip to content

Commit

Permalink
Generic/AbstractClassNamePrefix: improve the tests further
Browse files Browse the repository at this point in the history
* Remove redundant whitespace in the test case file.
* Adjust some existing tests to have comments and new lines in unexpected places.
* Add a few comments to pre-existing tests to clarify why they exist.
* Add extra test with `abstract readonly` class but with keywords in reverse order.
* Annotate two new tests with `// Error.` to be consistent with the rest of the tests in the file.
  • Loading branch information
jrfnl committed Oct 25, 2024
1 parent f7c0266 commit 82bb018
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,63 +1,43 @@
<?php

abstract class IncorrectName // Error.
{
abstract class IncorrectName {} // Error.

}

abstract class AbstractCorrectName
{

}

abstract class IncorrectNameAbstract // Error.
{

}

abstract class InvalidNameabstract // Error.
{
abstract class AbstractCorrectName {}

}
abstract class IncorrectNameAbstract {} // Error.

abstract class IncorrectAbstractName // Error.
{
abstract
/*comment*/
class
InvalidNameabstract {} // Error.

}
abstract class /*comment*/ IncorrectAbstractName {} // Error.

// Anonymous classes can't be declared as abstract (and don't have a name anyhow).
$anon = new class {};

class AbstractClassName
{

}
// Make sure that if the class is not abstract, the sniff does not check the name.
class AbstractClassName {}

// Class name is always checked, doesn't matter if the class is declared conditionally.
if (!class_exists('AbstractClassCorrectName')) {
abstract class AbstractClassCorrectName
{

}
abstract class AbstractClassCorrectName {}
}
if (!class_exists('ClassAbstractIncorrectName')) {
abstract class ClassAbstractIncorrectName // Error.
{

}
abstract class ClassAbstractIncorrectName {} // Error.
}

$var = 'abstract class TextStringsAreDisregarded';

class NotAnAbstractClassSoNoPrefixRequired {}

abstract class abstractOkCaseOfPrefixIsNotEnforced
{

}
abstract class abstractOkCaseOfPrefixIsNotEnforced {}

final class FinalClassShouldNotTriggerWarning {}

readonly class ReadonlyClassShouldNotTriggerWarning {}

abstract readonly class AbstractReadonlyClassWithPrefixShouldNotTriggerWarning {}

abstract readonly class ReadonlyAbstractClassShouldTriggerWarningWhenPrefixIsMissing {}
abstract readonly class ReadonlyAbstractClassShouldTriggerWarningWhenPrefixIsMissingA {} // Error.
readonly abstract class ReadonlyAbstractClassShouldTriggerWarningWhenPrefixIsMissingB {} // Error.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ public function getErrorList($testFile='')
case 'AbstractClassNamePrefixUnitTest.1.inc':
return [
3 => 1,
13 => 1,
18 => 1,
23 => 1,
7 => 1,
11 => 1,
14 => 1,
27 => 1,
42 => 1,
63 => 1,
43 => 1,
];
default:
return [];
Expand Down

0 comments on commit 82bb018

Please sign in to comment.