[Scoped][e2e] Fix standalone rule test on scoped build (#2491)

* [Scoped] Fix standalone rule test on scoped build

* name
This commit is contained in:
Abdul Malik Ikhsan 2022-06-14 13:44:59 +07:00 committed by GitHub
parent aceb0e8a93
commit b536a67738
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 138 additions and 17 deletions

View File

@ -9,32 +9,30 @@ on:
jobs:
standalone_rule_test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
actions:
-
name: 'Rector Prefixed'
run: |
composer config minimum-stability dev
composer config prefer-stable true
composer require rector/rector:dev-main --dev
php_version: ['7.3']
directory:
- 'e2e/rector-prefixed-rule-test'
name: End to end test - ${{ matrix.directory }}
steps:
# see https://github.com/rectorphp/rector-prefixed-rule-test
-
uses: actions/checkout@v2
with:
repository: rectorphp/rector-prefixed-rule-test
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: '7.3'
php-version: ${{ matrix.php_version }}
coverage: none
- uses: "ramsey/composer-install@v1"
# wait for deploy to packagist
- run: sleep 40
- run: ${{ matrix.actions.run }}
-
run: composer install --ansi
working-directory: ${{ matrix.directory }}
- run: vendor/bin/phpunit
-
run: vendor/bin/phpunit
working-directory: ${{ matrix.directory }}

View File

@ -0,0 +1,3 @@
/.phpunit.result.cache
/vendor
/composer.lock

View File

@ -0,0 +1,15 @@
{
"require": {
"php": "^7.3"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"rector/rector": "dev-main"
},
"autoload-dev": {
"psr-4": {
"Utils\\Rector\\": "utils/rector/src",
"Utils\\Rector\\Tests\\": "utils/rector/tests"
}
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/rector/rector/vendor/scoper-autoload.php"
colors="true"
>
<testsuites>
<testsuite name="main">
<directory>utils/rector/tests</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Utils\Rector\Rector;
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Utils\Rector\Tests\Rector\RenameSimpleRectorTest
*/
final class RenameSimpleRector extends AbstractRector
{
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [Variable::class];
}
/**
* @param Variable $node
*/
public function refactor(Node $node): ?Node
{
$node->name = 'newValue';
return $node;
}
public function getRuleDefinition(): RuleDefinition
{
// needed only for simple test only
}
}

View File

@ -0,0 +1,11 @@
<?php
$value = 1000;
?>
-----
<?php
$newValue = 1000;
?>

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Utils\Rector\Tests\Rector\RenameSimpleRector;
use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class RenameSimpleRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Utils\Rector\Rector\RenameSimpleRector;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(RenameSimpleRector::class);
};