コード例 #1
0
ファイル: Test.php プロジェクト: devco/europaphp
 /**
  * Runs all unit tests.
  *
  * @param string $test     The test suite to run. Defaults to "Test".
  * @param bool   $untested Whether or not to display untested LOC.
  * @param string $analyze  The path, relative to the base path, to analyze. If not specified, all modules are analyzed.
  *
  * @return array
  */
 public function all($test = null, $untested = false, $analyze = null)
 {
     $suite = new Suite();
     $cover = new Coverage();
     $finder = new FsFinder();
     $finder->is('/\\.php$/');
     $finder->in(__DIR__ . '/../../../' . $analyze);
     $cover->start();
     foreach (App::get() as $name => $module) {
         $path = __DIR__ . '/../../../';
         $path .= $name . '/';
         $path .= App::get()->modules['tests']['path'];
         $suite->addTests(new Finder($path, $test));
     }
     $suite->run($this->getTestEvent());
     $analyzer = $cover->stop();
     foreach ($finder as $file) {
         $analyzer->addFile($file->getRealpath());
     }
     return ['percent' => round(number_format($analyzer->getPercentTested(), 2), 2), 'suite' => $suite, 'report' => $analyzer, 'untested' => $untested];
 }
コード例 #2
0
ファイル: tests.php プロジェクト: devco/testes
<?php

use Testes\Coverage\Coverage;
use Testes\Finder\Finder;
use Testes\Autoloader;
use Testes\Event;
$base = __DIR__ . '/..';
require $base . '/src/Testes/Autoloader.php';
Autoloader::register();
Autoloader::addPath($base . '/tests');
Autoloader::addPath($base . '/src');
Autoloader::addPath($base . '/vendor/devco');
Autoloader::addPath($base . '/vendor/devco/event-emitter/src');
$coverage = new Coverage();
$finder = new Finder($base . '/tests', 'Test');
$coverage->start();
echo PHP_EOL;
$event = new Event\Test();
$event->on('postRun', function ($test) {
    echo $test->getAssertions()->isPassed() && !$test->getExceptions()->count() ? '.' : 'F';
});
$suite = $finder->run($event);
echo PHP_EOL . PHP_EOL . sprintf('Ran %d test%s.', count($suite), count($suite) === 1 ? '' : 's');
$analyzer = $coverage->stop()->addDirectory($base . '/src')->is('\\.php$');
echo PHP_EOL . PHP_EOL . 'Coverage: ' . $analyzer->getPercentTested() . '%' . PHP_EOL . PHP_EOL;
if (count($assertions = $suite->getAssertions()->getFailed())) {
    echo 'Assertions' . PHP_EOL;
    echo '----------' . PHP_EOL;
    foreach ($assertions as $ass) {
        echo '  ' . $ass->getTestClass() . ':' . $ass->getTestLine() . ' ' . $ass->getMessage() . PHP_EOL;
    }