mageekguy\atoum\report\fields\runner\exceptions\cli: lines coverage

94% of 416

OPs

100% of 70

Lines

69% of 51

Branches

51% of 35

Paths
Method OPs OPs % Lines Line % Branches Branches % Paths Path %
mageekguy\atoum\report\fields\runner\exceptions\cli::__construct() 34 100% 9 100% 1 0% 1 100%
mageekguy\atoum\report\fields\runner\exceptions\cli::__toString() 193 91% 40 100% 23 61% 16 13%
mageekguy\atoum\report\fields\runner\exceptions\cli::setTitlePrompt() 16 100% 2 100% 1 100% 1 100%
mageekguy\atoum\report\fields\runner\exceptions\cli::getTitlePrompt() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\report\fields\runner\exceptions\cli::setTitleColorizer() 16 100% 2 100% 1 100% 1 100%
mageekguy\atoum\report\fields\runner\exceptions\cli::getTitleColorizer() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\report\fields\runner\exceptions\cli::setMethodPrompt() 16 100% 2 100% 1 100% 1 100%
mageekguy\atoum\report\fields\runner\exceptions\cli::getMethodPrompt() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\report\fields\runner\exceptions\cli::setMethodColorizer() 16 100% 2 100% 1 100% 1 100%
mageekguy\atoum\report\fields\runner\exceptions\cli::getMethodColorizer() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\report\fields\runner\exceptions\cli::setExceptionPrompt() 16 100% 2 100% 1 100% 1 100%
mageekguy\atoum\report\fields\runner\exceptions\cli::getExceptionPrompt() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\report\fields\runner\exceptions\cli::setExceptionColorizer() 16 100% 2 100% 1 100% 1 100%
mageekguy\atoum\report\fields\runner\exceptions\cli::getExceptionColorizer() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\report\fields\runner\exceptions\cli::colorizeTitle() 19 89% 1 100% 5 60% 2 50%
mageekguy\atoum\report\fields\runner\exceptions\cli::colorizeMethod() 19 89% 1 100% 5 60% 2 50%
mageekguy\atoum\report\fields\runner\exceptions\cli::colorizeException() 19 89% 1 100% 5 60% 2 50%
#
1
<?php
2

                    
3
namespace mageekguy\atoum\report\fields\runner\exceptions;
4

                    
5
use
6
	mageekguy\atoum,
7
	mageekguy\atoum\locale,
8
	mageekguy\atoum\cli\prompt,
9
	mageekguy\atoum\cli\colorizer,
10
	mageekguy\atoum\report
11
;
12

                    
13
class cli extends report\fields\runner\exceptions
14
{
15
	protected $titlePrompt = null;
16
	protected $titleColorizer = null;
17
	protected $methodPrompt = null;
18
	protected $methodColorizer = null;
19
	protected $exceptionPrompt = null;
20
	protected $exceptionColorizer = null;
21

                    
22
	public function __construct()100%
23
	{
24
		parent::__construct();
25

                    
26
		$this
27
			->setTitlePrompt()
28
			->setTitleColorizer()
29
			->setMethodPrompt()
30
			->setMethodColorizer()
31
			->setExceptionPrompt()
32
			->setExceptionColorizer()
33
		;
34
	}
35

                    
36
	public function __toString()100%
37
	{
38
		$string = '';
39

                    
40
		if ($this->runner !== null)
41
		{
42
			$exceptions = $this->runner->getScore()->getExceptions();
43

                    
44
			$sizeOfErrors = sizeof($exceptions);
45

                    
46
			if ($sizeOfErrors > 0)
47
			{
48
				$string .=
49
					$this->titlePrompt .
50
					sprintf(
51
						$this->locale->_('%s:'),
52
						$this->colorizeTitle(sprintf($this->locale->__('There is %d exception', 'There are %d exceptions', $sizeOfErrors), $sizeOfErrors))
53
					) .
54
					PHP_EOL
55
				;
56

                    
57
				$class = null;
58
				$method = null;
59

                    
60
				foreach ($exceptions as $exception)
61
				{
62
					if ($exception['class'] !== $class || $exception['method'] !== $method)
63
					{
64
						$string .=
65
							$this->methodPrompt .
66
							sprintf(
67
								$this->locale->_('%s:'),
68
								$this->colorizeMethod($exception['class'] . '::' . $exception['method'] . '()')
69
							) .
70
							PHP_EOL
71
						;
72

                    
73
						$class = $exception['class'];
74
						$method = $exception['method'];
75
					}
76

                    
77
					$string .=
78
						$this->exceptionPrompt .
79
						sprintf(
80
							$this->locale->_('%s:'),
81
							$this->colorizeException(sprintf($this->locale->_('An exception has been thrown in file %s on line %d'), $exception['file'], $exception['line']))
82
						) .
83
						PHP_EOL
84
					;
85

                    
86
					foreach (explode(PHP_EOL, rtrim($exception['value'])) as $line)
87
					{
88
						$string .= $this->exceptionPrompt . $line . PHP_EOL;
89
					}
90
				}
91
			}
92
		}
93

                    
94
		return $string;
95
	}
96

                    
97
	public function setTitlePrompt(prompt $prompt = null)100%
98
	{
99
		$this->titlePrompt = $prompt ?: new prompt();
100

                    
101
		return $this;
102
	}
103

                    
104
	public function getTitlePrompt()100%
105
	{
106
		return $this->titlePrompt;
107
	}
108

                    
109
	public function setTitleColorizer(colorizer $colorizer = null)100%
110
	{
111
		$this->titleColorizer = $colorizer ?: new colorizer();
112

                    
113
		return $this;
114
	}
115

                    
116
	public function getTitleColorizer()100%
117
	{
118
		return $this->titleColorizer;
119
	}
120

                    
121
	public function setMethodPrompt(prompt $prompt = null)100%
122
	{
123
		$this->methodPrompt = $prompt ?: new prompt();
124

                    
125
		return $this;
126
	}
127

                    
128
	public function getMethodPrompt()100%
129
	{
130
		return $this->methodPrompt;
131
	}
132

                    
133
	public function setMethodColorizer(colorizer $colorizer = null)100%
134
	{
135
		$this->methodColorizer = $colorizer ?: new colorizer();
136

                    
137
		return $this;
138
	}
139

                    
140
	public function getMethodColorizer()100%
141
	{
142
		return $this->methodColorizer;
143
	}
144

                    
145
	public function setExceptionPrompt(prompt $prompt = null)100%
146
	{
147
		$this->exceptionPrompt = $prompt ?: new prompt();
148

                    
149
		return $this;
150
	}
151

                    
152
	public function getExceptionPrompt()100%
153
	{
154
		return $this->exceptionPrompt;
155
	}
156

                    
157
	public function setExceptionColorizer(colorizer $colorizer = null)100%
158
	{
159
		$this->exceptionColorizer = $colorizer ?: new colorizer();
160

                    
161
		return $this;
162
	}
163

                    
164
	public function getExceptionColorizer()100%
165
	{
166
		return $this->exceptionColorizer;
167
	}
168

                    
169
	private function colorizeTitle($title)100%
170
	{
171
		return $this->titleColorizer === null ? $title : $this->titleColorizer->colorize($title);
172
	}
173

                    
174
	private function colorizeMethod($method)100%
175
	{
176
		return $this->methodColorizer === null ? $method : $this->methodColorizer->colorize($method);
177
	}
178

                    
179
	private function colorizeException($exception)100%
180
	{
181
		return $this->exceptionColorizer === null ? $exception : $this->exceptionColorizer->colorize($exception);
182
	}
183
}