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