From bbf2dff36f54202e806e6900601d95ef6978e077 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 9 Sep 2025 16:59:36 +0200 Subject: [PATCH] Tokenizer/PHP/NullableVsInlineThenTest: add more test cases These tests will on PHPCS 4.x cause a "Using null as an array offset" deprecation notice on PHP 8.5. --- .../PHP/NullableVsInlineThenTest.inc | 50 +++++++++++++++++++ .../PHP/NullableVsInlineThenTest.php | 25 +++++++++- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/tests/Core/Tokenizers/PHP/NullableVsInlineThenTest.inc b/tests/Core/Tokenizers/PHP/NullableVsInlineThenTest.inc index ce25391203..ffdbd9e046 100644 --- a/tests/Core/Tokenizers/PHP/NullableVsInlineThenTest.inc +++ b/tests/Core/Tokenizers/PHP/NullableVsInlineThenTest.inc @@ -18,8 +18,58 @@ abstract class Nullable abstract ?string $prop5 { get; } } +$closure = function ( + /* testClosureParamTypeNullableInt */ + ?Int $a, + /* testClosureParamTypeNullableCallable */ + ? Callable $b +/* testClosureReturnTypeNullableInt */ +) :?INT{}; + +/* testFunctionReturnTypeNullableCallable */ +function testCallableReturn() : ? callable {} + class InlineThen { /* testInlineThenInPropertyDefaultValue */ public int $prop = self::SOMECONT ? PHP_CONST ? OTHER_CONST; } + +/* testInlineThenWithArrayDeclaration */ +$ternary = true ? array() : null; + +/* testInlineThenWithUnqualifiedNameAndNothingElse */ +$ternary = true ? CONSTANT_NAME : null; + +/* testInlineThenWithUnqualifiedNameAndParens */ +$ternary = true ? callMe() : null; + +/* testInlineThenWithUnqualifiedNameAndDoubleColon */ +$ternary = true ? ClassName::callMe() : null; + +/* testInlineThenWithFullyQualifiedNameAndNothingElse */ +$ternary = true ? \CONSTANT_NAME : null; + +/* testInlineThenWithFullyQualifiedNameAndParens */ +$ternary = true ? \Fully\callMe() : null; + +/* testInlineThenWithFullyQualifiedNameAndDoubleColon */ +$ternary = true ? \Fully\ClassName::callMe() : null; + +/* testInlineThenWithPartiallyQualifiedNameAndNothingElse */ +$ternary = true ? Partially\CONSTANT_NAME : null; + +/* testInlineThenWithPartiallyQualifiedNameAndParens */ +$ternary = true ? Partially\callMe() : null; + +/* testInlineThenWithPartiallyQualifiedNameAndDoubleColon */ +$ternary = true ? Partially\ClassName::callMe() : null; + +/* testInlineThenWithNamespaceRelativeNameAndNothingElse */ +$ternary = true ? Partially\CONSTANT_NAME : null; + +/* testInlineThenWithNamespaceRelativeNameAndParens */ +$ternary = true ? Partially\callMe() : null; + +/* testInlineThenWithNamespaceRelativeNameAndDoubleColon */ +$ternary = true ? Partially\ClassName::callMe() : null; diff --git a/tests/Core/Tokenizers/PHP/NullableVsInlineThenTest.php b/tests/Core/Tokenizers/PHP/NullableVsInlineThenTest.php index 9d36fa62a3..81d4b6c01c 100644 --- a/tests/Core/Tokenizers/PHP/NullableVsInlineThenTest.php +++ b/tests/Core/Tokenizers/PHP/NullableVsInlineThenTest.php @@ -55,6 +55,11 @@ public static function dataNullable() 'property declaration, public and protected set' => ['/* testNullablePublicProtectedSet */'], 'property declaration, final, no visibility' => ['/* testNullableFinalOnly */'], 'property declaration, abstract, no visibility' => ['/* testNullableAbstractOnly */'], + + 'closure param type, nullable int' => ['/* testClosureParamTypeNullableInt */'], + 'closure param type, nullable callable' => ['/* testClosureParamTypeNullableCallable */'], + 'closure return type, nullable int' => ['/* testClosureReturnTypeNullableInt */'], + 'function return type, nullable callable' => ['/* testFunctionReturnTypeNullableCallable */'], ]; }//end dataNullable() @@ -91,7 +96,25 @@ public function testInlineThen($testMarker) public static function dataInlineThen() { return [ - 'ternary in property default value' => ['/* testInlineThenInPropertyDefaultValue */'], + 'ternary in property default value' => ['/* testInlineThenInPropertyDefaultValue */'], + + 'ternary ? followed by array declaration' => ['/* testInlineThenWithArrayDeclaration */'], + + 'ternary ? followed by unqualified constant' => ['/* testInlineThenWithUnqualifiedNameAndNothingElse */'], + 'ternary ? followed by unqualified function call' => ['/* testInlineThenWithUnqualifiedNameAndParens */'], + 'ternary ? followed by unqualified static method call' => ['/* testInlineThenWithUnqualifiedNameAndDoubleColon */'], + + 'ternary ? followed by fully qualified constant' => ['/* testInlineThenWithFullyQualifiedNameAndNothingElse */'], + 'ternary ? followed by fully qualified function call' => ['/* testInlineThenWithFullyQualifiedNameAndParens */'], + 'ternary ? followed by fully qualified static method call' => ['/* testInlineThenWithFullyQualifiedNameAndDoubleColon */'], + + 'ternary ? followed by partially qualified constant' => ['/* testInlineThenWithPartiallyQualifiedNameAndNothingElse */'], + 'ternary ? followed by partially qualified function call' => ['/* testInlineThenWithPartiallyQualifiedNameAndParens */'], + 'ternary ? followed by partially qualified static method call' => ['/* testInlineThenWithPartiallyQualifiedNameAndDoubleColon */'], + + 'ternary ? followed by namespace relative constant' => ['/* testInlineThenWithNamespaceRelativeNameAndNothingElse */'], + 'ternary ? followed by namespace relative function call' => ['/* testInlineThenWithNamespaceRelativeNameAndParens */'], + 'ternary ? followed by namespace relative static method call' => ['/* testInlineThenWithNamespaceRelativeNameAndDoubleColon */'], ]; }//end dataInlineThen()