1. sfTestAllTask.class.php
  2. /** * Launches all tests. * * @package symfony * @subpackage task * @author Fabien Potencier * @version SVN: $Id: sfTestAllTask.class.php 25036 2009-12-07 19:41:58Z Kris.Wallsmith $ */
  3. class sfTestAllTask extends sfTestBaseTask
  4. {
  5. /**
  6. * @see sfTask
  7. */
  8. protected function configure()
  9. {
  10. $this->addOptions(array(
  11. new sfCommandOption('only-failed', 'f', sfCommandOption::PARAMETER_NONE, 'Only run tests that failed last time'),
  12. new sfCommandOption('xml', null, sfCommandOption::PARAMETER_REQUIRED, 'The file name for the JUnit compatible XML log file'),
  13. ));
  14. $this->namespace = 'test';
  15. $this->name = 'all';
  16. $this->briefDescription = 'Launches all tests';
  17. $this->detailedDescription = <<<EOF
  18. The [test:all|INFO] task launches all unit and functional tests:
  19. [./symfony test:all|INFO]
  20. The task launches all tests found in [test/|COMMENT].
  21. If some tests fail, you can use the [--trace|COMMENT] option to have more
  22. information about the failures:
  23. [./symfony test:all -t|INFO]
  24. Or you can also try to fix the problem by launching them by hand or with the
  25. [test:unit|COMMENT] and [test:functional|COMMENT] task.
  26. Use the [--only-failed|COMMENT] option to force the task to only execute tests
  27. that failed during the previous run:
  28. [./symfony test:all --only-failed|INFO]
  29. Here is how it works: the first time, all tests are run as usual. But for
  30. subsequent test runs, only tests that failed last time are executed. As you
  31. fix your code, some tests will pass, and will be removed from subsequent runs.
  32. When all tests pass again, the full test suite is run... you can then rinse
  33. and repeat.
  34. The task can output a JUnit compatible XML log file with the [--xml|COMMENT]
  35. options:
  36. [./symfony test:all --xml=log.xml|INFO]
  37. EOF;
  38. }
  39. /**
  40. * @see sfTask
  41. */
  42. protected function execute($arguments = array(), $options = array())
  43. {
  44. require_once dirname(__FILE__).'/sfLimeHarness.class.php';
  45. $h = new sfLimeHarness(array(
  46. 'force_colors' => isset($options['color']) && $options['color'],
  47. 'verbose' => isset($options['trace']) && $options['trace'],
  48. ));
  49. $h->addPlugins(array_map(array($this->configuration, 'getPluginConfiguration'), $this->configuration->getPlugins()));
  50. $h->base_dir = sfConfig::get('sf_test_dir');
  51. $status = false;
  52. $statusFile = sfConfig::get('sf_cache_dir').'/.test_all_status';
  53. if ($options['only-failed'])
  54. {
  55. if (file_exists($statusFile))
  56. {
  57. $status = unserialize(file_get_contents($statusFile));
  58. }
  59. }
  60. if ($status)
  61. {
  62. foreach ($status as $file)
  63. {
  64. $h->register($file);
  65. }
  66. }
  67. else
  68. {
  69. // filter and register all tests
  70. $finder = sfFinder::type('file')->follow_link()->name('*Test.php');
  71. $h->register($this->filterTestFiles($finder->in($h->base_dir), $arguments, $options));
  72. }
  73. $ret = $h->run() ? 0 : 1;
  74. file_put_contents($statusFile, serialize($h->get_failed_files()));
  75. if ($options['xml'])
  76. {
  77. file_put_contents($options['xml'], $h->to_xml());
  78. }
  79. return $ret;
  80. }
  81. }

Debug toolbar