Skip to content

Commit 01e247b

Browse files
authored
Merge pull request #659 from rodrigoprimo/test-coverage-trait-name-suffix
Generic/TraitNameSuffix: improve code coverage
2 parents 4bcd18a + 54cb911 commit 01e247b

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

src/Standards/Generic/Sniffs/NamingConventions/TraitNameSuffixSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function process(File $phpcsFile, $stackPtr)
4040
{
4141
$traitName = $phpcsFile->getDeclarationName($stackPtr);
4242
if ($traitName === null) {
43+
// Live coding or parse error. Bow out.
4344
return;
4445
}
4546

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
trait MissingTraitSuffix {} // Error.
4+
5+
trait GoodTrait {}
6+
7+
trait SuffixCaseIsNotEnforced_tRaIt {}
8+
9+
trait
10+
/*comment*/
11+
AnotherInvalidTraitName {} // 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 trait name).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
trait

src/Standards/Generic/Tests/NamingConventions/TraitNameSuffixUnitTest.inc

Lines changed: 0 additions & 13 deletions
This file was deleted.

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,22 @@ final class TraitNameSuffixUnitTest extends AbstractSniffUnitTest
2525
* The key of the array should represent the line number and the value
2626
* should represent the number of errors that should occur on that line.
2727
*
28+
* @param string $testFile The name of the test file to process.
29+
*
2830
* @return array<int, int>
2931
*/
30-
public function getErrorList()
32+
public function getErrorList($testFile='')
3133
{
32-
return [
33-
3 => 1,
34-
9 => 1,
35-
];
34+
switch ($testFile) {
35+
case 'TraitNameSuffixUnitTest.1.inc':
36+
return [
37+
3 => 1,
38+
9 => 1,
39+
];
40+
41+
default:
42+
return [];
43+
}
3644

3745
}//end getErrorList()
3846

0 commit comments

Comments
 (0)