Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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