コード例 #1
0
 /**
  * Transforms the annotations in the script file and executes the resulting
  * script.
  */
 protected function execute()
 {
     if (file_exists($this->path)) {
         unlink($this->path);
     }
     $this->lexer = new LimeLexerTransformAnnotations($this->path);
     $callbacks = $this->lexer->parse($this->originalPath);
     $this->includeTestFile();
     $testRunner = new LimeTestRunner($this->test ? $this->test->getOutput() : null);
     foreach ($callbacks as $annotation => $callbacks) {
         $addMethod = 'add' . $annotation;
         foreach ($callbacks as $list) {
             list($callback, $comment) = $list;
             $testRunner->{$addMethod}($callback, $comment);
         }
     }
     if ($this->test instanceof LimeTest) {
         $testRunner->addExceptionHandler(array($this->test, 'handleException'));
         $testRunner->addAfter(array($this->test, 'verifyException'));
     }
     $testRunner->run();
 }
コード例 #2
0
ファイル: LimeTestRunnerTest.php プロジェクト: b00giZm/lime
// test
$r->run();
$t->diag('The exception handlers are called when a test throws an exception');
// fixtures
$mock = $t->mock('Mock', array('strict' => true));
$r = new LimeTestRunner();
$r->addTest(array($mock, 'testThrowsException'), '', '', 0);
$r->addExceptionHandler(array($mock, 'handleExceptionFailed'));
$r->addExceptionHandler(array($mock, 'handleExceptionSuccessful'));
$mock->testThrowsException()->throws('Exception');
$mock->method('handleExceptionFailed')->returns(false);
$mock->method('handleExceptionSuccessful')->returns(true);
$mock->replay();
// test
$r->run();
$t->diag('If no exception handler returns true, the exception is thrown again');
// fixtures
$mock = $t->mock('Mock', array('strict' => true));
$r = new LimeTestRunner();
$r->addTest(array($mock, 'testThrowsException'), '', '', 0);
$r->addExceptionHandler(array($mock, 'handleExceptionFailed'));
$mock->testThrowsException()->throws('Exception');
$mock->method('handleExceptionFailed')->returns(false);
$mock->replay();
// test
$t->expect('Exception');
try {
    $r->run();
    $t->fail('The exception was thrown');
} catch (Exception $e) {
}