コード例 #1
0
 public function testFromProcessUsesStdOutputIfErrorOutputEmpty()
 {
     $process = $this->getMockBuilder(Process::class)->disableOriginalConstructor()->getMock();
     $process->expects($this->exactly(1))->method('getErrorOutput')->will($this->returnValue(''));
     $process->expects($this->exactly(1))->method('getOutput')->will($this->returnValue('Std Output'));
     $e = CodeExecutionException::fromProcess($process);
     $this->assertEquals('PHP Code failed to execute. Error: "Std Output"', $e->getMessage());
 }
コード例 #2
0
ファイル: CliRunner.php プロジェクト: jacmoe/php-workshop
 /**
  * @param string $fileName
  * @param ArrayObject $args
  * @param string $type
  * @return string
  */
 private function executePhpFile($fileName, ArrayObject $args, $type)
 {
     $process = $this->getPhpProcess($fileName, $args);
     $process->start();
     $this->eventDispatcher->dispatch(new CliExecuteEvent(sprintf('cli.verify.%s.executing', $type), $args));
     $process->wait();
     if (!$process->isSuccessful()) {
         throw CodeExecutionException::fromProcess($process);
     }
     return $process->getOutput();
 }
コード例 #3
0
ファイル: CgiRunner.php プロジェクト: php-school/php-workshop
 /**
  * @param string $fileName
  * @param RequestInterface $request
  * @param string $type
  * @return ResponseInterface
  */
 private function executePhpFile($fileName, RequestInterface $request, $type)
 {
     $process = $this->getProcess($fileName, $request);
     $process->start();
     $this->eventDispatcher->dispatch(new CgiExecuteEvent(sprintf('cgi.verify.%s.executing', $type), $request));
     $process->wait();
     if (!$process->isSuccessful()) {
         throw CodeExecutionException::fromProcess($process);
     }
     //if no status line, pre-pend 200 OK
     $output = $process->getOutput();
     if (!preg_match('/^HTTP\\/([1-9]\\d*\\.\\d) ([1-5]\\d{2})(\\s+(.+))?\\r\\n/', $output)) {
         $output = "HTTP/1.0 200 OK\r\n" . $output;
     }
     return ResponseSerializer::fromString($output);
 }