Skip to content

Commit

Permalink
[e2e][parallel] Allow set custom config on Parallel (#1620)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Jan 4, 2022
1 parent 0a0e0fd commit 6390862
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 8 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/e2e.yaml
Expand Up @@ -25,6 +25,7 @@ jobs:
directory:
- 'e2e/template-extends'
- 'e2e/plain-views'
- 'e2e/parallel-custom-config'

name: End to end test - ${{ matrix.directory }}

Expand All @@ -45,7 +46,15 @@ jobs:
working-directory: ${{ matrix.directory }}

# run e2e test
-
run: php ../e2eTestRunner.php
- run: php ../e2eTestRunner.php -c custom/config/rector.php
working-directory: ${{ matrix.directory }}
if: ${{ matrix.directory == 'e2e/parallel-custom-config' }}

- run: php ../e2eTestRunner.php --config custom/config/rector.php
working-directory: ${{ matrix.directory }}
if: ${{ matrix.directory == 'e2e/parallel-custom-config' }}

- run: php ../e2eTestRunner.php
working-directory: ${{ matrix.directory }}
if: ${{ matrix.directory != 'e2e/parallel-custom-config' }}

11 changes: 10 additions & 1 deletion e2e/e2eTestRunner.php
Expand Up @@ -8,7 +8,16 @@
$rectorBin = $projectRoot .'bin/rector';
$autoloadFile = $projectRoot .'vendor/autoload.php';

$e2eCommand = 'php '. $rectorBin .' process --dry-run --no-ansi --no-progress-bar -a '. $autoloadFile;
$e2eCommand = 'php '. $rectorBin .' process --dry-run --no-ansi --no-progress-bar -a '. $autoloadFile . ' --clear-cache';

if (isset($argv[1]) && $argv[1] === '-c') {
$e2eCommand .= ' -c ' . $argv[2];
}

if (isset($argv[1]) && $argv[1] === '--config') {
$e2eCommand .= ' --config ' . $argv[2];
}

exec($e2eCommand, $output, $exitCode);
$output = trim(implode("\n", $output));

Expand Down
1 change: 1 addition & 0 deletions e2e/parallel-custom-config/.gitignore
@@ -0,0 +1 @@
/vendor
5 changes: 5 additions & 0 deletions e2e/parallel-custom-config/composer.json
@@ -0,0 +1,5 @@
{
"require": {
"php": "^8.1"
}
}
20 changes: 20 additions & 0 deletions e2e/parallel-custom-config/custom/config/rector.php
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\Core\Configuration\Option;
use Rector\DowngradePhp81\Rector\Property\DowngradeReadonlyPropertyRector;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();

$parameters->set(Option::PARALLEL, true);
$parameters->set(Option::PATHS, [
__DIR__.'/../../src/',
]);

$services = $containerConfigurator->services();
$services->set(DowngradeReadonlyPropertyRector::class);
};

22 changes: 22 additions & 0 deletions e2e/parallel-custom-config/expected-output.diff
@@ -0,0 +1,22 @@
1 file with changes
===================

1) src/SomeClass.php:6

---------- begin diff ----------
@@ @@
class SomeClass
{
public function __construct(
- private readonly \stdClass $stdClass
+ private \stdClass $stdClass
)
{
}
----------- end diff -----------

Applied rules:
* DowngradeReadonlyPropertyRector (https://wiki.php.net/rfc/readonly_properties_v2)


[OK] 1 file would have changed (dry-run) by Rector
14 changes: 14 additions & 0 deletions e2e/parallel-custom-config/src/SomeClass.php
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace E2e\Parallel\Custom\Config;

class SomeClass
{
public function __construct(
private readonly \stdClass $stdClass
)
{
}
}
5 changes: 5 additions & 0 deletions packages/Parallel/Command/WorkerCommandLineFactory.php
Expand Up @@ -96,6 +96,11 @@ public function create(
// @see https://github.com/symfony/symfony/issues/1238
$workerCommandArray[] = '--no-ansi';

if ($input->hasOption(Option::CONFIG)) {
$workerCommandArray[] = '--config';
$workerCommandArray[] = $input->getOption(Option::CONFIG);
}

return implode(' ', $workerCommandArray);
}

Expand Down
Expand Up @@ -7,14 +7,12 @@
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Name;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -25,11 +23,13 @@
*/
final class DowngradeUncallableValueCallToCallUserFuncRector extends AbstractRector
{
/** @var array<class-string<Expr>> */
/**
* @var array<class-string<Expr>>
*/
private const INDIRECT_CALLABLE_EXPR = [
// Interpreted as MethodCall without parentheses.
// Interpreted as MethodCall without parentheses.
PropertyFetch::class,
// Interpreted as StaticCall without parentheses.
// Interpreted as StaticCall without parentheses.
StaticPropertyFetch::class,
Closure::class,
// The first function call does not even need to be wrapped in parentheses
Expand Down Expand Up @@ -95,6 +95,7 @@ public function refactor(Node $node): ?FuncCall
if ($node->name instanceof Name) {
return null;
}

if (! $this->isNotDirectlyCallableInPhp5($node->name)) {
return null;
}
Expand Down

0 comments on commit 6390862

Please sign in to comment.