Completed
Push — master ( ecd5d7...f9662e )
by Julián
11:22
created

FixedTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 7
Bugs 1 Features 0
Metric Value
wmc 10
c 7
b 1
f 0
lcom 1
cbo 2
dl 0
loc 115
rs 10
1
<?php
2
3
/*
4
 * janitor (http://juliangut.com/janitor).
5
 * Effortless maintenance management.
6
 *
7
 * @license BSD-3-Clause
8
 * @link https://github.com/juliangut/janitor
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
namespace Janitor\Test\Watcher\Scheduled;
13
14
use Janitor\Watcher\Scheduled\Fixed;
15
16
/**
17
 * Class FixedTest.
18
 */
19
class FixedTest extends \PHPUnit_Framework_TestCase
20
{
21
    /**
22
     * @var Fixed
23
     */
24
    protected $watcher;
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function setUp()
30
    {
31
        $this->watcher = new Fixed('yesterday', 'tomorrow', 'UTC');
32
    }
33
34
    public function testDefaults()
35
    {
36
        self::assertTrue($this->watcher->isActive());
37
        self::assertFalse($this->watcher->isScheduled());
38
        self::assertEquals([], $this->watcher->getScheduledTimes());
39
    }
40
41
    public function testMutatorsAccessors()
42
    {
43
        $start = new \DateTime('now', new \DateTimeZone('UTC'));
44
        $end = clone $start;
45
        $end->add(new \DateInterval('PT1H'));
46
47
        $this->watcher->setStart($start);
48
        self::assertEquals($start, $this->watcher->getStart());
49
        $this->watcher->setEnd($end);
50
        self::assertEquals($end, $this->watcher->getEnd());
51
    }
52
53
    /**
54
     * @expectedException \InvalidArgumentException
55
     */
56
    public function testInvalidStartDate()
57
    {
58
        $this->watcher->setEnd('now');
59
60
        $start = new \DateTime('now', new \DateTimeZone('UTC'));
61
        $start->add(new \DateInterval('P10D'));
62
        $this->watcher->setStart($start);
63
    }
64
65
    /**
66
     * @expectedException \InvalidArgumentException
67
     */
68
    public function testInvalidStartString()
69
    {
70
        $this->watcher->setStart('wow');
71
    }
72
73
    /**
74
     * @expectedException \InvalidArgumentException
75
     */
76
    public function testInvalidEndDate()
77
    {
78
        $this->watcher->setStart('now');
79
80
        $end = new \DateTime('now', new \DateTimeZone('UTC'));
81
        $end->sub(new \DateInterval('P10D'));
82
        $this->watcher->setEnd($end);
83
    }
84
85
    /**
86
     * @expectedException \InvalidArgumentException
87
     */
88
    public function testInvalidEndString()
89
    {
90
        $this->watcher->setEnd('wow');
91
    }
92
93
    public function testScheduledTime()
94
    {
95
        self::assertEquals([], $this->watcher->getScheduledTimes());
96
97
        $start = new \DateTime('now', new \DateTimeZone('UTC'));
98
        $start->add(new \DateInterval('P1D'));
99
        $end = clone $start;
100
        $this->watcher->setEnd($end);
101
        $this->watcher->setStart($start);
102
        self::assertEquals([['start' => $start, 'end' => $end]], $this->watcher->getScheduledTimes());
103
104
        $start = new \DateTime('now', new \DateTimeZone('UTC'));
105
        $start->sub(new \DateInterval('P1D'));
106
        $end = clone $start;
107
        $this->watcher->setStart($start);
108
        $this->watcher->setEnd($end);
109
        self::assertEquals([], $this->watcher->getScheduledTimes());
110
    }
111
112
    public function testBeforeTime()
113
    {
114
        $start = new \DateTime('now', new \DateTimeZone('UTC'));
115
        $start->add(new \DateInterval('P1D'));
116
        $end = clone $start;
117
        $watcher = new Fixed($start, $end);
118
119
        self::assertFalse($watcher->isActive());
120
        self::assertTrue($watcher->isScheduled());
121
    }
122
123
    public function testAfterTime()
124
    {
125
        $start = new \DateTime('now', new \DateTimeZone('UTC'));
126
        $start->sub(new \DateInterval('P1D'));
127
        $end = clone $start;
128
        $watcher = new Fixed($start, $end);
129
130
        self::assertFalse($watcher->isActive());
131
        self::assertFalse($watcher->isScheduled());
132
    }
133
}
134