protected function request(Code $code)
 {
     $file = $this->createTemporaryFile();
     $this->logger->info(sprintf('FastCGI: Dumped code to file: %s', $file));
     try {
         $code->writeTo($file);
         $environment = array('REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/', 'SCRIPT_FILENAME' => $file);
         $response = $this->client->request($environment, '');
         $this->logger->debug(sprintf('FastCGI: Response: %s', json_encode($response)));
         @unlink($file);
         return $response;
     } catch (\Exception $e) {
         @unlink($file);
         throw new \RuntimeException(sprintf('FastCGI error: %s', $e->getMessage()), $e->getCode());
     }
 }
Beispiel #2
0
 /**
  * @expectedException RuntimeException
  */
 public function testException()
 {
     $cli = new Cli();
     $cli->setTempDir(sys_get_temp_dir());
     $cli->setLogger($this->getMockBuilder('Monolog\\Logger')->disableOriginalConstructor()->getMock());
     $code = Code::fromString('throw new \\Exception("test");');
     $result = $cli->run($code);
 }
 /**
  * @param  Code   $code
  * @throws \RuntimeException
  * @return mixed
  */
 public function run(Code $code)
 {
     $this->logger->debug(sprintf('Executing code: %s', $code->getCode()));
     $data = $this->doRun($code);
     $result = @unserialize($data);
     if (!is_array($result)) {
         $this->logger->debug(sprintf('Return serialized: %s', $data));
         throw new \RuntimeException('Could not unserialize data from adapter.');
     }
     $this->logger->debug(sprintf('Return errors: %s', json_encode($result['errors'])));
     $this->logger->debug(sprintf('Return result: %s', json_encode($result['result'])));
     if (empty($result['errors'])) {
         return $result['result'];
     }
     $errors = array_reduce($result['errors'], function ($carry, $error) {
         return $carry .= "{$error['str']} (error code: {$error['no']})\n";
     });
     throw new \RuntimeException($errors);
 }
Beispiel #4
0
 public function testRun()
 {
     $fcgi = new FastCGI();
     $fcgi->setTempDir(sys_get_temp_dir());
     $fcgi->setLogger($this->getMockBuilder('Monolog\\Logger')->disableOriginalConstructor()->getMock());
     $code = Code::fromString('return true;');
     try {
         $result = $fcgi->run($code);
     } catch (\RuntimeException $e) {
         $this->markTestSkipped($e->getMessage());
     }
     $this->assertTrue($result);
 }
 /**
  * Evaluate a string as PHP code
  *
  * @param  string $expression Evaluates the given code as PHP
  * @return mixed
  */
 public function _eval($expression)
 {
     $code = new Code();
     $code->addStatement($expression);
     return $this->adapter->run($code);
 }
Beispiel #6
0
 /**
  * @return string
  */
 public function opcache_version()
 {
     $code = new Code();
     $code->addStatement('return phpversion("Zend OPcache");');
     return $this->adapter->run($code);
 }
Beispiel #7
0
 /**
  * @return string
  */
 public function apc_version()
 {
     $code = new Code();
     $code->addStatement('return phpversion("apc");');
     return $this->adapter->run($code);
 }
Beispiel #8
0
 protected function getCodeResult($statements)
 {
     $code = Code::fromString($statements);
     $exec = $code->getCodeExecutable();
     ob_start();
     eval($exec);
     $result = ob_get_clean();
     $this->assertTrue(strlen($result) > 0);
     $unserialized = unserialize($result);
     $this->assertTrue(is_array($unserialized));
     $this->assertCount(2, $unserialized);
     $this->assertArrayHasKey('result', $unserialized);
     $this->assertArrayHasKey('errors', $unserialized);
     return $unserialized;
 }