From 7c052de28a713ad776305e8e9348e413fe8533d1 Mon Sep 17 00:00:00 2001 From: DonCallisto Date: Fri, 12 Jun 2020 15:08:05 +0200 Subject: [PATCH] Fixed input command args parsing --- src/Process/ProcessFactory.php | 11 +++--- src/Process/ProcessorCounter.php | 19 ++++------- tests/Process/ProcessFactoryTest.php | 50 ++++++++++++++-------------- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/Process/ProcessFactory.php b/src/Process/ProcessFactory.php index 044b8c0..be6bb3e 100644 --- a/src/Process/ProcessFactory.php +++ b/src/Process/ProcessFactory.php @@ -47,14 +47,17 @@ private function replaceParameters($cmd, $suite, $processNumber, $currentProcess $commandToExecute = str_replace('{p}', $processNumber, $commandToExecute); $commandToExecute = str_replace('{n}', $currentProcessCounter, $commandToExecute); - preg_match_all('#(?setTimeout(null); $process->setIdleTimeout(null); diff --git a/src/Process/ProcessorCounter.php b/src/Process/ProcessorCounter.php index 4d0535f..22bf2f5 100644 --- a/src/Process/ProcessorCounter.php +++ b/src/Process/ProcessorCounter.php @@ -50,18 +50,13 @@ private function readFromProcCPUInfo() } } } elseif ('\\' === DIRECTORY_SEPARATOR) { - $command = [ - 'for', - '/F', - '"tokens=2 delims=="', - '%C', - 'in', - "('wmic cpu get NumberOfLogicalProcessors /value ^| findstr NumberOfLogicalProcessors')", - 'do', - '@echo', - '%C' - ]; - $process = new Process($command); + $executeCommand = 'for /F "tokens=2 delims==" %C in (\'wmic cpu get NumberOfLogicalProcessors /value ^| findstr NumberOfLogicalProcessors\') do @echo %C'; + if (method_exists(Process::class, 'fromShellCommandline')) { + $process = Process::fromShellCommandline($executeCommand); + } else { + // Drop when sf 3.4 supports ends + $process = new Process($executeCommand); + } $process->run(); if ($process->isSuccessful() && ($numProc = (int) ($process->getOutput())) > 0) { diff --git a/tests/Process/ProcessFactoryTest.php b/tests/Process/ProcessFactoryTest.php index 777110e..a44ff6a 100644 --- a/tests/Process/ProcessFactoryTest.php +++ b/tests/Process/ProcessFactoryTest.php @@ -16,16 +16,16 @@ public function shouldCreateACommandUsingParallelTests() $serverEnvs = EnvCommandCreator::cleanEnvVariables($_SERVER); unset($serverEnvs['argv']); - $this->assertEquals("'bin".DIRECTORY_SEPARATOR."phpunit' 'fileA'", $process->getCommandLine()); + $this->assertEquals('bin'.DIRECTORY_SEPARATOR.'phpunit fileA', $process->getCommandLine()); $this->assertEquals( $this->castValues(array_change_key_case($serverEnvs + $_ENV + [ - 'ENV_TEST_CHANNEL' => 2, - 'ENV_TEST_CHANNEL_READABLE' => 'test_2', - 'ENV_TEST_CHANNELS_NUMBER' => 10, - 'ENV_TEST_ARGUMENT' => 'fileA', - 'ENV_TEST_INC_NUMBER' => 10, - 'ENV_TEST_IS_FIRST_ON_CHANNEL' => 1, - ], CASE_UPPER)), + 'ENV_TEST_CHANNEL' => 2, + 'ENV_TEST_CHANNEL_READABLE' => 'test_2', + 'ENV_TEST_CHANNELS_NUMBER' => 10, + 'ENV_TEST_ARGUMENT' => 'fileA', + 'ENV_TEST_INC_NUMBER' => 10, + 'ENV_TEST_IS_FIRST_ON_CHANNEL' => 1, + ], CASE_UPPER)), $this->castValues($process->getenv()) ); } @@ -38,7 +38,7 @@ public function shouldCreateACommandUsingParallelTestsWithFilteredVariables() $factory = new ProcessFactory(10); $process = $factory->createAProcess('fileA', 2, 10, true); - $this->assertEquals("'bin".DIRECTORY_SEPARATOR."phpunit' 'fileA'", $process->getCommandLine()); + $this->assertEquals('bin'.DIRECTORY_SEPARATOR.'phpunit fileA', $process->getCommandLine()); $processEnv = $process->getEnv(); $envTestVars = $this->filterEnvTestVariables($processEnv); @@ -63,16 +63,16 @@ public function shouldCreateACommandUsingParallelTestsWithOptions() $serverEnvs = EnvCommandCreator::cleanEnvVariables($_SERVER); unset($serverEnvs['argv']); - $this->assertEquals("'execute'", $process->getCommandLine()); + $this->assertEquals('execute', $process->getCommandLine()); $this->assertEquals( $this->castValues(array_change_key_case($serverEnvs + $_ENV + [ - 'ENV_TEST_CHANNEL' => 2, - 'ENV_TEST_CHANNEL_READABLE' => 'test_2', - 'ENV_TEST_CHANNELS_NUMBER' => 11, - 'ENV_TEST_ARGUMENT' => 'fileA', - 'ENV_TEST_INC_NUMBER' => 12, - 'ENV_TEST_IS_FIRST_ON_CHANNEL' => 0, - ], CASE_UPPER)), + 'ENV_TEST_CHANNEL' => 2, + 'ENV_TEST_CHANNEL_READABLE' => 'test_2', + 'ENV_TEST_CHANNELS_NUMBER' => 11, + 'ENV_TEST_ARGUMENT' => 'fileA', + 'ENV_TEST_INC_NUMBER' => 12, + 'ENV_TEST_IS_FIRST_ON_CHANNEL' => 0, + ], CASE_UPPER)), $this->castValues($process->getenv()) ); } @@ -87,16 +87,16 @@ public function shouldReplaceThePlaceholder() $serverEnvs = EnvCommandCreator::cleanEnvVariables($_SERVER); unset($serverEnvs['argv']); - $this->assertEquals("'execute' '1' 'fileA' '13'", $process->getCommandLine()); + $this->assertEquals('execute 1 fileA 13', $process->getCommandLine()); $this->assertEquals( $this->castValues(array_change_key_case($serverEnvs + $_ENV + [ - 'ENV_TEST_CHANNEL' => 1, - 'ENV_TEST_CHANNEL_READABLE' => 'test_1', - 'ENV_TEST_CHANNELS_NUMBER' => 12, - 'ENV_TEST_ARGUMENT' => 'fileA', - 'ENV_TEST_INC_NUMBER' => 13, - 'ENV_TEST_IS_FIRST_ON_CHANNEL' => 1, - ], CASE_UPPER)), + 'ENV_TEST_CHANNEL' => 1, + 'ENV_TEST_CHANNEL_READABLE' => 'test_1', + 'ENV_TEST_CHANNELS_NUMBER' => 12, + 'ENV_TEST_ARGUMENT' => 'fileA', + 'ENV_TEST_INC_NUMBER' => 13, + 'ENV_TEST_IS_FIRST_ON_CHANNEL' => 1, + ], CASE_UPPER)), $this->castValues($process->getenv()) ); }