|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JhFlexiTimeTest\Options; |
|
4
|
|
|
|
|
5
|
|
|
use JhFlexiTime\Options\BookingOptions; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class BookingOptionsTest |
|
9
|
|
|
* @package JhFlexiTimeTest\Options |
|
10
|
|
|
* @author Aydin Hassan <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class BookingOptionsTest extends \PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Test The default options are correct |
|
16
|
|
|
*/ |
|
17
|
|
|
public function testDefaults() |
|
18
|
|
|
{ |
|
19
|
|
|
$options = new BookingOptions(); |
|
20
|
|
|
$this->assertFalse($options->getMinStartTime(), 'min_start_time must default to false'); |
|
21
|
|
|
$this->assertFalse($options->getMaxStartTime(), 'max_start_time must default to false'); |
|
22
|
|
|
$this->assertFalse($options->getMinEndTime(), 'min_end_time must default to false'); |
|
23
|
|
|
$this->assertFalse($options->getMaxEndTime(), 'max_end_time must default to false'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testSetValues() |
|
27
|
|
|
{ |
|
28
|
|
|
$options = new BookingOptions([ |
|
29
|
|
|
'min_start_time' => '08:00', |
|
30
|
|
|
'max_start_time' => '10:00', |
|
31
|
|
|
'min_end_time' => '16:00', |
|
32
|
|
|
'max_end_time' => false, |
|
33
|
|
|
]); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertEquals($options->getMinStartTime(), '08:00'); |
|
36
|
|
|
$this->assertEquals($options->getMaxStartTime(), '10:00'); |
|
37
|
|
|
$this->assertEquals($options->getMinEndTime(), '16:00'); |
|
38
|
|
|
$this->assertEquals($options->getMaxEndTime(), false); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @dataProvider invalidTimeProvider |
|
43
|
|
|
*/ |
|
44
|
|
|
public function testSetTimeThrowsExceptionIfNotValid24HourTime($field, $value = 'not-a-date') |
|
45
|
|
|
{ |
|
46
|
|
|
$this->setExpectedException( |
|
47
|
|
|
'\InvalidArgumentException', |
|
48
|
|
|
sprintf('%s should be a 24 hour time in the format HH:MM', $field) |
|
49
|
|
|
); |
|
50
|
|
|
$options = new BookingOptions([$field => $value]); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function invalidTimeProvider() |
|
54
|
|
|
{ |
|
55
|
|
|
return [ |
|
56
|
|
|
['min_start_time', 'not-a-date'], |
|
57
|
|
|
['max_start_time', 'not-a-date'], |
|
58
|
|
|
['min_end_time', 'not-a-date'], |
|
59
|
|
|
['max_end_time', 'not-a-date'], |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param string $value |
|
65
|
|
|
* @param bool $expected |
|
66
|
|
|
* @dataProvider timeProvider |
|
67
|
|
|
*/ |
|
68
|
|
|
public function testValidateTime($value, $expected) |
|
69
|
|
|
{ |
|
70
|
|
|
$options = new BookingOptions(); |
|
71
|
|
|
$this->assertEquals($options->validateTime($value), $expected); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function timeProvider() |
|
75
|
|
|
{ |
|
76
|
|
|
return [ |
|
77
|
|
|
["10:00" ,true], |
|
78
|
|
|
["25:00" ,false], |
|
79
|
|
|
["1000" ,false], |
|
80
|
|
|
["not-a-time" ,false], |
|
81
|
|
|
["24:00" ,false], |
|
82
|
|
|
["23:59" ,true], |
|
83
|
|
|
["00:00" ,true], |
|
84
|
|
|
]; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testSetInvalidPropertyThrowsException() |
|
88
|
|
|
{ |
|
89
|
|
|
$this->setExpectedException( |
|
90
|
|
|
'BadMethodCallException', |
|
91
|
|
|
'The option "not-a-valid-property" is not a valid property' |
|
92
|
|
|
); |
|
93
|
|
|
$options = new BookingOptions(['not-a-valid-property' => 'some-value']); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.