public function testHandlerRestoresDefaultHandler()
 {
     $dummyHandler = $this->getDummyHandler();
     // Restores the default error handler.
     while (set_error_handler($dummyHandler)) {
         // Unset the just set dummy handler.
         restore_error_handler();
         // Unset the previous handler.
         restore_error_handler();
     }
     // Restores the built-in handler (the last dummy handler we set will
     // be removed).
     restore_error_handler();
     $handler = TwigErrorHandler::register();
     try {
         // The test fails, if the Handler throws TwigException.
         $handler->restore();
     } catch (\Exception $e) {
         // The test has failed, but PHPUnit's error handler should be restored.
     }
     set_error_handler(self::$phpUnitHandler);
     if (isset($e)) {
         throw $e;
     }
 }
Exemplo n.º 2
0
 public function executeTwig($templateName, CodingContext $context, CodingExecutionResult $codingExecutionResult)
 {
     $errorHandler = TwigErrorHandler::register();
     try {
         $output = $this->getTwigEnvironment()->render($templateName, $context->getVariables());
         $codingExecutionResult->setOutput($output);
     } catch (TwigException $error) {
         $codingExecutionResult->setLanguageError($error->getMessage());
     } catch (\Twig_Error $error) {
         // not doing anything special here... but in the future, we might
         // fetch more information about line numbers, etc
         $codingExecutionResult->setLanguageError($error->getMessage());
     } catch (\Exception $error) {
         $codingExecutionResult->setLanguageError($error->getMessage());
     }
     $errorHandler->restore();
     return $codingExecutionResult;
 }
Exemplo n.º 3
0
 /**
  * Execute the code and modify the CodingExecutionResult
  *
  * @param string $rootDir Where all the files have been placed
  * @param string $entryPointFilename
  * @param CodingContext $context
  * @param CodingExecutionResult $result
  */
 public function executeCode($rootDir, $entryPointFilename, CodingContext $context, CodingExecutionResult $result)
 {
     Debug::enable();
     $errorHandler = TwigErrorHandler::register();
     $twig = $this->getTwigEnvironment($rootDir);
     try {
         $output = $twig->render($entryPointFilename, $context->getVariables());
         $result->setOutput($output);
     } catch (TwigException $error) {
         $result->setLanguageError($error->getMessage());
     } catch (\Twig_Error $error) {
         // not doing anything special here... but in the future, we might
         // fetch more information about line numbers, etc
         $result->setLanguageError($error->getMessage());
     } catch (\Exception $error) {
         $result->setLanguageError($error->getMessage());
     }
     $errorHandler->restore();
 }