invalidConstructorArgumentsProvider()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 124

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 124
rs 8
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace DataValues\Tests;
4
5
use DataValues\TimeValue;
6
7
/**
8
 * @covers DataValues\TimeValue
9
 *
10
 * @group DataValue
11
 * @group DataValueExtensions
12
 *
13
 * @license GPL-2.0+
14
 * @author Jeroen De Dauw < [email protected] >
15
 * @author Thiemo Kreuz
16
 */
17
class TimeValueTest extends DataValueTest {
18
19
	/**
20
	 * @see DataValueTest::getClass
21
	 *
22
	 * @return string
23
	 */
24
	public function getClass() {
25
		return TimeValue::class;
26
	}
27
28
	public function validConstructorArgumentsProvider() {
29
		return array(
30
			'1 January' => array(
31
				'+2013-01-01T00:00:00Z',
32
				0, 0, 0,
33
				TimeValue::PRECISION_SECOND,
34
				'http://nyan.cat/original.php'
35
			),
36
			'Maximum timezone' => array(
37
				'+2013-01-01T00:00:00Z',
38
				7200, 9001, 9001,
39
				TimeValue::PRECISION_YEAR1G,
40
				'http://nyan.cat/original.php'
41
			),
42
			'Minimum timezone' => array(
43
				'+2013-01-01T00:00:00Z',
44
				-7200, 0, 42,
45
				TimeValue::PRECISION_YEAR,
46
				'http://nyan.cat/original.php'
47
			),
48
			'Negative year' => array(
49
				'-0005-01-01T00:00:00Z',
50
				0, 0, 0,
51
				TimeValue::PRECISION_SECOND,
52
				'http://nyan.cat/original.php'
53
			),
54
			'No day' => array(
55
				'+2015-01-00T00:00:00Z',
56
				0, 0, 0,
57
				TimeValue::PRECISION_YEAR,
58
				'http://nyan.cat/original.php'
59
			),
60
			'No day and month' => array(
61
				'+2015-00-00T00:00:00Z',
62
				0, 0, 0,
63
				TimeValue::PRECISION_YEAR,
64
				'http://nyan.cat/original.php'
65
			),
66
			'Zero' => array(
67
				'+0000-00-00T00:00:00Z',
68
				0, 0, 0,
69
				TimeValue::PRECISION_SECOND,
70
				'http://nyan.cat/original.php'
71
			),
72
			'Minimum timestamp' => array(
73
				'-9999999999999999-12-31T23:59:61Z',
74
				0, 0, 0,
75
				TimeValue::PRECISION_SECOND,
76
				'http://nyan.cat/original.php'
77
			),
78
			'Maximum timestamp' => array(
79
				'+9999999999999999-12-31T23:59:61Z',
80
				0, 0, 0,
81
				TimeValue::PRECISION_SECOND,
82
				'http://nyan.cat/original.php'
83
			),
84
			'Leap year' => array(
85
				'+2000-02-29T00:00:00Z',
86
				0, 0, 0,
87
				TimeValue::PRECISION_DAY,
88
				'http://nyan.cat/original.php'
89
			),
90
			'Non-leap year 29 February' => array(
91
				'+2015-02-29T00:00:00Z',
92
				0, 0, 0,
93
				TimeValue::PRECISION_DAY,
94
				'http://nyan.cat/original.php'
95
			),
96
			'31 November' => array(
97
				'+2015-11-31T00:00:00Z',
98
				0, 0, 0,
99
				TimeValue::PRECISION_DAY,
100
				'http://nyan.cat/original.php'
101
			),
102
		);
103
	}
104
105
	public function invalidConstructorArgumentsProvider() {
106
		return array(
107
			'String timezone' => array(
108
				'+00000002013-01-01T00:00:00Z',
109
				'0', 0, 0,
110
				TimeValue::PRECISION_SECOND,
111
				'http://nyan.cat/original.php'
112
			),
113
			'Float timezone' => array(
114
				'+00000002013-01-01T00:00:00Z',
115
				4.2, 0, 0,
116
				TimeValue::PRECISION_SECOND,
117
				'http://nyan.cat/original.php'
118
			),
119
			'Timezone out of range' => array(
120
				'+00000002013-01-01T00:00:00Z',
121
				-20 * 3600, 0, 0,
122
				TimeValue::PRECISION_SECOND,
123
				'http://nyan.cat/original.php'
124
			),
125
			'Precision out of range' => array(
126
				'+00000002013-01-01T00:00:00Z',
127
				0, 0, 0,
128
				15,
129
				'http://nyan.cat/original.php'
130
			),
131
			'Integer timestamp' => array(
132
				42,
133
				0, 0, 0,
134
				TimeValue::PRECISION_SECOND,
135
				'http://nyan.cat/original.php'
136
			),
137
			'Float before' => array(
138
				'+00000002013-01-01T00:00:00Z',
139
				0, 4.2, 0,
140
				TimeValue::PRECISION_SECOND,
141
				'http://nyan.cat/original.php'
142
			),
143
			'Negative after' => array(
144
				'+00000002013-01-01T00:00:00Z',
145
				0, 0, -1,
146
				TimeValue::PRECISION_SECOND,
147
				'http://nyan.cat/original.php'
148
			),
149
			'Non-ISO timestamp' => array(
150
				'bla',
151
				0, 0, 0,
152
				TimeValue::PRECISION_SECOND,
153
				'http://nyan.cat/original.php'
154
			),
155
			'Invalid separators' => array(
156
				'+00000002013/01/01 00:00:00',
157
				0, 0, 0,
158
				TimeValue::PRECISION_SECOND,
159
				'http://nyan.cat/original.php'
160
			),
161
			'No month' => array(
162
				'+2015-00-01T00:00:00Z',
163
				0, 0, 0,
164
				TimeValue::PRECISION_DAY,
165
				'http://nyan.cat/original.php'
166
			),
167
			'No day but hour' => array(
168
				'+2015-01-00T01:00:00Z',
169
				0, 0, 0,
170
				TimeValue::PRECISION_DAY,
171
				'http://nyan.cat/original.php'
172
			),
173
			'No day but minute' => array(
174
				'+2015-01-00T00:01:00Z',
175
				0, 0, 0,
176
				TimeValue::PRECISION_DAY,
177
				'http://nyan.cat/original.php'
178
			),
179
			'No day but second' => array(
180
				'+2015-01-00T00:00:01Z',
181
				0, 0, 0,
182
				TimeValue::PRECISION_DAY,
183
				'http://nyan.cat/original.php'
184
			),
185
			'Month out of range' => array(
186
				'+00000002013-13-01T00:00:00Z',
187
				0, 0, 0,
188
				TimeValue::PRECISION_SECOND,
189
				'http://nyan.cat/original.php'
190
			),
191
			'Day out of range' => array(
192
				'+00000002013-01-32T00:00:00Z',
193
				0, 0, 0,
194
				TimeValue::PRECISION_SECOND,
195
				'http://nyan.cat/original.php'
196
			),
197
			'Hour out of range' => array(
198
				'+00000002013-01-01T24:00:00Z',
199
				0, 0, 0,
200
				TimeValue::PRECISION_SECOND,
201
				'http://nyan.cat/original.php'
202
			),
203
			'Minute out of range' => array(
204
				'+00000002013-01-01T00:60:00Z',
205
				0, 0, 0,
206
				TimeValue::PRECISION_SECOND,
207
				'http://nyan.cat/original.php'
208
			),
209
			'Second out of range' => array(
210
				'+00000002013-01-01T00:00:62Z',
211
				0, 0, 0,
212
				TimeValue::PRECISION_SECOND,
213
				'http://nyan.cat/original.php'
214
			),
215
			'Invalid timezone' => array(
216
				'+00000002013-01-01T00:00:00+60',
217
				0, 0, 0,
218
				TimeValue::PRECISION_SECOND,
219
				'http://nyan.cat/original.php'
220
			),
221
			'Year to long' => array(
222
				'+00000000000000001-01-01T00:00:00Z',
223
				0, 0, 0,
224
				TimeValue::PRECISION_DAY,
225
				'http://nyan.cat/original.php'
226
			),
227
		);
228
	}
229
230
	/**
231
	 * @dataProvider instanceProvider
232
	 */
233
	public function testGetTime( TimeValue $time, array $arguments ) {
234
		$this->assertEquals( $arguments[0], $time->getTime() );
235
	}
236
237
	/**
238
	 * @dataProvider instanceProvider
239
	 */
240
	public function testGetTimezone( TimeValue $time, array $arguments ) {
241
		$this->assertEquals( $arguments[1], $time->getTimezone() );
242
	}
243
244
	/**
245
	 * @dataProvider instanceProvider
246
	 */
247
	public function testGetBefore( TimeValue $time, array $arguments ) {
248
		$this->assertEquals( $arguments[2], $time->getBefore() );
249
	}
250
251
	/**
252
	 * @dataProvider instanceProvider
253
	 */
254
	public function testGetAfter( TimeValue $time, array $arguments ) {
255
		$this->assertEquals( $arguments[3], $time->getAfter() );
256
	}
257
258
	/**
259
	 * @dataProvider instanceProvider
260
	 */
261
	public function testGetPrecision( TimeValue $time, array $arguments ) {
262
		$this->assertEquals( $arguments[4], $time->getPrecision() );
263
	}
264
265
	/**
266
	 * @dataProvider instanceProvider
267
	 */
268
	public function testGetCalendarModel( TimeValue $time, array $arguments ) {
269
		$this->assertEquals( $arguments[5], $time->getCalendarModel() );
270
	}
271
272
	/**
273
	 * @dataProvider instanceProvider
274
	 */
275
	public function testGetValue( TimeValue $time, array $arguments ) {
0 ignored issues
show
Unused Code introduced by
The parameter $arguments is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
276
		$this->assertTrue( $time->equals( $time->getValue() ) );
277
	}
278
279
	/**
280
	 * @dataProvider unpaddedYearsProvider
281
	 */
282
	public function testGivenUnpaddedYear_yearIsPadded( $year, $expected ) {
283
		$timeValue = new TimeValue(
284
			$year . '-01-01T00:00:00Z',
285
			0, 0, 0,
286
			TimeValue::PRECISION_DAY,
287
			'Stardate'
288
		);
289
		$this->assertSame( $expected . '-01-01T00:00:00Z', $timeValue->getTime() );
290
	}
291
292
	public function unpaddedYearsProvider() {
293
		return array(
294
			array( '+1', '+0001' ),
295
			array( '-10', '-0010' ),
296
			array( '+2015', '+2015' ),
297
			array( '+02015', '+2015' ),
298
			array( '+00000010000', '+10000' ),
299
			array( '+0000000000000001', '+0001' ),
300
			array( '+9999999999999999', '+9999999999999999' ),
301
		);
302
	}
303
304
}
305