-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Php56][Php70] Handle infinite loop on TernaryToNullCoalescingRector+…
…AddDefaultValueForUndefinedVariableRector (#3639) * reproduce hang * Closes rectorphp/rector#7889 * clean up * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <actions@github.com>
- Loading branch information
1 parent
fff2232
commit 8425c90
Showing
5 changed files
with
76 additions
and
4 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
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
29 changes: 29 additions & 0 deletions
29
tests/Issues/TernaryCoalesceDefault/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,29 @@ | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\TernaryCoalesceDefault\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function run() | ||
{ | ||
$http = env('HTTP_X'); | ||
return ($http === null) ? false : $http; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\TernaryCoalesceDefault\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function run() | ||
{ | ||
$http = env('HTTP_X'); | ||
return $http ?? false; | ||
} | ||
} | ||
|
||
?> |
28 changes: 28 additions & 0 deletions
28
tests/Issues/TernaryCoalesceDefault/TernaryCoalesceDefaultTest.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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\TernaryCoalesceDefault; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class TernaryCoalesceDefaultTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/Issues/TernaryCoalesceDefault/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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector; | ||
use Rector\Php70\Rector\Ternary\TernaryToNullCoalescingRector; | ||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rules([ | ||
TernaryToNullCoalescingRector::class, | ||
AddDefaultValueForUndefinedVariableRector::class, | ||
]); | ||
}; |