82% of 375OPs |
95% of 58Lines |
73% of 45Branches |
19% of 59Paths |
# | |
---|---|
1 |
<?php |
2 |
|
3 |
namespace mageekguy\atoum\report\fields\runner\failures; |
4 |
|
5 |
use |
6 |
mageekguy\atoum, |
7 |
mageekguy\atoum\locale, |
8 |
mageekguy\atoum\cli\prompt, |
9 |
mageekguy\atoum\cli\colorizer, |
10 |
mageekguy\atoum\report\fields\runner |
11 |
; |
12 |
|
13 |
class cli extends runner\failures |
14 |
{ |
15 |
protected $titlePrompt = null; |
16 |
protected $titleColorizer = null; |
17 |
protected $methodPrompt = null; |
18 |
protected $methodColorizer = null; |
19 |
|
20 |
public function __construct()100% |
21 |
{ |
22 |
parent::__construct(); |
23 |
|
24 |
$this |
25 |
->setTitlePrompt() |
26 |
->setTitleColorizer() |
27 |
->setMethodPrompt() |
28 |
->setMethodColorizer() |
29 |
; |
30 |
} |
31 |
|
32 |
public function __toString()92% |
33 |
{ |
34 |
$string = ''; |
35 |
|
36 |
if ($this->runner !== null) |
37 |
{ |
38 |
$fails = $this->runner->getScore()->getFailAssertions(); |
39 |
|
40 |
$numberOfFails = sizeof($fails); |
41 |
|
42 |
if ($numberOfFails > 0) |
43 |
{ |
44 |
$string .= |
45 |
$this->titlePrompt . |
46 |
sprintf( |
47 |
$this->locale->_('%s:'), |
48 |
$this->titleColorizer->colorize(sprintf($this->locale->__('There is %d failure', 'There are %d failures', $numberOfFails), $numberOfFails)) |
49 |
) . |
50 |
PHP_EOL |
51 |
; |
52 |
|
53 |
foreach ($fails as $fail) |
54 |
{ |
55 |
$string .= |
56 |
$this->methodPrompt . |
57 |
sprintf( |
58 |
'%s:', |
59 |
$this->methodColorizer->colorize(($fail['class'] . '::' . $fail['method'] . '()')) |
60 |
) . |
61 |
PHP_EOL |
62 |
; |
63 |
|
64 |
switch (true) |
65 |
{ |
66 |
case $fail['case'] === null && $fail['dataSetKey'] === null: |
67 |
$string .= sprintf($this->locale->_('In file %s on line %d, %s failed: %s'), $fail['file'], $fail['line'], $fail['asserter'], $fail['fail']); |
68 |
break; |
69 |
|
70 |
case $fail['case'] === null && $fail['dataSetKey'] !== null: |
71 |
$string .= sprintf($this->locale->_('In file %s on line %d, %s failed for data set [%s] of data provider %s: %s'), $fail['file'], $fail['line'], $fail['asserter'], $fail['dataSetKey'], $fail['dataSetProvider'], $fail['fail']); |
72 |
break; |
73 |
|
74 |
case $fail['case'] !== null && $fail['dataSetKey'] === null: |
75 |
$string .= sprintf($this->locale->_('In file %s on line %d in case \'%s\', %s failed: %s'), $fail['file'], $fail['line'], $fail['case'], $fail['asserter'], $fail['fail']); |
76 |
break; |
77 |
|
78 |
case $fail['case'] !== null && $fail['dataSetKey'] !== null: |
79 |
$string .= sprintf($this->locale->_('In file %s on line %d in case \'%s\', %s failed for data set [%s] of data provider %s: %s'), $fail['file'], $fail['line'], $fail['case'], $fail['asserter'], $fail['dataSetKey'], $fail['dataSetProvider'], $fail['fail']); |
80 |
break; |
81 |
} |
82 |
|
83 |
$string .= PHP_EOL; |
84 |
} |
85 |
} |
86 |
} |
87 |
|
88 |
return $string; |
89 |
} |
90 |
|
91 |
public function setTitlePrompt(prompt $prompt = null)100% |
92 |
{ |
93 |
$this->titlePrompt = $prompt ?: new prompt(); |
94 |
|
95 |
return $this; |
96 |
} |
97 |
|
98 |
public function getTitlePrompt()100% |
99 |
{ |
100 |
return $this->titlePrompt; |
101 |
} |
102 |
|
103 |
public function setTitleColorizer(colorizer $colorizer = null)100% |
104 |
{ |
105 |
$this->titleColorizer = $colorizer ?: new colorizer(); |
106 |
|
107 |
return $this; |
108 |
} |
109 |
|
110 |
public function getTitleColorizer()100% |
111 |
{ |
112 |
return $this->titleColorizer; |
113 |
} |
114 |
|
115 |
public function setMethodPrompt(prompt $prompt = null)100% |
116 |
{ |
117 |
$this->methodPrompt = $prompt ?: new prompt(); |
118 |
|
119 |
return $this; |
120 |
} |
121 |
|
122 |
public function getMethodPrompt()100% |
123 |
{ |
124 |
return $this->methodPrompt; |
125 |
} |
126 |
|
127 |
public function setMethodColorizer(colorizer $colorizer = null)100% |
128 |
{ |
129 |
$this->methodColorizer = $colorizer ?: new colorizer(); |
130 |
|
131 |
return $this; |
132 |
} |
133 |
|
134 |
public function getMethodColorizer()100% |
135 |
{ |
136 |
return $this->methodColorizer; |
137 |
} |
138 |
} |