mageekguy\atoum\asserters\dateTime: lines coverage

99% of 700

OPs

99% of 78

Lines

80% of 65

Branches

57% of 28

Paths
Method OPs OPs % Lines Line % Branches Branches % Paths Path %
mageekguy\atoum\asserters\dateTime::setWith() 44 100% 10 100% 8 88% 3 67%
mageekguy\atoum\asserters\dateTime::hasTimezone() 61 100% 6 100% 5 80% 2 50%
mageekguy\atoum\asserters\dateTime::hasYear() 53 100% 6 100% 5 80% 2 50%
mageekguy\atoum\asserters\dateTime::isInYear() 15 100% 1 100% 1 100% 1 100%
mageekguy\atoum\asserters\dateTime::hasMonth() 53 100% 6 100% 5 80% 2 50%
mageekguy\atoum\asserters\dateTime::isInMonth() 15 100% 1 100% 1 100% 1 100%
mageekguy\atoum\asserters\dateTime::hasDay() 53 100% 6 100% 5 80% 2 50%
mageekguy\atoum\asserters\dateTime::isInDay() 15 100% 1 100% 1 100% 1 100%
mageekguy\atoum\asserters\dateTime::hasDate() 65 100% 6 100% 5 80% 2 50%
mageekguy\atoum\asserters\dateTime::hasHours() 53 100% 6 100% 5 80% 2 50%
mageekguy\atoum\asserters\dateTime::hasMinutes() 53 100% 6 100% 5 80% 2 50%
mageekguy\atoum\asserters\dateTime::hasSeconds() 53 100% 7 100% 5 80% 2 50%
mageekguy\atoum\asserters\dateTime::hasTime() 65 100% 6 100% 5 80% 2 50%
mageekguy\atoum\asserters\dateTime::hasDateAndTime() 74 100% 6 100% 5 80% 2 50%
mageekguy\atoum\asserters\dateTime::valueIsSet() 28 68% 4 75% 4 50% 2 50%
#
1
<?php
2

                    
3
namespace mageekguy\atoum\asserters;
4

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

                    
10
class dateTime extends asserters\object
11
{
12
	public function setWith($value, $checkType = true)100%
13
	{
14
		parent::setWith($value, false);
15

                    
16
		if ($checkType === true)
17
		{
18
			if ($this->value instanceof \dateTime)
19
			{
20
				$this->pass();
21
			}
22
			else
23
			{
24
				$this->fail($this->_('%s is not an instance of \\dateTime', $this));
25
			}
26
		}
27

                    
28
		return $this;
29
	}
30

                    
31
	public function hasTimezone(\dateTimezone $timezone, $failMessage = null)100%
32
	{
33
		if ($this->valueIsSet()->value->getTimezone()->getName() == $timezone->getName())
34
		{
35
			$this->pass();
36
		}
37
		else
38
		{
39
			$this->fail($failMessage ?: $this->_('Timezone is %s instead of %s', $this->value->getTimezone()->getName(), $timezone->getName()));
40
		}
41

                    
42
		return $this;
43
	}
44

                    
45
	public function hasYear($year, $failMessage = null)100%
46
	{
47
		if ($this->valueIsSet()->value->format('Y') === sprintf('%04d', $year))
48
		{
49
			$this->pass();
50
		}
51
		else
52
		{
53
			$this->fail($failMessage ?: $this->_('Year is %s instead of %s', $this->value->format('Y'), $year));
54
		}
55

                    
56
		return $this;
57
	}
58

                    
59
	public function isInYear()100%
60
	{
61
		throw new exceptions\runtime('The method ' . __METHOD__ . ' is deprecated, please use ' . __CLASS__ . '::hasYear instead');
62
	}
63

                    
64
	public function hasMonth($month, $failMessage = null)100%
65
	{
66
		if ($this->valueIsSet()->value->format('m') === sprintf('%02d', $month))
67
		{
68
			$this->pass();
69
		}
70
		else
71
		{
72
			$this->fail($failMessage ?: $this->_('Month is %s instead of %02d', $this->value->format('m'), $month));
73
		}
74

                    
75
		return $this;
76
	}
77

                    
78
	public function isInMonth()100%
79
	{
80
		throw new exceptions\runtime('The method ' . __METHOD__ . ' is deprecated, please use ' . __CLASS__ . '::hasMonth instead');
81
	}
82

                    
83
	public function hasDay($day, $failMessage = null)100%
84
	{
85
		if ($this->valueIsSet()->value->format('d') === sprintf('%02d', $day))
86
		{
87
			$this->pass();
88
		}
89
		else
90
		{
91
			$this->fail($failMessage ?: $this->_('Day is %s instead of %02d', $this->value->format('d'), $day));
92
		}
93

                    
94
		return $this;
95
	}
96

                    
97
	public function isInDay()100%
98
	{
99
		throw new exceptions\runtime('The method ' . __METHOD__ . ' is deprecated, please use ' . __CLASS__ . '::hasDay instead');
100
	}
101

                    
102
	public function hasDate($year, $month, $day, $failMessage = null)100%
103
	{
104
		if ($this->valueIsSet()->value->format('Y-m-d') === sprintf('%04d-%02d-%02d', $year, $month, $day))
105
		{
106
			$this->pass();
107
		}
108
		else
109
		{
110
			$this->fail($failMessage ?: $this->_('Date is %s instead of %s', $this->value->format('Y-m-d'), sprintf('%04d-%02d-%02d', $year, $month, $day)));
111
		}
112

                    
113
		return $this;
114
	}
115

                    
116
	public function hasHours($hours, $failMessage = null)100%
117
	{
118
		if ($this->valueIsSet()->value->format('H') === sprintf('%02d', $hours))
119
		{
120
			$this->pass();
121
		}
122
		else
123
		{
124
			$this->fail($failMessage ?: $this->_('Hours are %s instead of %02d', $this->value->format('H'), $hours));
125
		}
126

                    
127
		return $this;
128
	}
129

                    
130
	public function hasMinutes($minutes, $failMessage = null)100%
131
	{
132
		if ($this->valueIsSet()->value->format('i') === sprintf('%02d', $minutes))
133
		{
134
			$this->pass();
135
		}
136
		else
137
		{
138
			$this->fail($failMessage ?: $this->_('Minutes are %s instead of %02d', $this->value->format('i'), $minutes));
139
		}
140

                    
141
		return $this;
142
	}
143

                    
144
	public function hasSeconds($seconds, $failMessage = null)
145
	{
146
		if ($this->valueIsSet()->value->format('s') === sprintf('%02d', $seconds))
147
		{
148
			$this->pass();
149
		}
150
		else
151
		{
152
			$this->fail($failMessage ?: $this->_('Seconds are %s instead of %02d', $this->value->format('s'), $seconds));
153
		}
154

                    
155
		return $this;
156
	}
157

                    
158
	public function hasTime($hours, $minutes, $seconds, $failMessage = null)100%
159
	{
160
		if ($this->valueIsSet()->value->format('H:i:s') === sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds))
161
		{
162
			$this->pass();
163
		}
164
		else
165
		{
166
			$this->fail($failMessage ?: $this->_('Time is %s instead of %s', $this->value->format('H:i:s'), sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds)));
167
		}
168

                    
169
		return $this;
170
	}
171

                    
172
	public function hasDateAndTime($year, $month, $day, $hours, $minutes, $seconds, $failMessage = null)100%
173
	{
174
		if ($this->valueIsSet()->value->format('Y-m-d H:i:s') === sprintf('%04d-%02d-%02d %02d:%02d:%02d', $year, $month, $day, $hours, $minutes, $seconds))
175
		{
176
			$this->pass();
177
		}
178
		else
179
		{
180
			$this->fail($failMessage ?: $this->_('Datetime is %s instead of %s', $this->value->format('Y-m-d H:i:s'), sprintf('%04d-%02d-%02d %02d:%02d:%02d', $year, $month, $day, $hours, $minutes, $seconds)));
181
		}
182

                    
183
		return $this;
184
	}
185

                    
186
	protected function valueIsSet($message = 'Instance of \dateTime is undefined')75%
187
	{
188
		if (parent::valueIsSet($message)->value instanceof \dateTime === false)
189
		{
190
			throw new exceptions\logic($message);
191
		}
192

                    
193
		return $this;
194
	}
195
}