Skip to content

Commit

Permalink
Tokenizer/PHP: add some extra tests for the readonly keyword backfill
Browse files Browse the repository at this point in the history
Includes some minor tweaks to pre-existing tests.
  • Loading branch information
jrfnl committed Nov 9, 2023
1 parent 7b103ed commit 8f43103
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
23 changes: 15 additions & 8 deletions tests/Core/Tokenizer/BackfillReadonlyTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ class Foo
public ReAdOnLy string $caseInsensitiveProperty;

/* testReadonlyConstructorPropertyPromotion */
public function __construct(private readonly bool $constructorPropertyPromotion)
{
}
public function __construct(private readonly bool $constructorPropertyPromotion) {}

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

/* testReadonlyUsedAsMethodName */
public function readonly() {
// Do something.

/* testReadonlyUsedAsPropertyName */
$this->readonly = 'foo';

Expand All @@ -79,16 +75,27 @@ class ClassName {
}

/* testReadonlyUsedAsFunctionName */
function readonly()
{
}
function readonly() {}

/* testReadonlyUsedAsFunctionNameWithReturnByRef */
function &readonly() {}

/* testReadonlyUsedAsNamespaceName */
namespace Readonly;
/* testReadonlyUsedAsPartOfNamespaceName */
namespace My\Readonly\Collection;
/* testReadonlyAsFunctionCall */
$var = readonly($a, $b);
/* testReadonlyAsNamespacedFunctionCall */
$var = My\NS\readonly($a, $b);
/* testReadonlyAsNamespaceRelativeFunctionCall */
$var = namespace\ReadOnly($a, $b);
/* testReadonlyAsMethodCall */
$var = $obj->readonly($a, $b);
/* testReadonlyAsNullsafeMethodCall */
$var = $obj?->readOnly($a, $b);
/* testReadonlyAsStaticMethodCallWithSpace */
$var = ClassName::readonly ($a, $b);
/* testClassConstantFetchWithReadonlyAsConstantName */
echo ClassName::READONLY;

Expand Down
24 changes: 24 additions & 0 deletions tests/Core/Tokenizer/BackfillReadonlyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ public function dataNotReadonly()
'/* testReadonlyUsedAsFunctionName */',
'readonly',
],
[
'/* testReadonlyUsedAsFunctionNameWithReturnByRef */',
'readonly',
],
[
'/* testReadonlyUsedAsNamespaceName */',
'Readonly',
Expand All @@ -224,6 +228,26 @@ public function dataNotReadonly()
'/* testReadonlyAsFunctionCall */',
'readonly',
],
[
'/* testReadonlyAsNamespacedFunctionCall */',
'readonly',
],
[
'/* testReadonlyAsNamespaceRelativeFunctionCall */',
'ReadOnly',
],
[
'/* testReadonlyAsMethodCall */',
'readonly',
],
[
'/* testReadonlyAsNullsafeMethodCall */',
'readOnly',
],
[
'/* testReadonlyAsStaticMethodCallWithSpace */',
'readonly',
],
[
'/* testClassConstantFetchWithReadonlyAsConstantName */',
'READONLY',
Expand Down

0 comments on commit 8f43103

Please sign in to comment.