8000 [Process] Fix PhpProcess with phpdbg runtime · symfony/symfony@107fd3e · GitHub
[go: up one dir, main page]

Skip to content

Commit 107fd3e

Browse files
[Process] Fix PhpProcess with phpdbg runtime
1 parent c0f7463 commit 107fd3e

File tree

7 files changed

+28
-23
lines changed
  • 7 files changed

    +28
    -23
    lines changed

    phpunit

    Lines changed: 6 additions & 3 deletions
    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-17 16:20 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();
    @@ -66,7 +69,7 @@ EOPHP
    6669
    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")));
    6770
    symlink(realpath('../src/Symfony/Bridge/PhpUnit'), "phpunit-$PHPUNIT_VERSION/vendor/symfony/phpunit-bridge");
    6871
    }
    69-
    file_put_contents('.md5', md5_file(__FILE__));
    72+
    file_put_contents(".$PHPUNIT_VERSION.md5", md5_file(__FILE__));
    7073
    chdir($oldPwd);
    7174

    7275
    }

    src/Symfony/Component/Process/PhpExecutableFinder.php

    Lines changed: 4 additions & 3 deletions
    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

    Lines changed: 7 additions & 0 deletions
    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

    Lines changed: 1 addition & 1 deletion
    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

    Lines changed: 4 additions & 16 deletions
    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

    Lines changed: 2 additions & 0 deletions
    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

    Lines changed: 4 additions & 0 deletions
    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)
    0