Skip to content

Commit b80228e

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/AbstractClassNamePrefix: improve code coverage and clean up tests
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.
1 parent e95d796 commit b80228e

File tree

3 files changed

+38
-43
lines changed

3 files changed

+38
-43
lines changed
Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,45 @@
11
<?php
22

3-
abstract class IncorrectName // error
4-
{
3+
abstract class IncorrectName {} // Error.
54

6-
}
7-
8-
abstract class AbstractCorrectName
9-
{
10-
11-
}
5+
abstract class AbstractCorrectName {}
126

13-
abstract class IncorrectNameAbstract // error
14-
{
7+
abstract class IncorrectNameAbstract {} // Error.
158

16-
}
17-
18-
abstract class InvalidNameabstract // error
19-
{
20-
21-
}
9+
abstract
10+
/*comment*/
11+
class
12+
InvalidNameabstract
13+
extends
14+
BarClass {} // Error.
2215

23-
abstract class IncorrectAbstractName // error
24-
{
25-
26-
}
16+
abstract class /*comment*/ IncorrectAbstractName {} // Error.
2717

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

30-
class AbstractClassName
31-
{
32-
33-
}
21+
// Make sure that if the class is not abstract, the sniff does not check the name.
22+
class AbstractClassName {}
3423

24+
// Class name is always checked, doesn't matter if the class is declared conditionally.
3525
if (!class_exists('AbstractClassCorrectName')) {
36-
abstract class AbstractClassCorrectName
37-
{
38-
39-
}
26+
abstract class AbstractClassCorrectName {}
4027
}
4128
if (!class_exists('ClassAbstractIncorrectName')) {
42-
abstract class ClassAbstractIncorrectName // error
43-
{
44-
45-
}
29+
abstract class ClassAbstractIncorrectName implements FooInterface {} // Error.
4630
}
4731

48-
$abstractVar = '';
32+
$var = 'abstract class TextStringsAreDisregarded';
33+
34+
class NotAnAbstractClassSoNoPrefixRequired {}
4935

50-
$var = 'abstract class IncorrectNameButOk';
36+
abstract class abstractOkCaseOfPrefixIsNotEnforced {}
5137

52-
$abstracVar = '';
38+
final class FinalClassShouldNotTriggerWarning {}
5339

54-
class NameAbstractBar {}
40+
readonly class ReadonlyClassShouldNotTriggerWarning {}
5541

56-
abstract class abstractOkName
57-
{
42+
abstract readonly class AbstractReadonlyClassWithPrefixShouldNotTriggerWarning {}
5843

59-
}
44+
abstract readonly class ReadonlyAbstractClassShouldTriggerWarningWhenPrefixIsMissingA {} // Error.
45+
readonly abstract class ReadonlyAbstractClassShouldTriggerWarningWhenPrefixIsMissingB {} // Error.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// Intentional parse error (no class name).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
abstract class

src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ public function getErrorList($testFile='')
3535
case 'AbstractClassNamePrefixUnitTest.1.inc':
3636
return [
3737
3 => 1,
38-
13 => 1,
39-
18 => 1,
40-
23 => 1,
41-
42 => 1,
38+
7 => 1,
39+
11 => 1,
40+
16 => 1,
41+
29 => 1,
42+
44 => 1,
43+
45 => 1,
4244
];
4345
default:
4446
return [];

0 commit comments

Comments
 (0)