/**
  * 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();
 }
Example #2
0
$r = new LimeTestRunner();
$r->addBefore(array($mock, 'setUp'));
$r->addTest(array($mock, 'testDoSomething'), 'Do something', '/test/file', 11);
$r->addTest(array($mock, 'testDoSomethingElse'), 'Do something else', '/test/file', 22);
$mock->setUp('Do something', '/test/file', 11);
$mock->testDoSomething();
$mock->setUp('Do something else', '/test/file', 22);
$mock->testDoSomethingElse();
$mock->replay();
// test
$r->run();
$t->diag('The after callbacks are called before each test method');
// fixtures
$mock = $t->mock('Mock', array('strict' => true));
$r = new LimeTestRunner();
$r->addAfter(array($mock, 'tearDown'));
$r->addTest(array($mock, 'testDoSomething'), '', '', 0);
$r->addTest(array($mock, 'testDoSomethingElse'), '', '', 0);
$mock->testDoSomething();
$mock->tearDown();
$mock->testDoSomethingElse();
$mock->tearDown();
$mock->replay();
// test
$r->run();
$t->diag('The before-all callbacks are called before the whole test suite');
// fixtures
$mock = $t->mock('Mock', array('strict' => true));
$r = new LimeTestRunner();
$r->addBeforeAll(array($mock, 'setUp'));
$r->addTest(array($mock, 'testDoSomething'), '', '', 0);