Beispiel #1
0
 public function testChaining()
 {
     $e1 = new \Exception('This is an error message!');
     $e2 = new \Exception('This is a 2nd error message!', 0, $e1);
     // With class name.
     $expected = "[Exception] This is a 2nd error message!\n";
     $expected .= "Caused by:\n";
     $expected .= "[Exception] This is an error message!";
     $this->assertEquals($expected, ExceptionUtils::formatMessage($e2));
     // No class name.
     $expected = "This is a 2nd error message!\n";
     $expected .= "Caused by:\n";
     $expected .= "This is an error message!";
     $this->assertEquals($expected, ExceptionUtils::formatMessage($e2, false));
 }
Beispiel #2
0
 /**
  * Renders a QTI XML File into another flavour.
  * 
  * This implementations considers that all necessary checks about
  * arguments and their values were performed in \qtism\cli\Render::checkArguments().
  * 
  * @see \qtism\cli\Cli::run()
  * @see \qtism\cli\Render::checkArguments()
  */
 protected function run()
 {
     $engine = $this->instantiateEngine();
     $arguments = $this->getArguments();
     // Load XML Document.
     $source = $arguments['source'];
     $doc = new XmlDocument();
     $validate = !($arguments['novalidate'] === true);
     try {
         $doc->load($source, $validate);
         $renderingData = '';
         switch (strtolower($arguments['flavour'])) {
             case 'goldilocks':
                 $renderingData = $this->runGoldilocks($doc, $engine);
                 break;
             case 'xhtml':
                 $renderingData = $this->runXhtml($doc, $engine);
                 break;
         }
         // Add final new line?
         $nl = false;
         if ($arguments['document'] !== true && $arguments['format'] !== true) {
             $nl = true;
         }
         $this->out($renderingData, $nl);
         $this->success("QTI XML file successfully rendered.");
     } catch (XmlStorageException $e) {
         switch ($e->getCode()) {
             case XmlStorageException::READ:
                 $msg = "An error occured while reading QTI file '{$source}'.\nThe system returned the following error:\n";
                 $msg .= ExceptionUtils::formatMessage($e);
                 $this->fail($msg);
                 break;
             case XmlStorageException::XSD_VALIDATION:
                 $msg = "The QTI file '{$source}' is invalid against XML Schema.\nThe system returned the following error:\n";
                 $msg .= ExceptionUtils::formatMessage($e);
                 $this->fail($msg);
                 break;
             case XmlStorageException::VERSION:
                 $msg = "The QTI version of file '{$source}' could not be detected.";
                 $this->fail($msg);
                 break;
             default:
                 $msg = "An fatal error occured while reading QTI file '{$source}'.";
                 $this->fail($msg);
                 break;
         }
     }
 }