ConstructTest::testParseWithFancyString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

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 3
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 ConstructTest extends AbstractTestCase
18
{
19 View Code Duplication
    public function testCreatesAnInstanceDefaultToNow()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    {
21
        $c = new Date();
22
        $now = Date::now();
23
        $this->assertInstanceOfDate($c);
24
        $this->assertSame($now->getTimezoneName(), $c->getTimezoneName());
25
        $this->assertDate(
26
            $c,
27
            $now->getYear(),
28
            $now->getMonth(),
29
            $now->getDay(),
30
            $now->getHour(),
31
            $now->getMinute(),
32
            $now->getSecond()
33
        );
34
    }
35
36 View Code Duplication
    public function testParseCreatesAnInstanceDefaultToNow()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        $c = Date::parse();
39
        $now = Date::now();
40
        $this->assertInstanceOfDate($c);
41
        $this->assertSame($now->getTimezoneName(), $c->getTimezoneName());
42
        $this->assertDate(
43
            $c,
44
            $now->getYear(),
45
            $now->getMonth(),
46
            $now->getDay(),
47
            $now->getHour(),
48
            $now->getMinute(),
49
            $now->getSecond()
50
        );
51
    }
52
53
    public function testWithFancyString()
54
    {
55
        $c = new Date('first day of January 2008');
56
        $this->assertDate($c, 2008, 1, 1, 0, 0, 0);
57
    }
58
59
    public function testParseWithFancyString()
60
    {
61
        $c = Date::parse('first day of January 2008');
62
        $this->assertDate($c, 2008, 1, 1, 0, 0, 0);
63
    }
64
65
    public function testDefaultTimezone()
66
    {
67
        $c = new Date('now');
68
        $this->assertSame('America/Toronto', $c->getTimezoneName());
69
    }
70
71
    public function testParseWithDefaultTimezone()
72
    {
73
        $c = Date::parse('now');
74
        $this->assertSame('America/Toronto', $c->getTimezoneName());
75
    }
76
77 View Code Duplication
    public function testSettingTimezone()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $timezone = 'Europe/London';
80
        $dtz = new \DateTimeZone($timezone);
81
        $dt = new \DateTime('now', $dtz);
82
        $dayLightSavingTimeOffset = (int) $dt->format('I');
83
84
        $c = new Date('now', $dtz);
85
        $this->assertSame($timezone, $c->getTimezoneName());
86
        $this->assertSame($dayLightSavingTimeOffset, $c->getOffsetHours());
87
    }
88
89 View Code Duplication
    public function testParseSettingTimezone()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
    {
91
        $timezone = 'Europe/London';
92
        $dtz = new \DateTimeZone($timezone);
93
        $dt = new \DateTime('now', $dtz);
94
        $dayLightSavingTimeOffset = (int) $dt->format('I');
95
96
        $c = Date::parse('now', $dtz);
97
        $this->assertSame($timezone, $c->getTimezoneName());
98
        $this->assertSame($dayLightSavingTimeOffset, $c->getOffsetHours());
99
    }
100
101 View Code Duplication
    public function testSettingTimezoneWithString()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
    {
103
        $timezone = 'Asia/Tokyo';
104
        $dtz = new \DateTimeZone($timezone);
105
        $dt = new \DateTime('now', $dtz);
106
        $dayLightSavingTimeOffset = (int) $dt->format('I');
107
108
        $c = new Date('now', $timezone);
109
        $this->assertSame($timezone, $c->getTimezoneName());
110
        $this->assertSame(9 + $dayLightSavingTimeOffset, $c->getOffsetHours());
111
    }
112
113 View Code Duplication
    public function testParseSettingTimezoneWithString()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
    {
115
        $timezone = 'Asia/Tokyo';
116
        $dtz = new \DateTimeZone($timezone);
117
        $dt = new \DateTime('now', $dtz);
118
        $dayLightSavingTimeOffset = (int) $dt->format('I');
119
120
        $c = Date::parse('now', $timezone);
121
        $this->assertSame($timezone, $c->getTimezoneName());
122
        $this->assertSame(9 + $dayLightSavingTimeOffset, $c->getOffsetHours());
123
    }
124
}
125