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 functional tests.
13
 *
14
 * @package    symfony
15
 * @subpackage task
16
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17
 * @version    SVN: $Id: sfTestFunctionalTask.class.php 29415 2010-05-12 06:24:54Z fabien $
18
 */
19
class sfTestFunctionalTask extends sfTestBaseTask
20
{
21
  /**
22
   * @see sfTask
23
   */
24
  protected function configure()
25
  {
26
    $this->addArguments(array(
27
      new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'),
28
      new sfCommandArgument('controller', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'The controller name'),
29
    ));
30
 
31
    $this->addOptions(array(
32
      new sfCommandOption('xml', null, sfCommandOption::PARAMETER_REQUIRED, 'The file name for the JUnit compatible XML log file'),
33
    ));
34
 
35
    $this->namespace = 'test';
36
    $this->name = 'functional';
37
    $this->briefDescription = 'Launches functional tests';
38
 
39
    $this->detailedDescription = <<<EOF
40
The [test:functional|INFO] task launches functional tests for a
41
given application:
42
 
43
  [./symfony test:functional frontend|INFO]
44
 
45
The task launches all tests found in [test/functional/%application%|COMMENT].
46
 
47
If some tests fail, you can use the [--trace|COMMENT] option to have more
48
information about the failures:
49
 
50
  [./symfony test:functional frontend -t|INFO]
51
 
52
You can launch all functional tests for a specific controller by
53
giving a controller name:
54
 
55
  [./symfony test:functional frontend article|INFO]
56
 
57
You can also launch all functional tests for several controllers:
58
 
59
  [./symfony test:functional frontend article comment|INFO]
60
 
61
The task can output a JUnit compatible XML log file with the [--xml|COMMENT]
62
options:
63
 
64
  [./symfony test:functional --xml=log.xml|INFO]
65
EOF;
66
  }
67
 
68
  /**
69
   * @see sfTask
70
   */
71
  protected function execute($arguments = array(), $options = array())
72
  {
73
    $app = $arguments['application'];
74
 
75
    if (count($arguments['controller']))
76
    {
77
      $files = array();
78
 
79
      foreach ($arguments['controller'] as $controller)
80
      {
81
        $finder = sfFinder::type('file')->follow_link()->name(basename($controller).'Test.php');
82
        $files = array_merge($files, $finder->in(sfConfig::get('sf_test_dir').'/functional/'.$app.'/'.dirname($controller)));
83
      }
84
 
85
      if($allFiles = $this->filterTestFiles($files, $arguments, $options))
86
      {
87
        foreach ($allFiles as $file)
88
        {
89
          include($file);
90
        }
91
      }
92
      else
93
      {
94
        $this->logSection('functional', 'no controller found', null, 'ERROR');
95
      }
96
    }
97
    else
98
    {
99
      require_once dirname(__FILE__).'/sfLimeHarness.class.php';
100
 
101
      $h = new sfLimeHarness(array(
102
        'force_colors' => isset($options['color']) && $options['color'],
103
        'verbose'      => isset($options['trace']) && $options['trace'],
104
      ));
105
      $h->addPlugins(array_map(array($this->configuration, 'getPluginConfiguration'), $this->configuration->getPlugins()));
106
      $h->base_dir = sfConfig::get('sf_test_dir').'/functional/'.$app;
107
 
108
      // filter and register functional tests
109
      $finder = sfFinder::type('file')->follow_link()->name('*Test.php');
110
      $h->register($this->filterTestFiles($finder->in($h->base_dir), $arguments, $options));
111
 
112
      $ret = $h->run() ? 0 : 1;
113
 
114
      if ($options['xml'])
115
      {
116
        file_put_contents($options['xml'], $h->to_xml());
117
      }
118
 
119
      return $ret;
120
    }
121
  }
122
}