mageekguy\atoum\asserters\error: lines coverage

93% of 602

OPs

97% of 114

Lines

79% of 131

Branches

43% of 81

Paths
Method OPs OPs % Lines Line % Branches Branches % Paths Path %
mageekguy\atoum\asserters\error::__construct() 22 100% 3 100% 1 0% 1 100%
mageekguy\atoum\asserters\error::__get() 47 64% 9 67% 15 67% 5 80%
mageekguy\atoum\asserters\error::setWithTest() 22 100% 2 100% 1 100% 1 100%
mageekguy\atoum\asserters\error::setWith() 17 100% 4 100% 1 100% 1 100%
mageekguy\atoum\asserters\error::setScore() 16 100% 2 100% 1 100% 1 100%
mageekguy\atoum\asserters\error::getScore() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\asserters\error::getMessage() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\asserters\error::getType() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\asserters\error::exists() 138 98% 21 100% 26 92% 23 4%
mageekguy\atoum\asserters\error::notExists() 136 98% 21 100% 26 92% 23 4%
mageekguy\atoum\asserters\error::withType() 9 100% 2 100% 1 100% 1 100%
mageekguy\atoum\asserters\error::withAnyType() 9 100% 2 100% 1 100% 1 100%
mageekguy\atoum\asserters\error::messageIsPattern() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\asserters\error::withMessage() 13 100% 3 100% 1 100% 1 100%
mageekguy\atoum\asserters\error::withPattern() 13 100% 3 100% 1 100% 1 100%
mageekguy\atoum\asserters\error::withAnyMessage() 13 100% 3 100% 1 100% 1 100%
mageekguy\atoum\asserters\error::getAsString() 123 86% 35 100% 51 67% 17 94%
#
1
<?php
2

                    
3
namespace mageekguy\atoum\asserters;
4

                    
5
use
6
	mageekguy\atoum,
7
	mageekguy\atoum\exceptions
8
;
9

                    
10
class error extends atoum\asserter
11
{
12
	protected $score = null;
13
	protected $message = null;
14
	protected $type = null;
15
	protected $messageIsPattern = false;
16

                    
17
	public function __construct(atoum\asserter\generator $generator = null, atoum\test\score $score = null, atoum\locale $locale = null)100%
18
	{
19
		parent::__construct($generator, null, $locale);
20

                    
21
		$this->setScore($score);
22
	}
23

                    
24
	public function __get($asserter)67%
25
	{
26
		switch (strtolower($asserter))
27
		{
28
			case 'exists':
29
			case 'notexists':
30
			case 'withanytype':
31
			case 'withanymessage':
32
				return $this->{$asserter}();
33

                    
34
			default:
35
				return parent::__get($asserter);
36
		}
37
	}
38

                    
39
	public function setWithTest(atoum\test $test)100%
40
	{
41
		$this->setScore($test->getScore());
42

                    
43
		return parent::setWithTest($test);
44
	}
45

                    
46
	public function setWith($message = null, $type = null)100%
47
	{
48
		return $this
49
			->withType($type)
50
			->withMessage($message)
51
		;
52
	}
53

                    
54
	public function setScore(atoum\test\score $score = null)100%
55
	{
56
		$this->score = $score ?: new atoum\test\score();
57

                    
58
		return $this;
59
	}
60

                    
61
	public function getScore()100%
62
	{
63
		return $this->score;
64
	}
65

                    
66
	public function getMessage()100%
67
	{
68
		return $this->message;
69
	}
70

                    
71
	public function getType()100%
72
	{
73
		return $this->type;
74
	}
75

                    
76
	public function exists()100%
77
	{
78
		$key = $this->score->errorExists($this->message, $this->type, $this->messageIsPattern);
79

                    
80
		if ($key !== null)
81
		{
82
			$this->score->deleteError($key);
83
			$this->pass();
84
		}
85
		else
86
		{
87
			switch (true)
88
			{
89
				case $this->type === null && $this->message === null:
90
					$failReason = $this->_('error does not exist');
91
					break;
92

                    
93
				case $this->type === null && $this->message !== null:
94
					$failReason = $this->_('error with message \'%s\' does not exist', $this->message);
95
					break;
96

                    
97
				case $this->type !== null && $this->message === null:
98
					$failReason = $this->_('error of type %s does not exist', self::getAsString($this->type));
99
					break;
100

                    
101
				default:
102
					$failReason = $this->_('error of type %s with message \'%s\' does not exist', self::getAsString($this->type), $this->message);
103
			}
104

                    
105
			$this->fail($failReason);
106
		}
107

                    
108
		return $this;
109
	}
110

                    
111
	public function notExists()100%
112
	{
113
		$score = $this->getScore();
114

                    
115
		$key = $score->errorExists($this->message, $this->type, $this->messageIsPattern);
116

                    
117
		if ($key === null)
118
		{
119
			$this->pass();
120
		}
121
		else
122
		{
123
			switch (true)
124
			{
125
				case $this->type === null && $this->message === null:
126
					$failReason = $this->_('error exists');
127
					break;
128

                    
129
				case $this->type === null && $this->message !== null:
130
					$failReason = $this->_('error with message \'%s\' exists', $this->message);
131
					break;
132

                    
133
				case $this->type !== null && $this->message === null:
134
					$failReason = $this->_('error of type %s exists', self::getAsString($this->type));
135
					break;
136

                    
137
				default:
138
					$failReason = $this->_('error of type %s with message \'%s\' exists', self::getAsString($this->type), $this->message);
139
			}
140

                    
141
			$this->fail($failReason);
142
		}
143

                    
144
		return $this;
145
	}
146

                    
147
	public function withType($type)100%
148
	{
149
		$this->type = $type;
150

                    
151
		return $this;
152
	}
153

                    
154
	public function withAnyType()100%
155
	{
156
		$this->type = null;
157

                    
158
		return $this;
159
	}
160

                    
161
	public function messageIsPattern()100%
162
	{
163
		return $this->messageIsPattern;
164
	}
165

                    
166
	public function withMessage($message)100%
167
	{
168
		$this->message = $message;
169
		$this->messageIsPattern = false;
170

                    
171
		return $this;
172
	}
173

                    
174
	public function withPattern($pattern)100%
175
	{
176
		$this->message = $pattern;
177
		$this->messageIsPattern = true;
178

                    
179
		return $this;
180
	}
181

                    
182
	public function withAnyMessage()100%
183
	{
184
		$this->message = null;
185
		$this->messageIsPattern = false;
186

                    
187
		return $this;
188
	}
189

                    
190
	public static function getAsString($errorType)100%
191
	{
192
		switch ($errorType)
193
		{
194
			case E_ERROR:
195
				return 'E_ERROR';
196

                    
197
			case E_WARNING:
198
				return 'E_WARNING';
199

                    
200
			case E_PARSE:
201
				return 'E_PARSE';
202

                    
203
			case E_NOTICE:
204
				return 'E_NOTICE';
205

                    
206
			case E_CORE_ERROR:
207
				return 'E_CORE_ERROR';
208

                    
209
			case E_CORE_WARNING:
210
				return 'E_CORE_WARNING';
211

                    
212
			case E_COMPILE_ERROR:
213
				return 'E_COMPILE_ERROR';
214

                    
215
			case E_COMPILE_WARNING:
216
				return 'E_COMPILE_WARNING';
217

                    
218
			case E_USER_ERROR:
219
				return 'E_USER_ERROR';
220

                    
221
			case E_USER_WARNING:
222
				return 'E_USER_WARNING';
223

                    
224
			case E_USER_NOTICE:
225
				return 'E_USER_NOTICE';
226

                    
227
			case E_STRICT:
228
				return 'E_STRICT';
229

                    
230
			case E_RECOVERABLE_ERROR:
231
				return 'E_RECOVERABLE_ERROR';
232

                    
233
			case E_DEPRECATED:
234
				return 'E_DEPRECATED';
235

                    
236
			case E_USER_DEPRECATED:
237
				return 'E_USER_DEPRECATED';
238

                    
239
			case E_ALL:
240
				return 'E_ALL';
241

                    
242
			default:
243
				return 'UNKNOWN';
244
		}
245
	}
246
}