1. sfTestFunctionalTask.class.php
  2. /** * Launches functional tests. * * @package symfony * @subpackage task * @author Fabien Potencier * @version SVN: $Id: sfTestFunctionalTask.class.php 25036 2009-12-07 19:41:58Z Kris.Wallsmith $ */
  3. class sfTestFunctionalTask extends sfTestBaseTask
  4. {
  5. /**
  6. * @see sfTask
  7. */
  8. protected function configure()
  9. {
  10. $this->addArguments(array(
  11. new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'),
  12. new sfCommandArgument('controller', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'The controller name'),
  13. ));
  14. $this->addOptions(array(
  15. new sfCommandOption('xml', null, sfCommandOption::PARAMETER_REQUIRED, 'The file name for the JUnit compatible XML log file'),
  16. ));
  17. $this->namespace = 'test';
  18. $this->name = 'functional';
  19. $this->briefDescription = 'Launches functional tests';
  20. $this->detailedDescription = <<<EOF
  21. The [test:functional|INFO] task launches functional tests for a
  22. given application:
  23. [./symfony test:functional frontend|INFO]
  24. The task launches all tests found in [test/functional/%application%|COMMENT].
  25. If some tests fail, you can use the [--trace|COMMENT] option to have more
  26. information about the failures:
  27. [./symfony test:functional frontend -t|INFO]
  28. You can launch all functional tests for a specific controller by
  29. giving a controller name:
  30. [./symfony test:functional frontend article|INFO]
  31. You can also launch all functional tests for several controllers:
  32. [./symfony test:functional frontend article comment|INFO]
  33. The task can output a JUnit compatible XML log file with the [--xml|COMMENT]
  34. options:
  35. [./symfony test:functional --xml=log.xml|INFO]
  36. EOF;
  37. }
  38. /**
  39. * @see sfTask
  40. */
  41. protected function execute($arguments = array(), $options = array())
  42. {
  43. $app = $arguments['application'];
  44. if (count($arguments['controller']))
  45. {
  46. $files = array();
  47. foreach ($arguments['controller'] as $controller)
  48. {
  49. $finder = sfFinder::type('file')->follow_link()->name(basename($controller).'Test.php');
  50. $files = array_merge($files, $finder->in(sfConfig::get('sf_test_dir').'/functional/'.$app.'/'.dirname($controller)));
  51. }
  52. if($allFiles = $this->filterTestFiles($files, $arguments, $options))
  53. {
  54. foreach ($allFiles as $file)
  55. {
  56. include($file);
  57. }
  58. }
  59. else
  60. {
  61. $this->logSection('functional', 'no controller found', null, 'ERROR');
  62. }
  63. }
  64. else
  65. {
  66. require_once dirname(__FILE__).'/sfLimeHarness.class.php';
  67. $h = new sfLimeHarness(array(
  68. 'force_colors' => isset($options['color']) && $options['color'],
  69. 'verbose' => isset($options['trace']) && $options['trace'],
  70. ));
  71. $h->addPlugins(array_map(array($this->configuration, 'getPluginConfiguration'), $this->configuration->getPlugins()));
  72. $h->base_dir = sfConfig::get('sf_test_dir').'/functional/'.$app;
  73. // filter and register functional tests
  74. $finder = sfFinder::type('file')->follow_link()->name('*Test.php');
  75. $h->register($this->filterTestFiles($finder->in($h->base_dir), $arguments, $options));
  76. $ret = $h->run() ? 0 : 1;
  77. if ($options['xml'])
  78. {
  79. file_put_contents($options['xml'], $h->to_xml());
  80. }
  81. return $ret;
  82. }
  83. }
  84. }

Debug toolbar