-
-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DX] [Experimental] Add withPhpLevel() to raise PHP level one rule at…
… a time (#6261) * [DX] [Experimental] Add withPhpLevel() to raise PHP lele one rule at a time * add set rectors resolver test
- Loading branch information
1 parent
d7bfc24
commit 684f23d
Showing
5 changed files
with
177 additions
and
15 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"require": { | ||
"php": "^7.3" | ||
} | ||
} |
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,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Bridge; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Rector\Bridge\SetRectorsResolver; | ||
use Rector\Configuration\PhpLevelSetResolver; | ||
use Rector\Contract\Rector\RectorInterface; | ||
use Rector\Php\PhpVersionResolver\ComposerJsonPhpVersionResolver; | ||
use Rector\Set\ValueObject\SetList; | ||
use Rector\ValueObject\PhpVersion; | ||
|
||
final class SetRectorsResolverTest extends TestCase | ||
{ | ||
private SetRectorsResolver $setRectorsResolver; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->setRectorsResolver = new SetRectorsResolver(); | ||
} | ||
|
||
public function testResolveFromFilePathForPhpVersion(): void | ||
{ | ||
$configFilePaths = PhpLevelSetResolver::resolveFromPhpVersion(PhpVersion::PHP_70); | ||
$this->assertCount(6, $configFilePaths); | ||
$this->assertContainsOnly('string', $configFilePaths); | ||
|
||
foreach ($configFilePaths as $configFilePath) { | ||
$this->assertFileExists($configFilePath); | ||
} | ||
} | ||
|
||
public function testResolveFromFilePathForPhpLevel(): void | ||
{ | ||
$projectPhpVersion = ComposerJsonPhpVersionResolver::resolve(__DIR__ . '/Fixture/some-composer.json'); | ||
|
||
$this->assertIsInt($projectPhpVersion); | ||
$this->assertSame(PhpVersion::PHP_73, $projectPhpVersion); | ||
|
||
$configFilePaths = PhpLevelSetResolver::resolveFromPhpVersion($projectPhpVersion); | ||
$this->assertCount(9, $configFilePaths); | ||
|
||
$rectorRulesWithConfiguration = $this->setRectorsResolver->resolveFromFilePathsIncludingConfiguration( | ||
$configFilePaths | ||
); | ||
$this->assertCount(63, $rectorRulesWithConfiguration); | ||
} | ||
|
||
public function testResolveWithConfiguration(): void | ||
{ | ||
$rectorRulesWithConfiguration = $this->setRectorsResolver->resolveFromFilePathIncludingConfiguration( | ||
SetList::PHP_73 | ||
); | ||
$this->assertCount(10, $rectorRulesWithConfiguration); | ||
|
||
$this->assertArrayHasKey(0, $rectorRulesWithConfiguration); | ||
$this->assertArrayHasKey(9, $rectorRulesWithConfiguration); | ||
|
||
foreach ($rectorRulesWithConfiguration as $rectorRuleWithConfiguration) { | ||
if (is_string($rectorRuleWithConfiguration)) { | ||
$this->assertTrue(is_a($rectorRuleWithConfiguration, RectorInterface::class, true)); | ||
} | ||
|
||
if (is_array($rectorRuleWithConfiguration)) { | ||
foreach ($rectorRuleWithConfiguration as $rectorRule => $rectorRuleConfiguration) { | ||
$this->assertTrue(is_a($rectorRule, RectorInterface::class, true)); | ||
$this->assertIsArray($rectorRuleConfiguration); | ||
} | ||
} | ||
} | ||
} | ||
} |