-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generic/AbstractClassNamePrefix: improve code coverage and clean up t…
…ests Test improvements: * Adjust some existing tests to have comments and new lines in unexpected places. * Adjust some existing tests to include extended classes and implemented interfaces. * Add tests with `final` and `readonly` class modifier keywords. * Make some tests more descriptive by making the class name reflect what is being tested. * Add a few comments to pre-existing tests to clarify why they exist. * Add a separate test case file with a live coding/parse error test. * Remove some code snippets which weren't testing anything. Clean up the test file: * Remove redundant whitespace in the test case file. * Use proper punctuation in comments in test case file.
- Loading branch information
1 parent
458ea0c
commit 7e7e712
Showing
3 changed files
with
38 additions
and
43 deletions.
There are no files selected for viewing
64 changes: 25 additions & 39 deletions
64
src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.1.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,45 @@ | ||
<?php | ||
|
||
abstract class IncorrectName // error | ||
{ | ||
abstract class IncorrectName {} // Error. | ||
|
||
} | ||
|
||
abstract class AbstractCorrectName | ||
{ | ||
|
||
} | ||
abstract class AbstractCorrectName {} | ||
|
||
abstract class IncorrectNameAbstract // error | ||
{ | ||
abstract class IncorrectNameAbstract {} // Error. | ||
|
||
} | ||
|
||
abstract class InvalidNameabstract // error | ||
{ | ||
|
||
} | ||
abstract | ||
/*comment*/ | ||
class | ||
InvalidNameabstract | ||
extends | ||
BarClass {} // Error. | ||
|
||
abstract class IncorrectAbstractName // 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 implements FooInterface {} // Error. | ||
} | ||
|
||
$abstractVar = ''; | ||
$var = 'abstract class TextStringsAreDisregarded'; | ||
|
||
class NotAnAbstractClassSoNoPrefixRequired {} | ||
|
||
$var = 'abstract class IncorrectNameButOk'; | ||
abstract class abstractOkCaseOfPrefixIsNotEnforced {} | ||
|
||
$abstracVar = ''; | ||
final class FinalClassShouldNotTriggerWarning {} | ||
|
||
class NameAbstractBar {} | ||
readonly class ReadonlyClassShouldNotTriggerWarning {} | ||
|
||
abstract class abstractOkName | ||
{ | ||
abstract readonly class AbstractReadonlyClassWithPrefixShouldNotTriggerWarning {} | ||
|
||
} | ||
abstract readonly class ReadonlyAbstractClassShouldTriggerWarningWhenPrefixIsMissingA {} // Error. | ||
readonly abstract class ReadonlyAbstractClassShouldTriggerWarningWhenPrefixIsMissingB {} // Error. |
7 changes: 7 additions & 0 deletions
7
src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.2.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
// Intentional parse error (no class name). | ||
// This should be the only test in this file. | ||
// Testing that the sniff is *not* triggered. | ||
|
||
abstract class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters