Skip to content

Commit

Permalink
Merge pull request #149 from DonCallisto/sf5
Browse files Browse the repository at this point in the history
Added Symfony 5 support
  • Loading branch information
DonCallisto committed Jun 10, 2020
2 parents ef64d09 + 8512f8e commit 95ffb81
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ before_script:

script:
- find tests/ -name "*Test.php" | php fastest -v
- ./fastest -x phpunit.xml.dist -v "bin/phpunit {};"
- ./fastest -x phpunit.xml.dist -v "bin/phpunit {}"
- bin/behat --config=adapters/Behat/behat.yml
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
],
"require": {
"php": "^7.2",
"symfony/console": "^3.4|^4.2",
"symfony/stopwatch": "^3.4|^4.2",
"symfony/process": "^3.4|^4.2",
"symfony/console": "^3.4|^4.2|^5.0",
"symfony/stopwatch": "^3.4|^4.2|^5.0",
"symfony/process": "^3.4|^4.2|^5.0",
"doctrine/collections": "^1.2"
},
"require-dev": {
Expand Down
9 changes: 4 additions & 5 deletions src/Process/ProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,17 @@ private function replaceParameters($cmd, $suite, $processNumber, $currentProcess
$commandToExecute = str_replace('{p}', $processNumber, $commandToExecute);
$commandToExecute = str_replace('{n}', $currentProcessCounter, $commandToExecute);

return $commandToExecute;
preg_match_all('#(?<!\\\\)("|\')(?:[^\\\\]|\\\\.)*?\1|\S+#s', $commandToExecute, $parsedCommand);

return $parsedCommand[0];
}

private function createProcess($executeCommand, $arrayEnv)
{
$process = new Process($executeCommand, null, $arrayEnv);

$process->setTimeout(null);
// compatibility to SF 2.2
if (method_exists($process, 'setIdleTimeout')) {
$process->setIdleTimeout(null);
}
$process->setIdleTimeout(null);

return $process;
}
Expand Down
13 changes: 12 additions & 1 deletion src/Process/ProcessorCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ private function readFromProcCPUInfo()
}
}
} elseif ('\\' === DIRECTORY_SEPARATOR) {
$process = new Process('for /F "tokens=2 delims==" %C in (\'wmic cpu get NumberOfLogicalProcessors /value ^| findstr NumberOfLogicalProcessors\') do @echo %C');
$command = [
'for',
'/F',
'"tokens=2 delims=="',
'%C',
'in',
"('wmic cpu get NumberOfLogicalProcessors /value ^| findstr NumberOfLogicalProcessors')",
'do',
'@echo',
'%C'
];
$process = new Process($command);
$process->run();

if ($process->isSuccessful() && ($numProc = (int) ($process->getOutput())) > 0) {
Expand Down
8 changes: 4 additions & 4 deletions tests/Process/ProcessFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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,
Expand All @@ -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);
Expand All @@ -63,7 +63,7 @@ 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,
Expand All @@ -87,7 +87,7 @@ 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,
Expand Down
6 changes: 3 additions & 3 deletions tests/Process/ProcessesManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function shouldCreateBeforeProcessesExecutingFactoryWithTheCorrectArgumen
$factory->expects($this->once())
->method('createAProcessForACustomCommand')
->with($this->anything(), $this->equalTo(1), $this->equalTo(1), $this->equalTo(true))
->willReturn(new Process('echo '.rand(), sys_get_temp_dir()));
->willReturn(new Process(['echo ', rand()], sys_get_temp_dir()));

$manager = new ProcessesManager($factory, 1, 'echo "ciao"');

Expand Down Expand Up @@ -57,7 +57,7 @@ public function shouldCreateProcessesWithoutBeforeProcessExecutingFactoryWithThe
$factory->expects($this->exactly(1))
->method('createAProcess')
->with($this->anything(), $this->equalTo(1), $this->equalTo(1), $this->equalTo(true))
->willReturn(new Process('echo ', rand()));
->willReturn(new Process(['echo '], rand()));

$manager = new ProcessesManager($factory, 1);

Expand Down Expand Up @@ -107,7 +107,7 @@ public function shouldCreate6ProcessesGivingThemTheCorrectEnvParameters()
$factory->expects($this->at($at))
->method('createAProcess')
->with($this->anything(), $this->equalTo($expectation[0]), $this->equalTo($expectation[1]), $this->equalTo($expectation[2]))
->willReturn(new Process('echo ', rand()));
->willReturn(new Process(['echo '], rand()));
}

$manager = new ProcessesManager($factory, 1);
Expand Down

0 comments on commit 95ffb81

Please sign in to comment.