Skip to content

Commit d555c4f

Browse files
committed
Generic/UnnecessaryStringConcat: improve code coverage
Also removes `?>` from the end of UnnecessaryStringConcatUnitTest.1.inc as this token was not relevant for the tests.
1 parent a3e4b50 commit d555c4f

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/Standards/Generic/Tests/Strings/UnnecessaryStringConcatUnitTest.1.inc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,17 @@ $code = '<'.'?php ';
1818
$string = 'This is a really long string. '
1919
. 'It is being used for errors. '
2020
. 'The message is not translated.';
21-
?>
21+
22+
$shouldBail = 1 + 1;
23+
24+
$shouldNotTrigger = 'My' . /* comment */ 'string';
25+
$shouldNotTrigger = 'My' /* comment */ . 'string';
26+
27+
// phpcs:set Generic.Strings.UnnecessaryStringConcat allowMultiline true
28+
$string = 'Multiline strings are allowed '
29+
. 'when setting is enabled.';
30+
// phpcs:set Generic.Strings.UnnecessaryStringConcat allowMultiline false
31+
32+
// phpcs:set Generic.Strings.UnnecessaryStringConcat error false
33+
$throwWarning = 'My' . 'string';
34+
// phpcs:set Generic.Strings.UnnecessaryStringConcat error true
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 (only empty tokens after T_STRING_CONCAT).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
$parseError = 'String' .

src/Standards/Generic/Tests/Strings/UnnecessaryStringConcatUnitTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,21 @@ public function getErrorList($testFile='')
6565
* The key of the array should represent the line number and the value
6666
* should represent the number of warnings that should occur on that line.
6767
*
68+
* @param string $testFile The name of the file being tested.
69+
*
6870
* @return array<int, int>
6971
*/
70-
public function getWarningList()
72+
public function getWarningList($testFile='')
7173
{
72-
return [];
74+
switch ($testFile) {
75+
case 'UnnecessaryStringConcatUnitTest.1.inc':
76+
return [
77+
33 => 1,
78+
];
79+
80+
default:
81+
return [];
82+
}
7383

7484
}//end getWarningList()
7585

0 commit comments

Comments
 (0)