/** * Registers LimeAutoloader as an SPL autoloader. */ public static function register() { if (!self::$isRegistered) { ini_set('unserialize_callback_func', 'spl_autoload_call'); spl_autoload_register(array(new self(), 'autoload')); self::$isRegistered = true; } }
<?php /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ $_src_path = __DIR__ . '/../../..'; require_once $_src_path . '/Bundle/Lime2Bundle/LimeAutoloader.php'; LimeAutoloader::enableLegacyMode(); LimeAutoloader::register(); require_once $_src_path . '/src/Symfony/src/Symfony/Foundation/UniversalClassLoader.php'; $loader = new Symfony\Foundation\UniversalClassLoader(); $loader->registerNamespace('Symfony', $_src_path . '/src/Symfony/src'); $loader->register(); $h = new lime_harness(new lime_output_color()); $h->base_dir = realpath(dirname(__FILE__)); $finder = new Symfony\Components\Finder\Finder(); $finder = $finder->files()->exclude('fixtures')->name('*Test.php')->in($h->base_dir . '/unit'); $files = array(); foreach ($finder as $file) { $files[] = $file->getPathname(); } $h->register($files); exit($h->run() ? 0 : 1);
<?php /* * This file is part of the Lime framework. * * (c) Fabien Potencier <*****@*****.**> * (c) Bernhard Schussek <*****@*****.**> * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ $t = new LimeTest(); $t->diag('->autoload() loads class files by class name'); $autoloader = new LimeAutoloader(); $t->is($autoloader->autoload('LimeHarness'), true, 'Returns true if a class can be loaded'); $t->is($autoloader->autoload('Foo'), false, 'Does not load classes that do not begin with "Lime"'); $t->is($autoloader->autoload('LimeFoo'), false, 'Does not load classes that do not exist'); $t->diag('->autoload() loads old class names if legacy mode is enabled'); $t->is($autoloader->autoload('lime_test'), false, 'Does not load old classes in normal mode'); LimeAutoloader::enableLegacyMode(); $t->is($autoloader->autoload('lime_test'), true, 'Loads old classes in legacy mode');
/** * 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; } }
<?php /* * This file is part of the Lime framework. * * (c) Fabien Potencier <*****@*****.**> * (c) Bernhard Schussek <*****@*****.**> * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ $t = new LimeTest(); $t->diag('Text can be colorized with font and color styles'); $c = new LimeColorizer(); $t->is($c->colorize('Hello World', array('bold' => true)), "[1mHello World[0m", 'Text can be bold'); $t->is($c->colorize('Hello World', array('underscore' => true)), "[4mHello World[0m", 'Text can be underscored'); $t->is($c->colorize('Hello World', array('blink' => true)), "[5mHello World[0m", 'Text can be blinking'); $t->is($c->colorize('Hello World', array('reverse' => true)), "[7mHello World[0m", 'Text can be reversed'); $t->is($c->colorize('Hello World', array('conceal' => true)), "[8mHello World[0m", 'Text can be invisible'); $t->is($c->colorize('Hello World', array('fg' => 'white')), "[37mHello World[0m", 'Text can have a custom text color'); $t->is($c->colorize('Hello World', array('bg' => 'white')), "[47mHello World[0m", 'Text can have a custom background color'); $t->is($c->colorize('Hello World', array('bold' => true, 'fg' => 'black', 'bg' => 'white')), "[30;47;1mHello World[0m", 'Styles can be combined'); $t->diag('Text styles can be preset using ->setStyle()'); $c = new LimeColorizer(); $c->setStyle('test_style', array('bold' => true, 'fg' => 'black', 'bg' => 'white')); $t->is($c->colorize('Hello World', 'test_style'), "[30;47;1mHello World[0m", 'Predefined styles can be used'); $t->diag('Text styles can be preset using backwards compatible ::style()'); LimeAutoloader::enableLegacyMode(); lime_colorizer::style('test_style', array('bold' => true, 'fg' => 'black', 'bg' => 'white')); $c = new lime_colorizer(); $t->is($c->colorize('Hello World', 'test_style'), "[30;47;1mHello World[0m", 'Predefined styles can be used');