Example #1
0
 /**
  * Tests a given set of labels.
  *
  * Packages may given with a leading "+" or "-". The tested files are:
  *
  *    * all files that are in all of the labels without leading "+" or "-"
  *    * all files that are in any label with a leading "+"
  *    * no files that are in any label with a leading "-"
  *
  * @param  array $labels  The label names
  * @return integer        The return value of the command (0 if successful)
  */
 protected function test(array $labels, array $options)
 {
     // don't load configuration in the constructor because then --init does
     // not work!
     $configuration = LimeConfiguration::read(getcwd());
     if ($configuration->getLegacyMode()) {
         LimeAutoloader::enableLegacyMode();
     }
     if (isset($options['processes'])) {
         $configuration->setProcesses($options['processes']);
     }
     if (isset($options['suffix'])) {
         $configuration->setSuffix($options['suffix']);
     }
     if (isset($options['output'])) {
         $configuration->setTestOutput($options['output']);
         $configuration->setSuiteOutput($options['output']);
     }
     if (isset($options['color'])) {
         $configuration->setForceColors(true);
     }
     if (isset($options['verbose'])) {
         $configuration->setVerbose(true);
     }
     if (isset($options['serialize'])) {
         $configuration->setSerialize(true);
     }
     if (isset($options['test'])) {
         $fileName = $options['test'];
         if (!is_readable($fileName)) {
             $loader = new LimeLoader($configuration);
             $files = $loader->getFilesByName($options['test']);
             if (count($files) == 0) {
                 throw new Exception("No tests are registered in the test suite! Please add your tests in lime.config.php.");
             } else {
                 if (count($files) > 1) {
                     $paths = array();
                     foreach ($files as $file) {
                         $paths[] = $file->getPath();
                     }
                     throw new Exception(sprintf("The name \"%s\" is ambiguous:\n  - %s\nPlease launch the test with the full file path.", $labels[0], implode("\n  - ", $paths)));
                 }
             }
             $fileName = $files[0]->getPath();
         } else {
             $fileName = realpath($fileName);
         }
         $configuration->getTestOutput()->focus($fileName);
         try {
             if ($configuration->getAnnotationSupport()) {
                 $support = new LimeAnnotationSupport($fileName);
                 $result = $support->execute();
             } else {
                 $result = $this->includeTest($fileName);
             }
             // xUnit compatibility
             $class = basename($fileName, '.php');
             if (class_exists($class) && is_subclass_of($class, 'LimeTestCase')) {
                 $test = new $class($configuration);
                 return $test->run();
             } else {
                 return $result;
             }
         } catch (Exception $e) {
             $configuration->getTestOutput()->error(LimeError::fromException($e));
             return 1;
         }
     } else {
         $loader = new LimeLoader($configuration);
         $harness = new LimeHarness($configuration, $loader);
         $files = $loader->getFilesByLabels($labels);
         if (count($files) == 0) {
             throw new Exception("No tests are registered in the test suite! Please add your tests in lime.config.php.");
         }
         return $harness->run($files) ? 0 : 1;
     }
 }
Example #2
0
 public function __construct($options = array())
 {
     // for BC
     if (!is_array($options)) {
         $options = array();
         // drop the old output because it is not compatible with LimeTest
     } else {
         if (array_key_exists('php_cli', $options)) {
             $options['executable'] = $options['php_cli'];
             unset($options['php_cli']);
         }
     }
     parent::__construct($options);
 }
Example #3
0
File: loc.php Project: b00giZm/lime
 * with this source code in the file LICENSE.
 */
require_once dirname(__FILE__) . '/../../lib/LimeAutoloader.php';
LimeAutoloader::register();
$baseDir = realpath(dirname(__FILE__) . '/..');
$printer = new LimePrinter(new LimeColorizer());
$printer->printLine('Source Lines Of Code', LimePrinter::HAPPY);
$fileLines = 0;
$testLines = 0;
$lexer = new LimeLexerCodeLines();
$suite = new LimeHarness();
$suite->registerGlob($baseDir . '/../lib/*.php');
$suite->registerGlob($baseDir . '/../lib/*/*.php');
$suite->registerGlob($baseDir . '/../lib/*/*/*.php');
$suite->registerGlob($baseDir . '/../lib/*/*/*/*.php');
$suite->registerGlob($baseDir . '/../lib/*/*/*/*/*.php');
foreach ($suite->getFiles() as $file) {
    $fileLines += count($lexer->parse($file));
}
$printer->printLine(sprintf('Classes:       %d', $fileLines));
$suite = new LimeHarness();
$suite->registerGlob($baseDir . '/unit/*.php');
$suite->registerGlob($baseDir . '/unit/*/*.php');
$suite->registerGlob($baseDir . '/unit/*/*/*.php');
$suite->registerGlob($baseDir . '/unit/*/*/*/*.php');
foreach ($suite->getFiles() as $file) {
    $testLines += count($lexer->parse($file));
}
$printer->printLine(sprintf('Tests:         %d', $testLines));
$printer->printLine(sprintf('TOTAL:         %d', $fileLines + $testLines));
$printer->printLine(sprintf('Tests/Classes: %d%%', 100 * $testLines / $fileLines));