testNowWithTimezone()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 4
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 NowAndOtherStaticHelpersTest extends AbstractTestCase
18
{
19
    public function testNow()
20
    {
21
        $dt = Date::now();
22
        $this->assertSame(time(), $dt->getTimestamp());
23
    }
24
25
    public function testNowWithTimezone()
26
    {
27
        $dt = Date::now('Europe/London');
28
        $this->assertSame(time(), $dt->getTimestamp());
29
        $this->assertSame('Europe/London', $dt->getTimezoneName());
30
    }
31
32
    public function testToday()
33
    {
34
        $dt = Date::today();
35
        $this->assertSame(date('Y-m-d 00:00:00'), $dt->toDateTimeString());
36
    }
37
38
    public function testTodayWithTimezone()
39
    {
40
        $dt = Date::today('Europe/London');
41
        $dt2 = new \DateTime('now', new \DateTimeZone('Europe/London'));
42
        $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString());
43
    }
44
45
    public function testTomorrow()
46
    {
47
        $dt = Date::tomorrow();
48
        $dt2 = new \DateTime('tomorrow');
49
        $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString());
50
    }
51
52
    public function testTomorrowWithTimezone()
53
    {
54
        $dt = Date::tomorrow('Europe/London');
55
        $dt2 = new \DateTime('tomorrow', new \DateTimeZone('Europe/London'));
56
        $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString());
57
    }
58
59
    public function testYesterday()
60
    {
61
        $dt = Date::yesterday();
62
        $dt2 = new \DateTime('yesterday');
63
        $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString());
64
    }
65
66
    public function testYesterdayWithTimezone()
67
    {
68
        $dt = Date::yesterday('Europe/London');
69
        $dt2 = new \DateTime('yesterday', new \DateTimeZone('Europe/London'));
70
        $this->assertSame($dt2->format('Y-m-d 00:00:00'), $dt->toDateTimeString());
71
    }
72
73
    public function testMinValue()
74
    {
75
        $this->assertLessThanOrEqual(-2147483647, Date::minValue()->getTimestamp());
76
    }
77
78
    public function testMaxValue()
79
    {
80
        $this->assertGreaterThanOrEqual(2147483647, Date::maxValue()->getTimestamp());
81
    }
82
}
83