Skip to content

Commit cd6a27d

Browse files
committed
Tokenizer/PHP: add some extra tests for the readonly keyword backfill
Includes some minor tweaks to pre-existing tests.
1 parent 7b974f9 commit cd6a27d

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

tests/Core/Tokenizer/BackfillReadonlyTest.inc

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ class Foo
4949
public ReAdOnLy string $caseInsensitiveProperty;
5050

5151
/* testReadonlyConstructorPropertyPromotion */
52-
public function __construct(private readonly bool $constructorPropertyPromotion)
53-
{
54-
}
52+
public function __construct(private readonly bool $constructorPropertyPromotion) {}
5553

5654
/* testReadonlyConstructorPropertyPromotionWithReference */
5755
public function __construct(private ReadOnly bool &$constructorPropertyPromotion) {}
@@ -68,8 +66,6 @@ class ClassName {
6866

6967
/* testReadonlyUsedAsMethodName */
7068
public function readonly() {
71-
// Do something.
72-
7369
/* testReadonlyUsedAsPropertyName */
7470
$this->readonly = 'foo';
7571

@@ -79,16 +75,27 @@ class ClassName {
7975
}
8076

8177
/* testReadonlyUsedAsFunctionName */
82-
function readonly()
83-
{
84-
}
78+
function readonly() {}
79+
80+
/* testReadonlyUsedAsFunctionNameWithReturnByRef */
81+
function &readonly() {}
8582

8683
/* testReadonlyUsedAsNamespaceName */
8784
namespace Readonly;
8885
/* testReadonlyUsedAsPartOfNamespaceName */
8986
namespace My\Readonly\Collection;
9087
/* testReadonlyAsFunctionCall */
9188
$var = readonly($a, $b);
89+
/* testReadonlyAsNamespacedFunctionCall */
90+
$var = My\NS\readonly($a, $b);
91+
/* testReadonlyAsNamespaceRelativeFunctionCall */
92+
$var = namespace\ReadOnly($a, $b);
93+
/* testReadonlyAsMethodCall */
94+
$var = $obj->readonly($a, $b);
95+
/* testReadonlyAsNullsafeMethodCall */
96+
$var = $obj?->readOnly($a, $b);
97+
/* testReadonlyAsStaticMethodCallWithSpace */
98+
$var = ClassName::readonly ($a, $b);
9299
/* testClassConstantFetchWithReadonlyAsConstantName */
93100
echo ClassName::READONLY;
94101

tests/Core/Tokenizer/BackfillReadonlyTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ public function dataNotReadonly()
214214
'/* testReadonlyUsedAsFunctionName */',
215215
'readonly',
216216
],
217+
[
218+
'/* testReadonlyUsedAsFunctionNameWithReturnByRef */',
219+
'readonly',
220+
],
217221
[
218222
'/* testReadonlyUsedAsNamespaceName */',
219223
'Readonly',
@@ -226,6 +230,26 @@ public function dataNotReadonly()
226230
'/* testReadonlyAsFunctionCall */',
227231
'readonly',
228232
],
233+
[
234+
'/* testReadonlyAsNamespacedFunctionCall */',
235+
'readonly',
236+
],
237+
[
238+
'/* testReadonlyAsNamespaceRelativeFunctionCall */',
239+
'ReadOnly',
240+
],
241+
[
242+
'/* testReadonlyAsMethodCall */',
243+
'readonly',
244+
],
245+
[
246+
'/* testReadonlyAsNullsafeMethodCall */',
247+
'readOnly',
248+
],
249+
[
250+
'/* testReadonlyAsStaticMethodCallWithSpace */',
251+
'readonly',
252+
],
229253
[
230254
'/* testClassConstantFetchWithReadonlyAsConstantName */',
231255
'READONLY',

0 commit comments

Comments
 (0)