Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bug #16574 [Process] Fix PhpProcess with phpdbg runtime (nicolas-grekas)
This PR was merged into the 2.3 branch.

Discussion
----------

[Process] Fix PhpProcess with phpdbg runtime

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

With this PR, I'm able to successfully run the test suite of the Process component using
`phpdbg -qrr ./phpunit src/Symfony/Component/Process/`

Commits
-------

9669238 [Process] Fix PhpProcess with phpdbg runtime
  • Loading branch information
nicolas-grekas committed Nov 18, 2015
2 parents 6f72d63 + 9669238 commit a05e73f
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -70,7 +70,7 @@
"monolog/monolog": "~1.3",
"propel/propel1": "~1.6",
"ircmaxell/password-compat": "~1.0",
"zendframework/zend-stdlib": "~2.5",
"zendframework/zend-stdlib": "~2.2",
"ocramius/proxy-manager": "~0.3.1"
},
"autoload": {
Expand Down
10 changes: 6 additions & 4 deletions phpunit
Expand Up @@ -11,7 +11,7 @@
*/

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

use Symfony\Component\Process\ProcessUtils;

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

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

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

$oldPwd = getcwd();
Expand All @@ -49,7 +52,6 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
$zip->close();
chdir("phpunit-$PHPUNIT_VERSION");
passthru("$COMPOSER remove --no-update symfony/yaml");
passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"<=3.0.0\"");
passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=2.8@dev\"");
passthru("$COMPOSER install --prefer-source --no-progress --ansi");
file_put_contents('phpunit', <<<EOPHP
Expand All @@ -66,7 +68,7 @@ EOPHP
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")));
symlink(realpath('../src/Symfony/Bridge/PhpUnit'), "phpunit-$PHPUNIT_VERSION/vendor/symfony/phpunit-bridge");
}
file_put_contents('.md5', md5_file(__FILE__));
file_put_contents(".$PHPUNIT_VERSION.md5", md5_file(__FILE__));
chdir($oldPwd);

}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/ProxyManager/composer.json
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=5.3.3",
"symfony/dependency-injection": "~2.3",
"zendframework/zend-stdlib": "~2.5",
"zendframework/zend-stdlib": "~2.2",
"ocramius/proxy-manager": "~0.3.1"
},
"require-dev": {
Expand Down
7 changes: 4 additions & 3 deletions src/Symfony/Component/Process/PhpExecutableFinder.php
Expand Up @@ -41,8 +41,8 @@ public function find($includeArgs = true)
}

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

if ($php = getenv('PHP_PATH')) {
Expand Down Expand Up @@ -76,9 +76,10 @@ public function findArguments()
{
$arguments = array();

// HHVM support
if (defined('HHVM_VERSION')) {
$arguments[] = '--php';
} elseif ('phpdbg' === PHP_SAPI) {
$arguments[] = '-qrr';
}

return $arguments;
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/Process/PhpProcess.php
Expand Up @@ -39,6 +39,13 @@ public function __construct($script, $cwd = null, array $env = null, $timeout =
if (false === $php = $executableFinder->find()) {
$php = null;
}
if ('phpdbg' === PHP_SAPI) {
$file = tempnam(sys_get_temp_dir(), 'dbg');
file_put_contents($file, $script);
register_shutdown_function('unlink', $file);
$php .= ' '.ProcessUtils::escapeArgument($file);
$script = null;
}

parent::__construct($php, $cwd, $env, $script, $timeout, $options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/Process.php
Expand Up @@ -242,7 +242,7 @@ public function start($callback = null)
if (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
// Workaround for the bug, when PTS functionality is enabled.
// @see : https://bugs.php.net/69442
$ptsWorkaround = fopen('php://fd/0', 'r');
$ptsWorkaround = fopen(__FILE__, 'r');
}

$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $this->env, $this->options);
Expand Down
20 changes: 4 additions & 16 deletions src/Symfony/Component/Process/Tests/AbstractProcessTest.php
Expand Up @@ -27,7 +27,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
$phpBin = new PhpExecutableFinder();
self::$phpBin = $phpBin->find();
self::$phpBin = 'phpdbg' === PHP_SAPI ? 'php' : $phpBin->find();
}

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

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

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

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

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

public function testPhpDeadlock()
{
$this->markTestSkipped('Can cause PHP to hang');

// Sleep doesn't work as it will allow the process to handle signals and close
// file handles from the other end.
$process = $this->getProcess(self::$phpBin.' -r "while (true) {}"');
$process->start();

// PHP will deadlock when it tries to cleanup $process
}

public function testRunProcessWithTimeout()
{
$timeout = 0.5;
Expand Down
Expand Up @@ -68,6 +68,8 @@ public function testFindArguments()

if (defined('HHVM_VERSION')) {
$this->assertEquals($f->findArguments(), array('--php'), '::findArguments() returns HHVM arguments');
} elseif ('phpdbg' === PHP_SAPI) {
$this->assertEquals($f->findArguments(), array('-qrr'), '::findArguments() returns phpdbg arguments');
} else {
$this->assertEquals($f->findArguments(), array(), '::findArguments() returns no arguments');
}
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Process/Tests/PhpProcessTest.php
Expand Up @@ -30,6 +30,10 @@ public function testNonBlockingWorks()

public function testCommandLine()
{
if ('phpdbg' === PHP_SAPI) {
$this->markTestSkipped('phpdbg SAPI is not supported by this test.');
}

$process = new PhpProcess(<<<PHP
<?php echo 'foobar';
PHP
Expand Down

0 comments on commit a05e73f

Please sign in to comment.