1. sfSymfonyTestTask.class.php
  2. /** * Launches the symfony test suite. * * @package symfony * @subpackage task * @author Fabien Potencier * @version SVN: $Id: sfSymfonyTestTask.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ */
  3. class sfSymfonyTestTask extends sfTask
  4. {
  5. /**
  6. * @see sfTask
  7. */
  8. protected function configure()
  9. {
  10. $this->addOptions(array(
  11. new sfCommandOption('update-autoloader', 'u', sfCommandOption::PARAMETER_NONE, 'Update the sfCoreAutoload class'),
  12. new sfCommandOption('only-failed', 'f', sfCommandOption::PARAMETER_NONE, 'Only run tests that failed last time'),
  13. new sfCommandOption('xml', null, sfCommandOption::PARAMETER_REQUIRED, 'The file name for the JUnit compatible XML log file'),
  14. new sfCommandOption('rebuild-all', null, sfCommandOption::PARAMETER_NONE, 'Rebuild all generated fixture files'),
  15. ));
  16. $this->namespace = 'symfony';
  17. $this->name = 'test';
  18. $this->briefDescription = 'Launches the symfony test suite';
  19. $this->detailedDescription = <<<EOF
  20. The [test:all|INFO] task launches the symfony test suite:
  21. [./symfony symfony:test|INFO]
  22. EOF;
  23. }
  24. /**
  25. * @see sfTask
  26. */
  27. protected function execute($arguments = array(), $options = array())
  28. {
  29. require_once(dirname(__FILE__).'/../../vendor/lime/lime.php');
  30. require_once(dirname(__FILE__).'/lime_symfony.php');
  31. // cleanup
  32. require_once(dirname(__FILE__).'/../../util/sfToolkit.class.php');
  33. if ($files = glob(sys_get_temp_dir().DIRECTORY_SEPARATOR.'/sf_autoload_unit_*'))
  34. {
  35. foreach ($files as $file)
  36. {
  37. unlink($file);
  38. }
  39. }
  40. // update sfCoreAutoload
  41. if ($options['update-autoloader'])
  42. {
  43. require_once(dirname(__FILE__).'/../../autoload/sfCoreAutoload.class.php');
  44. sfCoreAutoload::make();
  45. }
  46. $status = false;
  47. $statusFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.sprintf('/.test_symfony_%s_status', md5(dirname(__FILE__)));
  48. if ($options['only-failed'])
  49. {
  50. if (file_exists($statusFile))
  51. {
  52. $status = unserialize(file_get_contents($statusFile));
  53. }
  54. }
  55. $h = new lime_symfony(array('force_colors' => $options['color'], 'verbose' => $options['trace']));
  56. $h->base_dir = realpath(dirname(__FILE__).'/../../../test');
  57. // remove generated files
  58. if ($options['rebuild-all'])
  59. {
  60. $finder = sfFinder::type('dir')->name(array('base', 'om', 'map'));
  61. foreach ($finder->in(glob($h->base_dir.'/../lib/plugins/*/test/functional/fixtures/lib')) as $dir)
  62. {
  63. sfToolkit::clearDirectory($dir);
  64. }
  65. }
  66. if ($status)
  67. {
  68. foreach ($status as $file)
  69. {
  70. $h->register($file);
  71. }
  72. }
  73. else
  74. {
  75. $h->register(sfFinder::type('file')->prune('fixtures')->name('*Test.php')->in(array_merge(
  76. // unit tests
  77. array($h->base_dir.'/unit'),
  78. glob($h->base_dir.'/../lib/plugins/*/test/unit'),
  79. // functional tests
  80. array($h->base_dir.'/functional'),
  81. glob($h->base_dir.'/../lib/plugins/*/test/functional'),
  82. // other tests
  83. array($h->base_dir.'/other')
  84. )));
  85. }
  86. $ret = $h->run() ? 0 : 1;
  87. file_put_contents($statusFile, serialize($h->get_failed_files()));
  88. if ($options['xml'])
  89. {
  90. file_put_contents($options['xml'], $h->to_xml());
  91. }
  92. return $ret;
  93. }
  94. }

Debug toolbar