public function testNonBlockingWorks() { $expected = 'hello world!'; $process = new PhpProcess(<<<PHP <?php echo '{$expected}'; PHP ); $process->start(); $process->wait(); $this->assertEquals($expected, $process->getOutput()); }
public function testCommandLine() { $process = new PhpProcess(<<<'PHP' <?php echo 'foobar'; PHP ); $commandLine = $process->getCommandLine(); $f = new PhpExecutableFinder(); $this->assertContains($f->find(), $commandLine, '::getCommandLine() returns the command line of PHP before start'); $process->start(); $this->assertContains($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after start'); $process->wait(); $this->assertContains($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after wait'); }
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 ); $f = new PhpExecutableFinder(); $commandLine = $f->find(); $this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP before start'); $process->start(); $this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after start'); $process->wait(); $this->assertSame($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after wait'); }
/** * @medium * @dataProvider backends */ public function testCompressEventsKate($backend) { // CREATE web.scssdx1493.new // MODIFY web.scssdx1493.new // MOVED_FROM web.scssdx1493.new // MOVED_TO web.scss if (!$backend->isAvailable()) { $this->markTestSkipped(); } $f = __DIR__ . '/test/'; sleep(1); $php = "<?php sleep(2);\n file_put_contents('{$f}foo.txtdx1493.new', 'x');\n rename('{$f}foo.txtdx1493.new', '{$f}foo.txt');\n\n file_put_contents('{$f}stop.txt', 'x');\n "; $process = new PhpProcess($php); $process->start(); $gotEvents = array(); $backend->setPath(__DIR__ . '/test'); $backend->addListener(ModifyEvent::NAME, function ($e) use(&$gotEvents, $backend) { $gotEvents[] = 'modify'; }); $backend->addListener(CreateEvent::NAME, function ($e) use(&$gotEvents, $backend) { if ($e->filename == __DIR__ . '/test/stop.txt') { $backend->stop(); } else { $gotEvents[] = 'create'; } }); $backend->addListener(DeleteEvent::NAME, function ($e) use(&$gotEvents, $backend) { $gotEvents[] = 'delete'; }); $backend->addListener(MoveEvent::NAME, function ($e) use(&$gotEvents, $backend) { $gotEvents[] = 'move'; }); $backend->start(); $process->wait(); $this->assertTrue($process->isSuccessful()); $this->assertEquals($gotEvents, array('modify')); }
/** * Waits for the process to terminate. * * The callback receives the type of output (out or err) and some bytes * from the output in real-time while writing the standard input to the process. * It allows to have feedback from the independent process during execution. * * @param callable|null $callback A valid PHP callback * * @throws RuntimeException When process timed out * @throws RuntimeException When process stopped after receiving signal * @throws LogicException When process is not yet started * * @return int The returnValue of the Closure */ public function wait($callback = null) { parent::wait($callback); return $this->getReturnValue(); }