Skip to content

Commit

Permalink
[e2e] Add e2e for parallel process with current directory contains s…
Browse files Browse the repository at this point in the history
…pace (#2421)

* [e2e] Add e2e for parallel process with current directory contains space

* [e2e] Add e2e for parallel process with current directory contains space

* dir name

* Fixed 🎉

* phpstan

* final touch: eol

* clean up

* clean up

* final touch: use escapeshellarg()

* Add note for why escapeshellarg() is needed in parallel
  • Loading branch information
samsonasik committed Jun 3, 2022
1 parent d2bf080 commit e8f058a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
- 'e2e/template-extends'
- 'e2e/use-rector-configurator'
- 'e2e/applied-rule-removed-node'
- 'e2e/parallel with space'

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

Expand Down
5 changes: 5 additions & 0 deletions e2e/parallel with space/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"php": "^8.1"
}
}
12 changes: 12 additions & 0 deletions e2e/parallel with space/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
]);
$rectorConfig->parallel();
};
5 changes: 5 additions & 0 deletions e2e/parallel with space/src/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

class Test
{
}
19 changes: 18 additions & 1 deletion packages/Parallel/Command/WorkerCommandLineFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,24 @@ public function create(

if ($input->hasOption(Option::CONFIG)) {
$workerCommandArray[] = '--config';
$workerCommandArray[] = $input->getOption(Option::CONFIG);
/**
* On parallel, the command is generated with `--config` addition
* Using escapeshellarg() to ensure the --config path escaped, even when it has a space.
*
* eg:
* --config /path/e2e/parallel with space/rector.php
*
* that can cause error:
*
* File /rector-src/e2e/parallel\" was not found
*
* the escaped result is:
*
* --config '/path/e2e/parallel with space/rector.php'
*
* tested in macOS and Ubuntu (github action)
*/
$workerCommandArray[] = escapeshellarg($input->getOption(Option::CONFIG));
}

return implode(' ', $workerCommandArray);
Expand Down

0 comments on commit e8f058a

Please sign in to comment.