Skip to content

Commit ad950eb

Browse files
committed
Tests/BCFile::findStartOfStatement(): sync in new tests from upstream [3]
See PR PHPCSStandards/PHP_CodeSniffer 502 / PHPCSStandards/PHP_CodeSniffer@d3abcd6
1 parent 529f43e commit ad950eb

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Tests/BackCompat/BCFile/FindStartOfStatementTest.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,9 @@ callMe($paramA, match ($var) {
192192
'c' => fn($p1, /* test437FnSecondParamWithinNestedMatch */ $p2) => $p1 + $p2,
193193
default => false
194194
});
195+
196+
match ($var) {
197+
/* test437NestedShortArrayWithinMatch */
198+
'a' => [ 1, 2.5, $var],
199+
default => false
200+
};

Tests/BackCompat/BCFile/FindStartOfStatementTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,4 +813,53 @@ public static function dataFindStartInsideParenthesesNestedWithinNestedMatch()
813813
],
814814
];
815815
}
816+
817+
/**
818+
* Test finding the start of a statement for a token within a short array within a match expressions.
819+
*
820+
* @param string $testMarker The comment which prefaces the target token in the test file.
821+
* @param int|string $target The token to search for after the test marker.
822+
* @param int|string $expectedTarget Token code of the expected start of statement stack pointer.
823+
*
824+
* @link https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/437
825+
*
826+
* @dataProvider dataFindStartInsideShortArrayNestedWithinMatch
827+
*
828+
* @return void
829+
*/
830+
public function testFindStartInsideShortArrayNestedWithinMatch($testMarker, $target, $expectedTarget)
831+
{
832+
$testToken = $this->getTargetToken($testMarker, $target);
833+
$expected = $this->getTargetToken($testMarker, $expectedTarget);
834+
835+
$found = BCFile::findStartOfStatement(self::$phpcsFile, $testToken);
836+
837+
$this->assertSame($expected, $found);
838+
}
839+
840+
/**
841+
* Data provider.
842+
*
843+
* @return array<string, array<string, int|string>>
844+
*/
845+
public static function dataFindStartInsideShortArrayNestedWithinMatch()
846+
{
847+
return [
848+
'Array item itself should be start for first array item' => [
849+
'testMarker' => '/* test437NestedShortArrayWithinMatch */',
850+
'target' => T_LNUMBER,
851+
'expectedTarget' => T_LNUMBER,
852+
],
853+
'Array item itself should be start for second array item' => [
854+
'testMarker' => '/* test437NestedShortArrayWithinMatch */',
855+
'target' => T_DNUMBER,
856+
'expectedTarget' => T_DNUMBER,
857+
],
858+
'Array item itself should be start for third array item' => [
859+
'testMarker' => '/* test437NestedShortArrayWithinMatch */',
860+
'target' => T_VARIABLE,
861+
'expectedTarget' => T_VARIABLE,
862+
],
863+
];
864+
}
816865
}

0 commit comments

Comments
 (0)