Skip to content

Commit 9669238

Browse files
[Process] Fix PhpProcess with phpdbg runtime
1 parent 6f72d63 commit 9669238

9 files changed

+30
-26
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"monolog/monolog": "~1.3",
7171
"propel/propel1": "~1.6",
7272
"ircmaxell/password-compat": "~1.0",
73-
"zendframework/zend-stdlib": "~2.5",
73+
"zendframework/zend-stdlib": "~2.2",
7474
"ocramius/proxy-manager": "~0.3.1"
7575
},
7676
"autoload": {

phpunit

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
// Please update when phpunit needs to be reinstalled with fresh deps:
14-
// Cache-Id-Version: 2015-11-09 12:13 UTC
14+
// Cache-Id-Version: 2015-11-18 14:14 UTC
1515

1616
use Symfony\Component\Process\ProcessUtils;
1717

@@ -23,12 +23,15 @@ $PHPUNIT_VERSION = PHP_VERSION_ID >= 70000 ? '5.0' : '4.8';
2323
$PHPUNIT_DIR = __DIR__.'/.phpunit';
2424
$PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php';
2525
$PHP = ProcessUtils::escapeArgument($PHP);
26+
if ('phpdbg' === PHP_SAPI) {
27+
$PHP .= ' -qrr';
28+
}
2629

2730
$COMPOSER = file_exists($COMPOSER = __DIR__.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? `where.exe composer.phar` : `which composer.phar`))
2831
? $PHP.' '.ProcessUtils::escapeArgument($COMPOSER)
2932
: 'composer';
3033

31-
if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__FILE__) !== @file_get_contents("$PHPUNIT_DIR/.md5")) {
34+
if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__FILE__) !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION.md5")) {
3235
// Build a standalone phpunit without symfony/yaml
3336

3437
$oldPwd = getcwd();
@@ -49,7 +52,6 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
4952
$zip->close();
5053
chdir("phpunit-$PHPUNIT_VERSION");
5154
passthru("$COMPOSER remove --no-update symfony/yaml");
52-
passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"<=3.0.0\"");
5355
passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=2.8@dev\"");
5456
passthru("$COMPOSER install --prefer-source --no-progress --ansi");
5557
file_put_contents('phpunit', <<<EOPHP
@@ -66,7 +68,7 @@ EOPHP
6668
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', str_replace('/', DIRECTORY_SEPARATOR, "phpunit-$PHPUNIT_VERSION/vendor/symfony/phpunit-bridge")));
6769
symlink(realpath('../src/Symfony/Bridge/PhpUnit'), "phpunit-$PHPUNIT_VERSION/vendor/symfony/phpunit-bridge");
6870
}
69-
file_put_contents('.md5', md5_file(__FILE__));
71+
file_put_contents(".$PHPUNIT_VERSION.md5", md5_file(__FILE__));
7072
chdir($oldPwd);
7173

7274
}

src/Symfony/Bridge/ProxyManager/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=5.3.3",
2020
"symfony/dependency-injection": "~2.3",
21-
"zendframework/zend-stdlib": "~2.5",
21+
"zendframework/zend-stdlib": "~2.2",
2222
"ocramius/proxy-manager": "~0.3.1"
2323
},
2424
"require-dev": {

src/Symfony/Component/Process/PhpExecutableFinder.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function find($includeArgs = true)
4141
}
4242

4343
// PHP_BINARY return the current sapi executable
44-
if (defined('PHP_BINARY') && PHP_BINARY && in_array(PHP_SAPI, array('cli', 'cli-server')) && is_file(PHP_BINARY)) {
45-
return PHP_BINARY;
44+
if (defined('PHP_BINARY') && PHP_BINARY && in_array(PHP_SAPI, array('cli', 'cli-server', 'phpdbg')) && is_file(PHP_BINARY)) {
45+
return PHP_BINARY.($includeArgs ? ' '.implode(' ', $this->findArguments()) : '');
4646
}
4747

4848
if ($php = getenv('PHP_PATH')) {
@@ -76,9 +76,10 @@ public function findArguments()
7676
{
7777
$arguments = array();
7878

79-
// HHVM support
8079
if (defined('HHVM_VERSION')) {
8180
$arguments[] = '--php';
81+
} elseif ('phpdbg' === PHP_SAPI) {
82+
$arguments[] = '-qrr';
8283
}
8384

8485
return $arguments;

src/Symfony/Component/Process/PhpProcess.php

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ public function __construct($script, $cwd = null, array $env = null, $timeout =
3939
if (false === $php = $executableFinder->find()) {
4040
$php = null;
4141
}
42+
if ('phpdbg' === PHP_SAPI) {
43+
$file = tempnam(sys_get_temp_dir(), 'dbg');
44+
file_put_contents($file, $script);
45+
register_shutdown_function('unlink', $file);
46+
$php .= ' '.ProcessUtils::escapeArgument($file);
47+
$script = null;
48+
}
4249

4350
parent::__construct($php, $cwd, $env, $script, $timeout, $options);
4451
}

src/Symfony/Component/Process/Process.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public function start($callback = null)
242242
if (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
243243
// Workaround for the bug, when PTS functionality is enabled.
244244
// @see : https://bugs.php.net/69442
245-
$ptsWorkaround = fopen('php://fd/0', 'r');
245+
$ptsWorkaround = fopen(__FILE__, 'r');
246246
}
247247

248248
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $this->env, $this->options);

src/Symfony/Component/Process/Tests/AbstractProcessTest.php

+4-16
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
2727
public static function setUpBeforeClass()
2828
{
2929
$phpBin = new PhpExecutableFinder();
30-
self::$phpBin = $phpBin->find();
30+
self::$phpBin = 'phpdbg' === PHP_SAPI ? 'php' : $phpBin->find();
3131
}
3232

3333
public function testThatProcessDoesNotThrowWarningDuringRun()
@@ -80,7 +80,7 @@ public function testStopWithTimeoutIsActuallyWorking()
8080
// exec is mandatory here since we send a signal to the process
8181
// see https://github.com/symfony/symfony/issues/5030 about prepending
8282
// command with exec
83-
$p = $this->getProcess('exec php '.__DIR__.'/NonStopableProcess.php 3');
83+
$p = $this->getProcess('exec '.self::$phpBin.' '.__DIR__.'/NonStopableProcess.php 3');
8484
$p->start();
8585
usleep(100000);
8686
$start = microtime(true);
@@ -410,7 +410,7 @@ public function testTTYCommand()
410410
$this->markTestSkipped('Windows does have /dev/tty support');
411411
}
412412

413-
$process = $this->getProcess('echo "foo" >> /dev/null && php -r "usleep(100000);"');
413+
$process = $this->getProcess('echo "foo" >> /dev/null && '.self::$phpBin.' -r "usleep(100000);"');
414414
$process->setTty(true);
415415
$process->start();
416416
$this->assertTrue($process->isRunning());
@@ -633,7 +633,7 @@ public function testProcessThrowsExceptionWhenExternallySignaled()
633633

634634
$termSignal = defined('SIGKILL') ? SIGKILL : 9;
635635

636-
$process = $this->getProcess('exec php -r "while (true) {}"');
636+
$process = $this->getProcess('exec '.self::$phpBin.' -r "while (true) {}"');
637637
$process->start();
638638
posix_kill($process->getPid(), $termSignal);
639639

@@ -659,18 +659,6 @@ public function testRestart()
659659
$this->assertNotEquals($process1->getOutput(), $process2->getOutput());
660660
}
661661

662-
public function testPhpDeadlock()
663-
{
664-
$this->markTestSkipped('Can cause PHP to hang');
665-
666-
// Sleep doesn't work as it will allow the process to handle signals and close
667-
// file handles from the other end.
668-
$process = $this->getProcess(self::$phpBin.' -r "while (true) {}"');
669-
$process->start();
670-
671-
// PHP will deadlock when it tries to cleanup $process
672-
}
673-
674662
public function testRunProcessWithTimeout()
675663
{
676664
$timeout = 0.5;

src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public function testFindArguments()
6868

6969
if (defined('HHVM_VERSION')) {
7070
$this->assertEquals($f->findArguments(), array('--php'), '::findArguments() returns HHVM arguments');
71+
} elseif ('phpdbg' === PHP_SAPI) {
72+
$this->assertEquals($f->findArguments(), array('-qrr'), '::findArguments() returns phpdbg arguments');
7173
} else {
7274
$this->assertEquals($f->findArguments(), array(), '::findArguments() returns no arguments');
7375
}

src/Symfony/Component/Process/Tests/PhpProcessTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public function testNonBlockingWorks()
3030

3131
public function testCommandLine()
3232
{
33+
if ('phpdbg' === PHP_SAPI) {
34+
$this->markTestSkipped('phpdbg SAPI is not supported by this test.');
35+
}
36+
3337
$process = new PhpProcess(<<<PHP
3438
<?php echo 'foobar';
3539
PHP

0 commit comments

Comments
 (0)