Example #1
0
 /**
  * @dataProvider nonBlockingProvider
  *
  * @param $timeout
  * @param bool $wait
  * @param bool $finish
  * @param string $output
  * @param string $expectedOutput
  */
 public function testNonBlocking($timeout, $wait, $finish, $output, $expectedOutput)
 {
     $this->pid->shouldReceive("getPid")->withArgs([true])->andThrow("Silktide\\Teamster\\Exception\\PidException");
     $this->pid->shouldReceive("cleanPid")->once()->andReturn(true);
     // seems we need to use a real file and can't mock the filesystem
     $outFile = __DIR__ . "/output/output";
     $spec = $this->setupOutFile($outFile);
     // setup command
     $command = "php -r \"\\\$s = microtime(true); do {usleep({$timeout} / 4);} while (microtime(true) - \\\$s < {$timeout} / 1000000); echo '{$output}';\"";
     // do the test
     $runner = new ProcessRunner($this->pidFactory, $spec, "dud", 1, 5, 5);
     $runner->execute($command, false);
     $this->assertTrue($runner->isRunning($this->pid));
     if ($wait) {
         usleep($timeout * 2);
     }
     if ($finish) {
         $runner->finish($this->pid);
     }
     $this->assertFalse($runner->isRunning($this->pid));
     $this->assertEquals($expectedOutput, file_get_contents($outFile));
 }
Example #2
0
 /**
  * @param string $command
  * @param bool $block
  */
 public function execute($command, $block = true)
 {
     $consoleCommand = "php {$this->consolePath} {$command}";
     parent::execute($consoleCommand, $block);
 }