Completed
Push — master ( 926fb3...4b2baa )
by Hugues
02:39
created

CreateTest::testCreateWithValidTimezoneOffset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4286
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace HMLB\Date\Tests\Date;
4
5
/*
6
 * This file is part of the Date package.
7
 *
8
 * (c) Hugues Maignol <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
use HMLB\Date\Date;
15
use HMLB\Date\Tests\AbstractTestCase;
16
17
class CreateTest extends AbstractTestCase
18
{
19
    public function testCreateReturnsDatingInstance()
20
    {
21
        $d = Date::create();
22
        $this->assertTrue($d instanceof Date);
23
    }
24
25
    public function testCreateWithDefaults()
26
    {
27
        $d = Date::create();
28
        $this->assertSame($d->getTimestamp(), Date::now()->getTimestamp());
29
    }
30
31
    public function testCreateWithYear()
32
    {
33
        $d = Date::create(2012);
34
        $this->assertSame(2012, $d->getYear());
35
    }
36
37
    /**
38
     * @expectedException \InvalidArgumentException
39
     */
40
    public function testCreateWithInvalidYear()
41
    {
42
        Date::create(-3);
43
    }
44
45
    public function testCreateWithMonth()
46
    {
47
        $d = Date::create(null, 3);
48
        $this->assertSame(3, $d->getMonth());
49
    }
50
51
    /**
52
     * @expectedException \InvalidArgumentException
53
     */
54
    public function testCreateWithInvalidMonth()
55
    {
56
        Date::create(null, -5);
57
    }
58
59
    public function testCreateMonthWraps()
60
    {
61
        $d = Date::create(2011, 0, 1, 0, 0, 0);
62
        $this->assertDate($d, 2010, 12, 1, 0, 0, 0);
63
    }
64
65
    public function testCreateWithDay()
66
    {
67
        $d = Date::create(null, null, 21);
68
        $this->assertSame(21, $d->getDay());
69
    }
70
71
    /**
72
     * @expectedException \InvalidArgumentException
73
     */
74
    public function testCreateWithInvalidDay()
75
    {
76
        Date::create(null, null, -4);
77
    }
78
79
    public function testCreateDayWraps()
80
    {
81
        $d = Date::create(2011, 1, 40, 0, 0, 0);
82
        $this->assertDate($d, 2011, 2, 9, 0, 0, 0);
83
    }
84
85
    public function testCreateWithHourAndDefaultMinSecToZero()
86
    {
87
        $d = Date::create(null, null, null, 14);
88
        $this->assertSame(14, $d->getHour());
89
        $this->assertSame(0, $d->getMinute());
90
        $this->assertSame(0, $d->getSecond());
91
    }
92
93
    /**
94
     * @expectedException \InvalidArgumentException
95
     */
96
    public function testCreateWithInvalidHour()
97
    {
98
        Date::create(null, null, null, -1);
99
    }
100
101
    public function testCreateHourWraps()
102
    {
103
        $d = Date::create(2011, 1, 1, 24, 0, 0);
104
        $this->assertDate($d, 2011, 1, 2, 0, 0, 0);
105
    }
106
107
    public function testCreateWithMinute()
108
    {
109
        $d = Date::create(null, null, null, null, 58);
110
        $this->assertSame(58, $d->getMinute());
111
    }
112
113
    /**
114
     * @expectedException \InvalidArgumentException
115
     */
116
    public function testCreateWithInvalidMinute()
117
    {
118
        Date::create(2011, 1, 1, 0, -2, 0);
119
    }
120
121
    public function testCreateMinuteWraps()
122
    {
123
        $d = Date::create(2011, 1, 1, 0, 62, 0);
124
        $this->assertDate($d, 2011, 1, 1, 1, 2, 0);
125
    }
126
127
    public function testCreateWithSecond()
128
    {
129
        $d = Date::create(null, null, null, null, null, 59);
130
        $this->assertSame(59, $d->getSecond());
131
    }
132
133
    /**
134
     * @expectedException \InvalidArgumentException
135
     */
136
    public function testCreateWithInvalidSecond()
137
    {
138
        Date::create(null, null, null, null, null, -2);
139
    }
140
141
    public function testCreateSecondsWrap()
142
    {
143
        $d = Date::create(2012, 1, 1, 0, 0, 61);
144
        $this->assertDate($d, 2012, 1, 1, 0, 1, 1);
145
    }
146
147
    public function testCreateWithDateTimeZone()
148
    {
149
        $d = Date::create(2012, 1, 1, 0, 0, 0, new \DateTimeZone('Europe/London'));
150
        $this->assertDate($d, 2012, 1, 1, 0, 0, 0);
151
        $this->assertSame('Europe/London', $d->getTimezoneName());
152
    }
153
154
    public function testCreateWithTimeZoneString()
155
    {
156
        $d = Date::create(2012, 1, 1, 0, 0, 0, 'Europe/London');
157
        $this->assertDate($d, 2012, 1, 1, 0, 0, 0);
158
        $this->assertSame('Europe/London', $d->getTimezoneName());
159
    }
160
161
    /**
162
     * @expectedException \InvalidArgumentException
163
     */
164
    public function testCreateWithInvalidTimezoneOffset()
165
    {
166
        Date::createFromDate(2000, 1, 1, 'Mars/Somewhere');
167
    }
168
}
169