Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions packages-tests/Parallel/Command/WorkerCommandLineFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ final class WorkerCommandLineFactoryTest extends AbstractLazyTestCase
*/
private const DUMMY_MAIN_SCRIPT = 'main_script';

/**
* @var string
*/
private const SPACED_DUMMY_MAIN_SCRIPT = 'C:\Users\P\Desktop\Web Dev\vendor\bin\rector';

private WorkerCommandLineFactory $workerCommandLineFactory;

private ProcessCommand $processCommand;
Expand All @@ -37,6 +42,63 @@ protected function setUp(): void
$this->processCommand = $this->make(ProcessCommand::class);
}

/**
* @param array<string, mixed> $inputParameters
*/
#[DataProvider('provideDataSpacedMainScript')]
public function testSpacedMainScript(array $inputParameters, string $expectedCommand): void
{
$inputDefinition = $this->prepareProcessCommandDefinition();
$arrayInput = new ArrayInput($inputParameters, $inputDefinition);

$workerCommandLine = $this->workerCommandLineFactory->create(
self::SPACED_DUMMY_MAIN_SCRIPT,
ProcessCommand::class,
'worker',
$arrayInput,
'identifier',
2000
);

$this->assertSame($expectedCommand, $workerCommandLine);
}

/**
* @return Iterator<array<int, array<string, string|string[]|bool>>|string[]>
*/
public static function provideDataSpacedMainScript(): Iterator
{
$cliInputOptions = array_slice($_SERVER['argv'], 1);
$cliInputOptionsAsString = implode("' '", $cliInputOptions);

yield [
[
self::COMMAND => 'process',
Option::SOURCE => ['src'],
],
"'" . PHP_BINARY . "' '" . self::SPACED_DUMMY_MAIN_SCRIPT . "' '" . $cliInputOptionsAsString . "' worker --port 2000 --identifier 'identifier' 'src' --output-format 'json' --no-ansi",
];

yield [
[
self::COMMAND => 'process',
Option::SOURCE => ['src'],
'--' . Option::OUTPUT_FORMAT => ConsoleOutputFormatter::NAME,
],
"'" . PHP_BINARY . "' '" . self::SPACED_DUMMY_MAIN_SCRIPT . "' '" . $cliInputOptionsAsString . "' worker --port 2000 --identifier 'identifier' 'src' --output-format 'json' --no-ansi",
];

yield [
[
self::COMMAND => 'process',
Option::SOURCE => ['src'],
'--' . Option::OUTPUT_FORMAT => ConsoleOutputFormatter::NAME,
'--' . Option::DEBUG => true,
],
"'" . PHP_BINARY . "' '" . self::SPACED_DUMMY_MAIN_SCRIPT . "' '" . $cliInputOptionsAsString . "' worker --debug --port 2000 --identifier 'identifier' 'src' --output-format 'json' --no-ansi",
];
}

/**
* @param array<string, mixed> $inputParameters
*/
Expand Down
12 changes: 7 additions & 5 deletions packages/Parallel/Command/WorkerCommandLineFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Rector\ChangesReporting\Output\JsonOutputFormatter;
use Rector\Core\Configuration\Option;
use Rector\Core\FileSystem\FilePathHelper;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symplify\EasyParallel\Exception\ParallelShouldNotHappenException;
Expand All @@ -22,11 +23,11 @@ final class WorkerCommandLineFactory
*/
private const OPTION_DASHES = '--';

private readonly CommandFromReflectionFactory $commandFromReflectionFactory;

public function __construct()
public function __construct(
private readonly CommandFromReflectionFactory $commandFromReflectionFactory,
private readonly FilePathHelper $filePathHelper
)
{
$this->commandFromReflectionFactory = new CommandFromReflectionFactory();
}

/**
Expand Down Expand Up @@ -110,7 +111,8 @@ public function create(
*
* tested in macOS and Ubuntu (github action)
*/
$workerCommandArray[] = escapeshellarg((string) $input->getOption(Option::CONFIG));
$config = (string) $input->getOption(Option::CONFIG);
$workerCommandArray[] = escapeshellarg($this->filePathHelper->relativePath($config));
}

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