1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the LGPL. For more information please see |
17
|
|
|
* <http://phing.info>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* A wrapper for the implementations of PHPUnit2ResultFormatter. |
22
|
|
|
* |
23
|
|
|
* @author Michiel Rook <[email protected]> |
24
|
|
|
* @package phing.tasks.ext.phpunit |
25
|
|
|
* @since 2.1.0 |
26
|
|
|
*/ |
27
|
|
|
class FormatterElement |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var PHPUnitResultFormatter7 $fomatter |
31
|
|
|
*/ |
32
|
|
|
protected $formatter; |
33
|
|
|
|
34
|
|
|
protected $type = ""; |
35
|
|
|
|
36
|
|
|
protected $useFile = true; |
37
|
|
|
|
38
|
|
|
protected $toDir = "."; |
39
|
|
|
|
40
|
|
|
protected $outfile = ""; |
41
|
|
|
|
42
|
|
|
protected $parent; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Sets parent task |
46
|
|
|
* |
47
|
|
|
* @param Task $parent Calling Task |
48
|
|
|
*/ |
49
|
2 |
|
public function setParent($parent) |
50
|
|
|
{ |
51
|
2 |
|
$this->parent = $parent; |
52
|
2 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Loads a specific formatter type |
56
|
|
|
* |
57
|
|
|
* @param string $type |
58
|
|
|
*/ |
59
|
2 |
|
public function setType($type) |
60
|
|
|
{ |
61
|
2 |
|
$this->type = $type; |
62
|
2 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Loads a specific formatter class |
66
|
|
|
* |
67
|
|
|
* @param $className |
68
|
|
|
*/ |
69
|
|
|
public function setClassName($className) |
70
|
|
|
{ |
71
|
|
|
$classNameNoDot = Phing::import($className); |
72
|
|
|
|
73
|
|
|
$this->formatter = new $classNameNoDot(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Sets whether to store formatting results in a file |
78
|
|
|
* |
79
|
|
|
* @param $useFile |
80
|
|
|
*/ |
81
|
2 |
|
public function setUseFile($useFile) |
82
|
|
|
{ |
83
|
2 |
|
$this->useFile = $useFile; |
84
|
2 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns whether to store formatting results in a file |
88
|
|
|
*/ |
89
|
2 |
|
public function getUseFile() |
90
|
|
|
{ |
91
|
2 |
|
return $this->useFile; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Sets output directory |
96
|
|
|
* |
97
|
|
|
* @param string $toDir |
98
|
|
|
* @throws IOException |
99
|
|
|
* @throws NullPointerException |
100
|
|
|
*/ |
101
|
|
|
public function setToDir($toDir) |
102
|
|
|
{ |
103
|
|
|
if (!is_dir($toDir)) { |
104
|
|
|
$toDir = new PhingFile($toDir); |
105
|
|
|
$toDir->mkdirs(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$this->toDir = $toDir; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Returns output directory |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function getToDir() |
117
|
|
|
{ |
118
|
|
|
return $this->toDir; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Sets output filename |
123
|
|
|
* |
124
|
|
|
* @param string $outfile |
125
|
|
|
*/ |
126
|
|
|
public function setOutfile($outfile) |
127
|
|
|
{ |
128
|
|
|
$this->outfile = $outfile; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Returns output filename |
133
|
|
|
* |
134
|
|
|
* @return string |
135
|
|
|
*/ |
136
|
|
|
public function getOutfile() |
137
|
|
|
{ |
138
|
|
|
if ($this->outfile) { |
139
|
|
|
return $this->outfile; |
140
|
|
|
} else { |
141
|
|
|
return $this->formatter->getPreferredOutfile() . $this->getExtension(); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Returns extension |
147
|
|
|
* |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
|
|
public function getExtension() |
151
|
|
|
{ |
152
|
|
|
return $this->formatter->getExtension(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Returns formatter object |
157
|
|
|
* |
158
|
|
|
* @throws BuildException |
159
|
|
|
* @return PHPUnitResultFormatter7 |
160
|
|
|
*/ |
161
|
2 |
|
public function getFormatter() |
162
|
|
|
{ |
163
|
2 |
|
if ($this->formatter !== null) { |
164
|
2 |
|
return $this->formatter; |
165
|
|
|
} |
166
|
|
|
|
167
|
2 |
|
if ($this->type === "summary") { |
168
|
2 |
|
$this->formatter = new SummaryPHPUnitResultFormatter7($this->parent); |
169
|
2 |
|
} elseif ($this->type === "clover") { |
170
|
|
|
$this->formatter = new CloverPHPUnitResultFormatter7($this->parent); |
171
|
2 |
|
} elseif ($this->type === "xml") { |
172
|
1 |
|
$this->formatter = new XMLPHPUnitResultFormatter7($this->parent); |
173
|
2 |
|
} elseif ($this->type === "plain") { |
174
|
2 |
|
$this->formatter = new PlainPHPUnitResultFormatter7($this->parent); |
175
|
|
|
} elseif ($this->type === "crap4j") { |
176
|
|
|
$this->formatter = new Crap4JPHPUnitResultFormatter7($this->parent); |
177
|
|
|
} else { |
178
|
|
|
throw new BuildException("Formatter '" . $this->type . "' not implemented"); |
179
|
|
|
} |
180
|
|
|
|
181
|
2 |
|
return $this->formatter; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|