Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic/TraitNameSuffix: improve code coverage #659

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function process(File $phpcsFile, $stackPtr)
{
$traitName = $phpcsFile->getDeclarationName($stackPtr);
if ($traitName === null) {
// Live coding or parse error. Bow out.
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

trait MissingTraitSuffix {} // Error.

trait GoodTrait {}

trait SuffixCaseIsNotEnforced_tRaIt {}

trait
/*comment*/
AnotherInvalidTraitName {} // Error.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Intentional parse error (no trait name).
// This should be the only test in this file.
// Testing that the sniff is *not* triggered.

trait

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ final class TraitNameSuffixUnitTest extends AbstractSniffUnitTest
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @param string $testFile The name of the test file to process.
*
* @return array<int, int>
*/
public function getErrorList()
public function getErrorList($testFile='')
{
return [
3 => 1,
9 => 1,
];
switch ($testFile) {
case 'TraitNameSuffixUnitTest.1.inc':
return [
3 => 1,
9 => 1,
];

default:
return [];
}

}//end getErrorList()

Expand Down