1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Genesis\Commands; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author Adam Bisek <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
class PhpUnit extends Command |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
private $workingDir; |
14
|
|
|
|
15
|
|
|
private $target; |
16
|
|
|
|
17
|
|
|
private $options; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @return mixed |
22
|
|
|
*/ |
23
|
1 |
|
public function getWorkingDir() |
24
|
|
|
{ |
25
|
1 |
|
return $this->workingDir; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param mixed $workingDir |
31
|
|
|
*/ |
32
|
1 |
|
public function setWorkingDir($workingDir) |
33
|
|
|
{ |
34
|
1 |
|
$this->workingDir = $workingDir; |
35
|
1 |
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return mixed |
40
|
|
|
*/ |
41
|
1 |
|
public function getTarget() |
42
|
|
|
{ |
43
|
1 |
|
return $this->target; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param mixed $target |
49
|
|
|
*/ |
50
|
1 |
|
public function setTarget($target) |
51
|
|
|
{ |
52
|
1 |
|
$this->target = $target; |
53
|
1 |
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return array|NULL |
58
|
|
|
*/ |
59
|
1 |
|
public function getOptions() |
60
|
|
|
{ |
61
|
1 |
|
return $this->options; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param array|NULL $options |
67
|
|
|
*/ |
68
|
1 |
|
public function setOptions(array $options = NULL) |
69
|
|
|
{ |
70
|
1 |
|
$this->options = $options; |
71
|
1 |
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
1 |
|
public function execute() |
75
|
|
|
{ |
76
|
1 |
|
if (!isset($this->options['executable'])) { |
77
|
|
|
$this->error('PHPUnit executable not defined.'); |
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
$cmd = escapeshellarg($this->options['executable']) . ' '; |
81
|
1 |
|
if (isset($this->options['configFile'])) { |
82
|
|
|
$cmd .= '--configuration '; |
83
|
|
|
$cmd .= escapeshellarg($this->options['configFile']) . ' '; |
84
|
|
|
} |
85
|
1 |
|
$cmd .= escapeshellarg($this->target) . ' '; |
86
|
|
|
|
87
|
1 |
|
$currdir = getcwd(); |
88
|
1 |
|
$result = @chdir($this->workingDir); |
89
|
1 |
|
if(!$result){ |
90
|
|
|
$this->error("Cannot change working directory to '$this->workingDir'."); |
91
|
|
|
} |
92
|
|
|
|
93
|
1 |
|
$command = new Exec(); |
94
|
1 |
|
$command->setCommand($cmd); |
95
|
1 |
|
$result = $command->execute(); |
96
|
1 |
|
if ($result->getResult() !== 0) { |
97
|
|
|
$this->error(sprintf('Tests failed with code %d.', $result->getResult())); |
98
|
|
|
} |
99
|
|
|
|
100
|
1 |
|
$result = @chdir($currdir); |
101
|
1 |
|
if(!$result){ |
102
|
|
|
$this->error("Cannot change working directory back to '$currdir'."); |
103
|
|
|
} |
104
|
1 |
|
} |
105
|
|
|
|
106
|
|
|
} |