PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Group-I/jobeet/lib/vendor/symfony/lib/task/symfony/sfSymfonyTestTask.class.php

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