sfTestFunctionalTask.class.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 functional tests.
  11. *
  12. * @package symfony
  13. * @subpackage task
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfTestFunctionalTask.class.php 8148 2008-03-29 07:58:59Z fabien $
  16. */
  17. class sfTestFunctionalTask extends sfBaseTask
  18. {
  19. /**
  20. * @see sfTask
  21. */
  22. protected function configure()
  23. {
  24. $this->addArguments(array(
  25. new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'),
  26. new sfCommandArgument('controller', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'The controller name'),
  27. ));
  28. $this->aliases = array('test-functional');
  29. $this->namespace = 'test';
  30. $this->name = 'functional';
  31. $this->briefDescription = 'Launches functional tests';
  32. $this->detailedDescription = <<<EOF
  33. The [test:functional|INFO] task launches functional tests for a
  34. given application:
  35. [./symfony test:functional frontend|INFO]
  36. The task launches all tests found in [test/functional/%application%|COMMENT].
  37. You can launch all functional tests for a specific controller by
  38. giving a controller name:
  39. [./symfony test:functional frontend article|INFO]
  40. You can also launch all functional tests for several controllers:
  41. [./symfony test:functional frontend article comment|INFO]
  42. EOF;
  43. }
  44. /**
  45. * @see sfTask
  46. */
  47. protected function execute($arguments = array(), $options = array())
  48. {
  49. $app = $arguments['application'];
  50. if (count($arguments['controller']))
  51. {
  52. foreach ($arguments['controller'] as $controller)
  53. {
  54. $files = sfFinder::type('file')->follow_link()->name(basename($controller).'Test.php')->in(sfConfig::get('sf_test_dir').DIRECTORY_SEPARATOR.'functional'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.dirname($controller));
  55. foreach ($files as $file)
  56. {
  57. include($file);
  58. }
  59. }
  60. }
  61. else
  62. {
  63. require_once(sfConfig::get('sf_symfony_lib_dir').'/vendor/lime/lime.php');
  64. $h = new lime_harness(new lime_output_color());
  65. $h->base_dir = sfConfig::get('sf_test_dir').'/functional/'.$app;
  66. // register functional tests
  67. $finder = sfFinder::type('file')->follow_link()->name('*Test.php');
  68. $h->register($finder->in($h->base_dir));
  69. $h->run();
  70. }
  71. }
  72. }