You are here

public function AbstractProcessTest::testGetEmptyIncrementalOutput in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/process/Tests/AbstractProcessTest.php \Symfony\Component\Process\Tests\AbstractProcessTest::testGetEmptyIncrementalOutput()

File

vendor/symfony/process/Tests/AbstractProcessTest.php, line 408

Class

AbstractProcessTest
@author Robert Schönthal <seroscho@googlemail.com>

Namespace

Symfony\Component\Process\Tests

Code

public function testGetEmptyIncrementalOutput() {

  // use a lock file to toggle between writing ("W") and reading ("R") the
  // output stream
  $lock = tempnam(sys_get_temp_dir(), get_class($this) . 'Lock');
  file_put_contents($lock, 'W');
  $p = $this
    ->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { if (\'W\' === file_get_contents(' . var_export($lock, true) . ')) { echo \' foo \'; $n++; file_put_contents(' . var_export($lock, true) . ', \'R\'); } usleep(100); }')));
  $p
    ->start();
  $shouldWrite = false;
  while ($p
    ->isRunning()) {
    if ('R' === file_get_contents($lock)) {
      if (!$shouldWrite) {
        $this
          ->assertLessThanOrEqual(1, preg_match_all('/foo/', $p
          ->getIncrementalOutput(), $matches));
        $shouldWrite = true;
      }
      else {
        $this
          ->assertSame('', $p
          ->getIncrementalOutput());
        file_put_contents($lock, 'W');
        $shouldWrite = false;
      }
    }
    usleep(100);
  }
  unlink($lock);
}