From d1664db21cc0a4a9702e8629abd3e92bef85636a Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Fri, 10 May 2024 11:32:59 -0300 Subject: [PATCH 1/2] Generic/SpaceAfterCast: rename test case file Doing this to be able to create tests with syntax errors on separate files. --- ...tTest.inc => SpaceAfterCastUnitTest.1.inc} | 0 ...xed => SpaceAfterCastUnitTest.1.inc.fixed} | 0 .../Formatting/SpaceAfterCastUnitTest.php | 90 ++++++++++--------- 3 files changed, 49 insertions(+), 41 deletions(-) rename src/Standards/Generic/Tests/Formatting/{SpaceAfterCastUnitTest.inc => SpaceAfterCastUnitTest.1.inc} (100%) rename src/Standards/Generic/Tests/Formatting/{SpaceAfterCastUnitTest.inc.fixed => SpaceAfterCastUnitTest.1.inc.fixed} (100%) diff --git a/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.inc b/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.1.inc similarity index 100% rename from src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.inc rename to src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.1.inc diff --git a/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.inc.fixed b/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.1.inc.fixed similarity index 100% rename from src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.inc.fixed rename to src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.1.inc.fixed diff --git a/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.php b/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.php index 36e444b647..6025a147fb 100644 --- a/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.php +++ b/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.php @@ -26,50 +26,58 @@ final class SpaceAfterCastUnitTest 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 run. + * * @return array */ - public function getErrorList() + public function getErrorList($testFile='') { - return [ - 4 => 1, - 5 => 1, - 8 => 1, - 9 => 1, - 12 => 1, - 13 => 1, - 16 => 1, - 17 => 1, - 20 => 1, - 21 => 1, - 24 => 1, - 25 => 1, - 28 => 1, - 29 => 1, - 32 => 1, - 33 => 1, - 36 => 1, - 37 => 1, - 40 => 1, - 41 => 1, - 44 => 1, - 45 => 1, - 51 => 1, - 53 => 1, - 55 => 1, - 58 => 1, - 64 => 1, - 72 => 1, - 73 => 1, - 75 => 1, - 76 => 1, - 78 => 1, - 82 => 1, - 84 => 1, - 85 => 1, - 86 => 1, - 88 => 1, - 93 => 1, - ]; + switch ($testFile) { + case 'SpaceAfterCastUnitTest.1.inc': + return [ + 4 => 1, + 5 => 1, + 8 => 1, + 9 => 1, + 12 => 1, + 13 => 1, + 16 => 1, + 17 => 1, + 20 => 1, + 21 => 1, + 24 => 1, + 25 => 1, + 28 => 1, + 29 => 1, + 32 => 1, + 33 => 1, + 36 => 1, + 37 => 1, + 40 => 1, + 41 => 1, + 44 => 1, + 45 => 1, + 51 => 1, + 53 => 1, + 55 => 1, + 58 => 1, + 64 => 1, + 72 => 1, + 73 => 1, + 75 => 1, + 76 => 1, + 78 => 1, + 82 => 1, + 84 => 1, + 85 => 1, + 86 => 1, + 88 => 1, + 93 => 1, + ]; + + default: + return []; + }//end switch }//end getErrorList() From 16ca5073a5bdbb2434e9ee5a1bd04a0798cd17c4 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Fri, 10 May 2024 12:07:22 -0300 Subject: [PATCH 2/2] Generic/SpaceAfterCast: improve code coverage --- .../Formatting/SpaceAfterCastUnitTest.1.inc | 5 ++ .../SpaceAfterCastUnitTest.1.inc.fixed | 5 ++ .../Formatting/SpaceAfterCastUnitTest.2.inc | 3 + .../Formatting/SpaceAfterCastUnitTest.php | 79 ++++++++++--------- 4 files changed, 54 insertions(+), 38 deletions(-) create mode 100644 src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.2.inc diff --git a/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.1.inc b/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.1.inc index 70ecd98a12..a4b0a07f9d 100644 --- a/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.1.inc +++ b/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.1.inc @@ -93,3 +93,8 @@ $var = (int) $var1 + (bool) $var2; // phpcs:set Generic.Formatting.SpaceAfterCast ignoreNewlines false // phpcs:set Generic.Formatting.SpaceAfterCast spacing 1 + +$var = (boolean)/* comment */ $var2; + +$var = ( int )$spacesInsideParenthesis; +$var = ( int )$tabsInsideParenthesis; diff --git a/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.1.inc.fixed b/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.1.inc.fixed index f9b2a592aa..fd2b920dcb 100644 --- a/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.1.inc.fixed +++ b/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.1.inc.fixed @@ -90,3 +90,8 @@ $var = (int) $var1 + (bool)$var2; // phpcs:set Generic.Formatting.SpaceAfterCast ignoreNewlines false // phpcs:set Generic.Formatting.SpaceAfterCast spacing 1 + +$var = (boolean)/* comment */ $var2; + +$var = ( int ) $spacesInsideParenthesis; +$var = ( int ) $tabsInsideParenthesis; diff --git a/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.2.inc b/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.2.inc new file mode 100644 index 0000000000..7e947a2645 --- /dev/null +++ b/src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.2.inc @@ -0,0 +1,3 @@ + 1, - 5 => 1, - 8 => 1, - 9 => 1, - 12 => 1, - 13 => 1, - 16 => 1, - 17 => 1, - 20 => 1, - 21 => 1, - 24 => 1, - 25 => 1, - 28 => 1, - 29 => 1, - 32 => 1, - 33 => 1, - 36 => 1, - 37 => 1, - 40 => 1, - 41 => 1, - 44 => 1, - 45 => 1, - 51 => 1, - 53 => 1, - 55 => 1, - 58 => 1, - 64 => 1, - 72 => 1, - 73 => 1, - 75 => 1, - 76 => 1, - 78 => 1, - 82 => 1, - 84 => 1, - 85 => 1, - 86 => 1, - 88 => 1, - 93 => 1, + 4 => 1, + 5 => 1, + 8 => 1, + 9 => 1, + 12 => 1, + 13 => 1, + 16 => 1, + 17 => 1, + 20 => 1, + 21 => 1, + 24 => 1, + 25 => 1, + 28 => 1, + 29 => 1, + 32 => 1, + 33 => 1, + 36 => 1, + 37 => 1, + 40 => 1, + 41 => 1, + 44 => 1, + 45 => 1, + 51 => 1, + 53 => 1, + 55 => 1, + 58 => 1, + 64 => 1, + 72 => 1, + 73 => 1, + 75 => 1, + 76 => 1, + 78 => 1, + 82 => 1, + 84 => 1, + 85 => 1, + 86 => 1, + 88 => 1, + 93 => 1, + 97 => 1, + 99 => 1, + 100 => 1, ]; default: