From 40daecaa80d34442012a709fc65244a14d7eded0 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Thu, 24 Oct 2024 11:51:23 -0300 Subject: [PATCH 1/3] Generic/AbstractClassNamePrefix: rename test case file Doing this to be able to create tests with syntax errors in additional, separate test case files. --- ... => AbstractClassNamePrefixUnitTest.1.inc} | 0 .../AbstractClassNamePrefixUnitTest.php | 23 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) rename src/Standards/Generic/Tests/NamingConventions/{AbstractClassNamePrefixUnitTest.inc => AbstractClassNamePrefixUnitTest.1.inc} (100%) diff --git a/src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.inc b/src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.1.inc similarity index 100% rename from src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.inc rename to src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.1.inc diff --git a/src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.php b/src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.php index 0f7ef0939a..d0c19f96a7 100644 --- a/src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.php +++ b/src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.php @@ -25,17 +25,24 @@ final class AbstractClassNamePrefixUnitTest 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. + * * @return array */ - public function getErrorList() + public function getErrorList($testFile='') { - return [ - 3 => 1, - 13 => 1, - 18 => 1, - 23 => 1, - 42 => 1, - ]; + switch ($testFile) { + case 'AbstractClassNamePrefixUnitTest.1.inc': + return [ + 3 => 1, + 13 => 1, + 18 => 1, + 23 => 1, + 42 => 1, + ]; + default: + return []; + } }//end getErrorList() From e95d79608e7c67a808430dee1e4df2127782ed6c Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Thu, 24 Oct 2024 12:01:55 -0300 Subject: [PATCH 2/3] Generic/AbstractClassNamePrefix: fix up incorrect code comment This sniff only listens to `T_CLASS`. It does not listen to `T_ANON_CLASS`. So the removed code comment is incorrect. The if condition is still valid to bail early when live coding, but it does not ever apply to anonymous classes. --- .../Sniffs/NamingConventions/AbstractClassNamePrefixSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Standards/Generic/Sniffs/NamingConventions/AbstractClassNamePrefixSniff.php b/src/Standards/Generic/Sniffs/NamingConventions/AbstractClassNamePrefixSniff.php index 145dddf746..44c16390e6 100644 --- a/src/Standards/Generic/Sniffs/NamingConventions/AbstractClassNamePrefixSniff.php +++ b/src/Standards/Generic/Sniffs/NamingConventions/AbstractClassNamePrefixSniff.php @@ -45,7 +45,7 @@ public function process(File $phpcsFile, $stackPtr) $className = $phpcsFile->getDeclarationName($stackPtr); if ($className === null) { - // We are not interested in anonymous classes. + // Live coding or parse error. return; } From b80228eec9bc16b8565d75bbfdde925941b2d3d5 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Thu, 24 Oct 2024 14:41:09 -0300 Subject: [PATCH 3/3] 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. --- .../AbstractClassNamePrefixUnitTest.1.inc | 64 ++++++++----------- .../AbstractClassNamePrefixUnitTest.2.inc | 7 ++ .../AbstractClassNamePrefixUnitTest.php | 10 +-- 3 files changed, 38 insertions(+), 43 deletions(-) create mode 100644 src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.2.inc diff --git a/src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.1.inc b/src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.1.inc index 27b9d818da..43ba30c5b9 100644 --- a/src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.1.inc +++ b/src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.1.inc @@ -1,59 +1,45 @@ 1, - 13 => 1, - 18 => 1, - 23 => 1, - 42 => 1, + 7 => 1, + 11 => 1, + 16 => 1, + 29 => 1, + 44 => 1, + 45 => 1, ]; default: return [];