Skip to content

Commit

Permalink
[Test] Clean up test on WorkerCommandLineFactoryTest (#6714)
Browse files Browse the repository at this point in the history
* [Test] Clean up test on WorkerCommandLineFactoryTest

* rename private method

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
samsonasik and actions-user authored Feb 3, 2025
1 parent 8f5ac73 commit fe3b78a
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions tests/Parallel/Command/WorkerCommandLineFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,8 @@ public function testSpacedMainScript(array $inputParameters, string $expectedCom
2000
);

// running on macOS cause empty string after SPACED_DUMMY_MAIN_SCRIPT constant value removed on run whole unit test
// this ensure it works
$workerCommandLine = str_replace("rector' worker", "rector' '' worker", $workerCommandLine);

if (strncasecmp(PHP_OS, 'WIN', 3) === 0) {
$expectedCommand = str_replace("'", '"', $expectedCommand);
$workerCommandLine = str_replace("'", '"', $workerCommandLine);
}
$expectedCommand = $this->normalizeExpectedCommandOutput($expectedCommand);
$expectedCommand = $this->cleanUpEmptyQuoteExpectedCommandOutput($expectedCommand);

$this->assertSame($expectedCommand, $workerCommandLine);
}
Expand Down Expand Up @@ -137,14 +131,8 @@ public function test(array $inputParameters, string $expectedCommand): void
2000
);

// running on macOS cause empty string after main_script removed on run whole unit test
// this ensure it works
$workerCommandLine = str_replace("'main_script' worker", "'main_script' '' worker", $workerCommandLine);

if (strncasecmp(PHP_OS, 'WIN', 3) === 0) {
$expectedCommand = str_replace("'", '"', $expectedCommand);
$workerCommandLine = str_replace("'", '"', $workerCommandLine);
}
$expectedCommand = $this->normalizeExpectedCommandOutput($expectedCommand);
$expectedCommand = $this->cleanUpEmptyQuoteExpectedCommandOutput($expectedCommand);

$this->assertSame($expectedCommand, $workerCommandLine);
}
Expand Down Expand Up @@ -206,6 +194,24 @@ public static function provideData(): Iterator
];
}

private function cleanUpEmptyQuoteExpectedCommandOutput(string $result): string
{
if (strncasecmp(PHP_OS, 'WIN', 3) === 0) {
return str_replace(' "" ', ' ', $result);
}

return str_replace(" '' ", ' ', $result);
}

private function normalizeExpectedCommandOutput(string $command): string
{
if (strncasecmp(PHP_OS, 'WIN', 3) === 0) {
return str_replace("'", '"', $command);
}

return $command;
}

private function prepareProcessCommandDefinition(): InputDefinition
{
// clone the object as we should not modify a object taken from the DI container
Expand Down

0 comments on commit fe3b78a

Please sign in to comment.