Skip to content

Commit 072c3bf

Browse files
Michaël DupontDE TROOSTEMBERGH Antoine
authored andcommitted
fix: PHPUnit test Process() format
\Symfony\Component\Process\Process refuses being passed a string with version > 5, which is installed with PHP > 7.2.5. It also refuses being passed an array with version < 3.3, which is installed with PHP < 5.5.9. Solved by checking if Process::fromShellCommandLine() exists, which was introduced in version 4.2.0.
1 parent d423e9b commit 072c3bf

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,26 @@ abstract class AbstractWebServerEmbeddedTest extends \PHPUnit\Framework\TestCase
2626
public static function setUpBeforeClass()
2727
{
2828
if (self::isBuiltinServerSupported()) {
29-
self::$httpServer = new Process('php -S localhost:8080 -t tests/PhpWord/_files');
29+
$commandLine = 'php -S localhost:8080 -t tests/PhpWord/_files';
30+
31+
/*
32+
* Make sure to invoke \Symfony\Component\Process\Process correctly
33+
* regardless of PHP version used.
34+
*
35+
* In Process version >= 5 / PHP >= 7.2.5, the constructor requires
36+
* an array, while in version < 3.3 / PHP < 5.5.9 it requires a string.
37+
* In between, it can accept both.
38+
*
39+
* Process::fromShellCommandLine() was introduced in version 4.2.0,
40+
* to enable recent versions of Process to parse a command string,
41+
* so if it is not available it means it is still possible to pass
42+
* a string to the constructor.
43+
*/
44+
if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandLine')) {
45+
self::$httpServer = Process::fromShellCommandline($commandLine);
46+
} else {
47+
self::$httpServer = new Process($commandLine);
48+
}
3049
self::$httpServer->start();
3150
while (!self::$httpServer->isRunning()) {
3251
usleep(1000);

0 commit comments

Comments
 (0)