sfTestUnitTask.class.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * Launches unit tests.
  11. *
  12. * @package symfony
  13. * @subpackage task
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfTestUnitTask.class.php 8148 2008-03-29 07:58:59Z fabien $
  16. */
  17. class sfTestUnitTask extends sfBaseTask
  18. {
  19. /**
  20. * @see sfTask
  21. */
  22. protected function configure()
  23. {
  24. $this->addArguments(array(
  25. new sfCommandArgument('name', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'The test name'),
  26. ));
  27. $this->aliases = array('test-unit');
  28. $this->namespace = 'test';
  29. $this->name = 'unit';
  30. $this->briefDescription = 'Launches unit tests';
  31. $this->detailedDescription = <<<EOF
  32. The [test:unit|INFO] task launches unit tests:
  33. [./symfony test:unit|INFO]
  34. The task launches all tests found in [test/unit|COMMENT].
  35. You can launch unit tests for a specific name:
  36. [./symfony test:unit strtolower|INFO]
  37. You can also launch unit tests for several names:
  38. [./symfony test:unit strtolower strtoupper|INFO]
  39. EOF;
  40. }
  41. /**
  42. * @see sfTask
  43. */
  44. protected function execute($arguments = array(), $options = array())
  45. {
  46. if (count($arguments['name']))
  47. {
  48. foreach ($arguments['name'] as $name)
  49. {
  50. $files = sfFinder::type('file')->follow_link()->name(basename($name).'Test.php')->in(sfConfig::get('sf_test_dir').DIRECTORY_SEPARATOR.'unit'.DIRECTORY_SEPARATOR.dirname($name));
  51. foreach ($files as $file)
  52. {
  53. include($file);
  54. }
  55. }
  56. }
  57. else
  58. {
  59. require_once(sfConfig::get('sf_symfony_lib_dir').'/vendor/lime/lime.php');
  60. $h = new lime_harness(new lime_output_color());
  61. $h->base_dir = sfConfig::get('sf_test_dir').'/unit';
  62. // register unit tests
  63. $finder = sfFinder::type('file')->follow_link()->name('*Test.php');
  64. $h->register($finder->in($h->base_dir));
  65. $h->run();
  66. }
  67. }
  68. }