* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * Launches unit tests. * * @package symfony * @subpackage task * @author Fabien Potencier * @version SVN: $Id: sfTestUnitTask.class.php 29415 2010-05-12 06:24:54Z fabien $ */ class sfTestUnitTask extends sfTestBaseTask { /** * @see sfTask */ protected function configure() { $this->addArguments(array( new sfCommandArgument('name', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'The test name'), )); $this->addOptions(array( new sfCommandOption('xml', null, sfCommandOption::PARAMETER_REQUIRED, 'The file name for the JUnit compatible XML log file'), )); $this->namespace = 'test'; $this->name = 'unit'; $this->briefDescription = 'Launches unit tests'; $this->detailedDescription = <<follow_link()->name(basename($name).'Test.php'); $files = array_merge($files, $finder->in(sfConfig::get('sf_test_dir').'/unit/'.dirname($name))); } if($allFiles = $this->filterTestFiles($files, $arguments, $options)) { foreach ($allFiles as $file) { include($file); } } else { $this->logSection('test', 'no tests found', null, 'ERROR'); } } else { require_once dirname(__FILE__).'/sfLimeHarness.class.php'; $h = new sfLimeHarness(array( 'force_colors' => isset($options['color']) && $options['color'], 'verbose' => isset($options['trace']) && $options['trace'], )); $h->addPlugins(array_map(array($this->configuration, 'getPluginConfiguration'), $this->configuration->getPlugins())); $h->base_dir = sfConfig::get('sf_test_dir').'/unit'; // filter and register unit tests $finder = sfFinder::type('file')->follow_link()->name('*Test.php'); $h->register($this->filterTestFiles($finder->in($h->base_dir), $arguments, $options)); $ret = $h->run() ? 0 : 1; if ($options['xml']) { file_put_contents($options['xml'], $h->to_xml()); } return $ret; } } }