Skip to content

Commit 8f43103

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

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
@@ -212,6 +212,10 @@ public function dataNotReadonly()
212212
'/* testReadonlyUsedAsFunctionName */',
213213
'readonly',
214214
],
215+
[
216+
'/* testReadonlyUsedAsFunctionNameWithReturnByRef */',
217+
'readonly',
218+
],
215219
[
216220
'/* testReadonlyUsedAsNamespaceName */',
217221
'Readonly',
@@ -224,6 +228,26 @@ public function dataNotReadonly()
224228
'/* testReadonlyAsFunctionCall */',
225229
'readonly',
226230
],
231+
[
232+
'/* testReadonlyAsNamespacedFunctionCall */',
233+
'readonly',
234+
],
235+
[
236+
'/* testReadonlyAsNamespaceRelativeFunctionCall */',
237+
'ReadOnly',
238+
],
239+
[
240+
'/* testReadonlyAsMethodCall */',
241+
'readonly',
242+
],
243+
[
244+
'/* testReadonlyAsNullsafeMethodCall */',
245+
'readOnly',
246+
],
247+
[
248+
'/* testReadonlyAsStaticMethodCallWithSpace */',
249+
'readonly',
250+
],
227251
[
228252
'/* testClassConstantFetchWithReadonlyAsConstantName */',
229253
'READONLY',

0 commit comments

Comments
 (0)