Skip to content

Commit

Permalink
Generic/UnnecessaryStringConcat: improve code coverage
Browse files Browse the repository at this point in the history
Also removes `?>` from the end of UnnecessaryStringConcatUnitTest.1.inc
as this token was not relevant for the tests.
  • Loading branch information
rodrigoprimo committed Jul 16, 2024
1 parent e1ad905 commit c323af6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,17 @@ $code = '<'.'?php ';
$string = 'This is a really long string. '
. 'It is being used for errors. '
. 'The message is not translated.';
?>

$shouldBail = 1 + 1;

$shouldNotTrigger = 'My' . /* comment */ 'string';
$shouldNotTrigger = 'My' /* comment */ . 'string';

// phpcs:set Generic.Strings.UnnecessaryStringConcat allowMultiline true
$string = 'Multiline strings are allowed '
. 'when setting is enabled.';
// phpcs:set Generic.Strings.UnnecessaryStringConcat allowMultiline false

// phpcs:set Generic.Strings.UnnecessaryStringConcat error false
$throwWarning = 'My' . 'string';
// phpcs:set Generic.Strings.UnnecessaryStringConcat error true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Intentional parse error (only empty tokens after T_STRING_CONCAT).
// This should be the only test in this file.
// Testing that the sniff is *not* triggered.

$parseError = 'String' .
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,21 @@ public function getErrorList($testFile='')
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @param string $testFile The name of the file being tested.
*
* @return array<int, int>
*/
public function getWarningList()
public function getWarningList($testFile='')
{
return [];
switch ($testFile) {
case 'UnnecessaryStringConcatUnitTest.1.inc':
return [
33 => 1,
];

default:
return [];
}

}//end getWarningList()

Expand Down

0 comments on commit c323af6

Please sign in to comment.