Skip to content

Commit f97ece7

Browse files
authored
Merge pull request #707 from PHPCSStandards/feature/add-more-tests-with-fqn-exit-die
Parentheses/PassedParameters: add tests with FQN exit/die
2 parents e434bd8 + dfdc9e2 commit f97ece7

File tree

5 files changed

+76
-2
lines changed

5 files changed

+76
-2
lines changed

Tests/Utils/Parentheses/ParenthesesTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ eval($a . $b . $c );
6565
/* testExit */
6666
if (defined('FOO') || die('message')) {}
6767

68+
/* testFQNExit */
69+
if (defined('FOO') || \exit(10)) {}
70+
6871
/* testMatch */
6972
$m = match(count($a)) {
7073
1 => true,

Tests/Utils/Parentheses/ParenthesesTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ final class ParenthesesTest extends UtilityMethodTestCase
182182
'code' => \T_CONSTANT_ENCAPSED_STRING,
183183
'content' => "'message'",
184184
],
185+
'testIfFQNExitDie-boolean-or' => [
186+
'marker' => '/* testFQNExit */',
187+
'code' => \T_BOOLEAN_OR,
188+
],
189+
'testIfFQNExitDie-statuscode' => [
190+
'marker' => '/* testFQNExit */',
191+
'code' => \T_LNUMBER,
192+
],
185193
'testMatch-count' => [
186194
'marker' => '/* testMatch */',
187195
'code' => \T_STRING,
@@ -637,6 +645,8 @@ public function testGetLastOwner($testName, $expectedResults)
637645
*/
638646
public static function dataWalkParentheses()
639647
{
648+
$php8Names = parent::usesPhp8NameTokens();
649+
640650
$data = [
641651
'testIfWithArray-$a' => [
642652
'testName' => 'testIfWithArray-$a',
@@ -927,6 +937,40 @@ public static function dataWalkParentheses()
927937
'lastIfElseOwner' => -12,
928938
],
929939
],
940+
'testIfFQNExitDie-boolean-or' => [
941+
'testName' => 'testIfFQNExitDie-boolean-or',
942+
'expectedResults' => [
943+
'firstOpener' => -6,
944+
'firstCloser' => ($php8Names === true) ? 6 : 7,
945+
'firstOwner' => -8,
946+
'firstScopeOwnerOpener' => -6,
947+
'firstScopeOwnerCloser' => ($php8Names === true) ? 6 : 7,
948+
'firstScopeOwnerOwner' => -8,
949+
'lastOpener' => -6,
950+
'lastCloser' => ($php8Names === true) ? 6 : 7,
951+
'lastOwner' => -8,
952+
'lastArrayOpener' => false,
953+
'lastFunctionCloser' => false,
954+
'lastIfElseOwner' => -8,
955+
],
956+
],
957+
'testIfFQNExitDie-message' => [
958+
'testName' => 'testIfFQNExitDie-statuscode',
959+
'expectedResults' => [
960+
'firstOpener' => ($php8Names === true) ? -10 : -11,
961+
'firstCloser' => 2,
962+
'firstOwner' => ($php8Names === true) ? -12 : -13,
963+
'firstScopeOwnerOpener' => ($php8Names === true) ? -10 : -11,
964+
'firstScopeOwnerCloser' => 2,
965+
'firstScopeOwnerOwner' => ($php8Names === true) ? -12 : -13,
966+
'lastOpener' => -1,
967+
'lastCloser' => 1,
968+
'lastOwner' => -2,
969+
'lastArrayOpener' => false,
970+
'lastFunctionCloser' => false,
971+
'lastIfElseOwner' => ($php8Names === true) ? -12 : -13,
972+
],
973+
],
930974
'testMatch-count' => [
931975
'testName' => 'testMatch-count',
932976
'expectedResults' => [
@@ -1210,6 +1254,17 @@ public static function dataHasOwner()
12101254
'T_EXIT' => true,
12111255
],
12121256
],
1257+
'testIfFQNExitDie-boolean-or' => [
1258+
'testName' => 'testIfFQNExitDie-boolean-or',
1259+
'expectedResults' => ['T_IF' => true],
1260+
],
1261+
'testIfFQNExitDie-statuscode' => [
1262+
'testName' => 'testIfFQNExitDie-statuscode',
1263+
'expectedResults' => [
1264+
'T_IF' => true,
1265+
'T_EXIT' => true,
1266+
],
1267+
],
12131268
'testMatch-count' => [
12141269
'testName' => 'testMatch-count',
12151270
'expectedResults' => [

Tests/Utils/PassedParameters/GetParametersNamedTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ echo $cond ? foo( label: $something ) : /* testTernaryWithFunctionCallsInElse */
5656
/* testExitWithNamedParam */
5757
exit( status: 1 );
5858

59+
/* testFQNDieWithNamedParam */
60+
\die( status: 1 );
61+
5962
/* testCompileErrorNamedBeforePositional */
6063
// Not the concern of PHPCSUtils. Should still be handled.
6164
test(param: $bar, $foo);

Tests/Utils/PassedParameters/GetParametersNamedTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,19 @@ public static function dataGetParameters()
439439
],
440440
],
441441
],
442+
'named-args-for-FQN-die' => [
443+
'testMarker' => '/* testFQNDieWithNamedParam */',
444+
'targetType' => \T_EXIT,
445+
'expected' => [
446+
'status' => [
447+
'name' => 'status',
448+
'name_token' => 3,
449+
'start' => 5,
450+
'end' => 7,
451+
'raw' => '1',
452+
],
453+
],
454+
],
442455

443456
'named-args-compile-error-named-before-positional' => [
444457
'testMarker' => '/* testCompileErrorNamedBeforePositional */',

Tests/Utils/PassedParameters/HasParametersTest.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ unset(
174174
exit();
175175

176176
/* testHasParamsExit */
177-
exit( $code );
177+
\exit( $code );
178178

179179
/* testNoParamsDie */
180-
die( /*comment*/ );
180+
\die( /*comment*/ );
181181

182182
/* testHasParamsDie */
183183
die( $status );

0 commit comments

Comments
 (0)