Skip to content

Commit

Permalink
Generic/AbstractClassNamePrefix: improve code coverage and clean up t…
Browse files Browse the repository at this point in the history
…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
rodrigoprimo authored and jrfnl committed Oct 25, 2024
1 parent 458ea0c commit 7e7e712
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 43 deletions.
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.
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public function getErrorList($testFile='')
case 'AbstractClassNamePrefixUnitTest.1.inc':
return [
3 => 1,
13 => 1,
18 => 1,
23 => 1,
42 => 1,
7 => 1,
11 => 1,
16 => 1,
29 => 1,
44 => 1,
45 => 1,
];
default:
return [];
Expand Down

0 comments on commit 7e7e712

Please sign in to comment.