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()); }
/** * @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(); }
/** * @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); }
/** * Static constructor to create from a `PhpSchool\PhpWorkshop\Exception\CodeExecutionException` exception. * * @param RequestInterface $request The request that caused the failure. * @param CodeExecutionException $e The exception. * @return static The result. */ public static function fromRequestAndCodeExecutionFailure(RequestInterface $request, CodeExecutionException $e) { return new static($request, $e->getMessage()); }
/** * @param string $name * @param CodeExecutionException $e * @return static */ public static function fromNameAndCodeExecutionFailure($name, CodeExecutionException $e) { return new static($name, $e->getMessage()); }
/** * Static constructor to create from a `PhpSchool\PhpWorkshop\Exception\CodeExecutionException` exception. * * @param ArrayObject $args The arguments that caused the failure. * @param CodeExecutionException $e The exception. * @return static The result. */ public static function fromArgsAndCodeExecutionFailure(ArrayObject $args, CodeExecutionException $e) { return new static($args, $e->getMessage()); }