-
-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Php81][Restoration] Handle crash on ReadOnlyPropertyRector+MakeTyped…
…PropertyNullableIfCheckedRector (#3046) Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
8ede862
commit 51c2bbe
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/Issues/IssueReadonlyPropertyNullable/Fixture/fixture.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\IssueReadonlyPropertyNullable\Fixture; | ||
|
||
final class SomeClass | ||
{ | ||
private AnotherClass $anotherClass; | ||
|
||
public function run() | ||
{ | ||
if ($this->anotherClass === null) { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\IssueReadonlyPropertyNullable\Fixture; | ||
|
||
final class SomeClass | ||
{ | ||
private ?AnotherClass $anotherClass = null; | ||
|
||
public function run() | ||
{ | ||
if ($this->anotherClass === null) { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
?> |
35 changes: 35 additions & 0 deletions
35
tests/Issues/IssueReadonlyPropertyNullable/IssueReadonlyPropertyNullableTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\IssueReadonlyPropertyNullable; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
/** | ||
* @see https://github.com/rectorphp/rector/issues/7590 | ||
*/ | ||
final class IssueReadonlyPropertyNullableTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
/** | ||
* @return Iterator<array<string>> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Issues/IssueReadonlyPropertyNullable/config/configured_rule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; | ||
use Rector\Restoration\Rector\Property\MakeTypedPropertyNullableIfCheckedRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(ReadOnlyPropertyRector::class); | ||
$rectorConfig->rule(MakeTypedPropertyNullableIfCheckedRector::class); | ||
}; |