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