Esempio n. 1
0
 /**
  * Run this test.
  *
  * @param xTestRunner $testRunner Test runner.
  * @return boolean
  */
 public function run(xTestRunner $testRunner)
 {
     $this->testRunner = $testRunner;
     $this->resultPrinter->testHeader($this);
     $reflection = new \ReflectionClass(get_class($this));
     $methods = $reflection->getMethods();
     $passed = $count = 0;
     if (method_exists($this, 'init')) {
         try {
             $this->init();
         } catch (\Exception $exception) {
             echo '<tr style="color:white; background:red;"><td>init() failed</td><td><pre>' . $exception . '</pre></td></tr></table>';
             return false;
         }
     }
     foreach ($methods as $method) {
         if (substr($method->name, 0, 4) == 'test') {
             $this->result = null;
             $test = $method->name;
             $name = substr($test, 4);
             if (count($_GET) && isset($_GET[$name]) && $_GET[$name] !== '') {
                 continue;
             }
             $this->testRunner->startCoverageCollector($test);
             if (method_exists($this, 'setup')) {
                 $this->setup();
             }
             $exception = null;
             try {
                 $this->{$test}();
             } catch (\Exception $exception) {
             }
             try {
                 $this->assertException($exception);
             } catch (xTestException $subException) {
             }
             if (is_null($this->result) && !($exception instanceof xTestException && $exception->getCode() == xTestException::FAIL)) {
                 $this->result = (string) $exception;
             }
             $count++;
             if ($this->result === true) {
                 $passed++;
             }
             if (method_exists($this, 'teardown')) {
                 $this->teardown();
             }
             $this->setExpectedException(null, '', null);
             $this->testRunner->stopCoverageCollector();
             $this->resultPrinter->testCaseResult($method, $this->getResultColor(), $this->getResultMessage());
         }
     }
     $this->resultPrinter->testFooter($this, $count, $passed);
     return $passed == $count;
 }
 /**
  * Run this test.
  *
  * @param xTestRunner $testRunner Test runner.
  * @return boolean
  */
 public function run(xTestRunner $testRunner)
 {
     $testRunner->startCoverageCollector(__CLASS__);
     $cachePath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'runtime';
     Annotations::$config = array('cache' => new AnnotationCache($cachePath));
     if (!is_writable($cachePath)) {
         die('cache path is not writable: ' . $cachePath);
     }
     // manually wipe out the cache:
     $pattern = Annotations::getManager()->cache->getRoot() . DIRECTORY_SEPARATOR . '*.annotations.php';
     foreach (glob($pattern) as $path) {
         unlink($path);
     }
     // disable some annotations not used during testing:
     Annotations::getManager()->registry['var'] = false;
     Annotations::getManager()->registry['undefined'] = 'UndefinedAnnotation';
     $testRunner->stopCoverageCollector();
     return parent::run($testRunner);
 }