BookingOptionsTest::testSetValues()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
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]);
0 ignored issues
show
Unused Code introduced by
$options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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']);
0 ignored issues
show
Unused Code introduced by
$options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
94
    }
95
}
96