Completed
Push — master ( 038cb8...f2d1b9 )
by FX
13:23
created

PeriodTest::testConstructorWrongStartEndDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 1
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace AppBundle\Tests\Util;
4
5
use AppBundle\Util\Period;
6
use DateTime;
7
use LogicException;
8
use PHPUnit\Framework\TestCase;
9
10
class PeriodTest extends TestCase
11
{
12
    public function testConstructor()
13
    {
14
        $start = '2016-08-01 00:00:01';
15
        $end = '2016-08-02 00:00:01';
16
        $period = new Period(new DateTime($start), new DateTime($end));
17
18
        $this->assertEquals($start, $period->getStartDate()->format('Y-m-d H:i:s'));
19
        $this->assertEquals($end, $period->getEndDate()->format('Y-m-d H:i:s'));
20
    }
21
22
    public function testConstructorEqualDate()
23
    {
24
        $start = '2016-08-01 00:00:01';
25
        $end = '2016-08-01 00:00:01';
26
        $period = new Period(new DateTime($start), new DateTime($end));
27
28
        $this->assertEquals($start, $period->getStartDate()->format('Y-m-d H:i:s'));
29
        $this->assertEquals($end, $period->getEndDate()->format('Y-m-d H:i:s'));
30
    }
31
32
    public function testConstructorWrongStartEndDate()
33
    {
34
        $start = '2016-08-02 00:00:01';
35
        $end = '2016-08-01 00:00:01';
36
37
        $this->expectException(LogicException::class);
38
        $period = new Period(new DateTime($start), new DateTime($end));
0 ignored issues
show
Unused Code introduced by
$period 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...
39
    }
40
41
    public function testGetters()
42
    {
43
        $start = '2016-08-01 00:00:01';
44
        $end = '2016-08-02 00:00:01';
45
        $period = new Period(new DateTime($start), new DateTime($end));
46
47
        $this->assertEquals($start, $period->getStartDate()->format('Y-m-d H:i:s'));
48
        $this->assertEquals($end, $period->getEndDate()->format('Y-m-d H:i:s'));
49
    }
50
51
    public function testSetters()
52
    {
53
        $start = '2016-08-01 00:00:01';
54
        $end = '2016-08-02 00:00:01';
55
        $period = new Period(new DateTime($start), new DateTime($end));
56
57
        $startSet = '2016-08-01 01:00:01';
58
        $endSet = '2016-08-04 00:00:01';
59
        $period->setStartDate(new DateTime($startSet));
60
        $period->setEndDate(new DateTime($endSet));
61
62
        $this->assertEquals($startSet, $period->getStartDate()->format('Y-m-d H:i:s'));
63
        $this->assertEquals($endSet, $period->getEndDate()->format('Y-m-d H:i:s'));
64
    }
65
66
    public function testWrongSetStartDate()
67
    {
68
        $start = '2016-08-01 00:00:01';
69
        $end = '2016-08-02 00:00:01';
70
        $period = new Period(new DateTime($start), new DateTime($end));
71
72
        $startSet = '2016-08-03 01:00:01';
73
        $this->expectException(LogicException::class);
74
        $period->setStartDate(new DateTime($startSet));
75
    }
76
77
    public function testWrongSetEndDate()
78
    {
79
        $start = '2016-08-01 00:00:01';
80
        $end = '2016-08-02 00:00:01';
81
        $period = new Period(new DateTime($start), new DateTime($end));
82
83
        $endSet = '2016-07-31 00:00:01';
84
        $this->expectException(LogicException::class);
85
        $period->setEndDate(new DateTime($endSet));
86
    }
87
}
88