forked from adanda/CIPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CliRunner.php
executable file
·128 lines (106 loc) · 2.57 KB
/
CliRunner.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
require_once 'Sweety/Runner/AbstractTestRunner.php';
/**
* Runs SimpleTest cases as a group via the command line.
* @package Sweety
* @author Chris Corbyn
*/
class Sweety_Runner_CliRunner extends Sweety_Runner_AbstractTestRunner
{
/**
* Directories to scan for test cases.
* @var string[]
* @access private
*/
private $_dirs = array();
/**
* The command to invoke when running test cases.
* @var string
* @access private
*/
private $_command;
/**
* Creates a new CliRunner scanning the given directories, using the given
* command and having the given name.
* @param string[] $dirs
* @param string $command
* @param string $name
*/
public function __construct(array $dirs, $command)
{
$this->_dirs = $dirs;
$this->_command = $command;
}
/**
* Runs all test cases found under the given directories.
* @param string[] $directories to scan for test cases
* @param string To be prepended to class names
* @return int
*/
public function runAllTests($dirs = array())
{
if (empty($dirs))
{
$dirs = $this->_dirs;
}
$reporter = $this->getReporter();
if (!$reporter->isStarted())
{
$reporter->start();
}
$tests = $this->findTests($dirs);
usort($tests, array($this, '_sort'));
global $argv;
if (!empty($argv[1]))
{
if (substr($argv[1], 0, 1) == '!')
{
$argv[1] = substr($argv[1], 1);
foreach ($tests as $index => $name)
{
if (@preg_match($argv[1] . 'i', $name))
{
unset($tests[$index]);
}
}
}
else
{
foreach ($tests as $index => $name)
{
if (!@preg_match($argv[1] . 'i', $name))
{
unset($tests[$index]);
}
}
}
}
$ret = $this->_runTestList($tests);
$reporter->finish();
return $ret;
}
/**
* Run all possible tests from the given list.
* @param string[] $tests
* @return int
*/
protected function _runTestList(array $tests)
{
foreach ($tests as $testCase)
{
if (preg_match($this->getIgnoredClassRegex(), $testCase))
{
continue;
}
$command = $this->_command;
$command .= ' ' . $testCase;
$command .= ' ' . Sweety_Runner::REPORT_XML;
exec($command, $output, $status);
$xml = implode(PHP_EOL, $output);
$this->parseXml($xml, $testCase);
unset($status);
unset($output);
}
return 0;
}
}