/**
  * Prints the header before the test output.
  *
  * @param xTestRunner $testRunner Test runner.
  * @param string      $pattern    Test filename pattern.
  * @return void
  */
 public function suiteHeader(xTestRunner $testRunner, $pattern)
 {
     echo '<html>
                <head>
                    <title>Unit Tests</title>
                    <style type="text/css">
                        table { border-collapse:collapse; }
                        td, th { text-align:left; padding:2px 6px; border:solid 1px #aaa; }
                    </style>
                </head>
                <body>
                    <h2>Unit Tests</h2>';
     echo '<h4>Codebase: ' . $testRunner->getRootPath() . '</h4>';
     echo '<h4>Test Suite: ' . $pattern . '</h4>';
 }
 /**
  * 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);
 }
Esempio n. 3
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;
 }
Esempio n. 4
0
<?php

namespace mindplay\test;

use Composer\Autoload\ClassLoader;
use mindplay\test\lib\xTestRunner;
define('FULL_PATH', realpath(__DIR__ . '/..'));
$vendor_path = FULL_PATH . '/vendor';
if (!is_dir($vendor_path)) {
    echo 'Install dependencies first' . PHP_EOL;
    exit(1);
}
require_once $vendor_path . '/autoload.php';
$auto_loader = new ClassLoader();
$auto_loader->addPsr4("mindplay\\test\\", FULL_PATH . '/test');
$auto_loader->addPsr4("mindplay\\test\\Sample\\", FULL_PATH . '/test/suite/Sample');
$auto_loader->register();
$runner = new xTestRunner(dirname(__DIR__) . '/src/annotations', xTestRunner::createResultPrinter());
exit($runner->run(__DIR__ . '/suite', '.test.php') ? 0 : 1);
 /**
  * Prints the header before the test output.
  *
  * @param xTestRunner $testRunner Test runner.
  * @param string      $pattern    Test filename pattern.
  * @return void
  */
 public function suiteHeader(xTestRunner $testRunner, $pattern)
 {
     echo 'Unit Tests' . PHP_EOL;
     echo 'Codebase: ' . $testRunner->getRootPath() . PHP_EOL;
     echo 'Test Suite: ' . $pattern . PHP_EOL;
 }