Code Duplication    Length = 149-149 lines in 2 locations

tests/DateTime/Utilities/DateTimeUtilTest.php 1 location

@@ 16-164 (lines=149) @@
13
 * @coversDefaultClass \SubjectivePHP\DateTime\Utilities\DateTimeUtil
14
 * @covers ::<private>
15
 */
16
final class DateTimeTest extends TestCase
17
{
18
    /**
19
     * Verify basic behavior of isWeekDay().
20
     *
21
     * @test
22
     * @covers ::isWeekDay
23
     *
24
     * @return void
25
     */
26
    public function isWeekDay()
27
    {
28
        $this->assertTrue(DateTimeUtil::isWeekDay(new DateTime('2014-07-02')));
29
        $this->assertFalse(DateTimeUtil::isWeekDay(new DateTime('2014-07-05')));
30
    }
31
32
    /**
33
     * Verify basic behavior of isWeekendDay().
34
     *
35
     * @test
36
     * @covers ::isWeekendDay
37
     *
38
     * @return void
39
     */
40
    public function isWeekendDay()
41
    {
42
        $this->assertFalse(DateTimeUtil::isWeekendDay(new DateTime('2014-07-02')));
43
        $this->assertTrue(DateTimeUtil::isWeekendDay(new DateTime('2014-07-05')));
44
    }
45
46
    /**
47
     * Verify basic behavior of isSameDay().
48
     *
49
     * @test
50
     * @covers ::isSameDay
51
     *
52
     * @return void
53
     */
54
    public function isSameDay()
55
    {
56
        $thisDate = new DateTime('2015-01-01 12:00:00', new DateTimeZone('Pacific/Fiji'));
57
        $thatDate = new DateTime('2014-12-31 12:00:00', new DateTimeZone('America/New_York'));
58
59
        $this->assertNotEquals($thisDate->format('Y-m-d'), $thatDate->format('Y-m-d'));
60
        $this->assertTrue(DateTimeUtil::isSameDay($thisDate, $thatDate));
61
    }
62
63
    /**
64
     * Verify basic behavior of isDaylightSavings().
65
     *
66
     * @test
67
     * @covers ::isDaylightSavings
68
     *
69
     * @return void
70
     */
71
    public function isDaylightSavings()
72
    {
73
        $dateTime = new DateTime('now', new DateTimeZone('Pacific/Honolulu'));
74
        $this->assertFalse(DateTimeUtil::isDaylightSavings($dateTime));
75
    }
76
77
    /**
78
     * Verify basic behavior of isInRange().
79
     *
80
     * @test
81
     * @covers ::isInRange
82
     *
83
     * @return void
84
     */
85
    public function isInRange()
86
    {
87
        $currentDateTime = new DateTime('now');
88
        $startDateTime = new DateTime('last year');
89
        $endDateTime = new DateTime('next year');
90
        $this->assertTrue(DateTimeUtil::isInRange($currentDateTime, $startDateTime, $endDateTime));
91
    }
92
93
    /**
94
     * Verify error behavior of isInRange().
95
     *
96
     * @test
97
     * @covers ::isInRange
98
     * @expectedException \DomainException
99
     *
100
     * @return void
101
     */
102
    public function isInRangeWithInvalidRange()
103
    {
104
        $currentDateTime = new DateTime('now');
105
        $startDateTime = new DateTime('next year');
106
        $endDateTime = new DateTime('last year');
107
        DateTimeUtil::isInRange($currentDateTime, $startDateTime, $endDateTime);
108
    }
109
110
    /**
111
     * Verify basic behavior of asAgoString().
112
     *
113
     * @test
114
     * @covers ::asAgoString
115
     * @dataProvider provideAgoStringData
116
     *
117
     * @param string $dateTimeString    The date/time string.
118
     * @param string $expectedAgoString The expected ago string.
119
     *
120
     * @return void
121
     */
122
    public function asAgoString(string $dateTimeString, string $expectedAgoString)
123
    {
124
        $this->assertSame($expectedAgoString, DateTimeUtil::asAgoString(new DateTime($dateTimeString)));
125
    }
126
127
    /**
128
     * Returns data for the asAgoString test.
129
     *
130
     * @return array
131
     */
132
    public function provideAgoStringData()
133
    {
134
        return [
135
            [ '-1 minute', 'just now'],
136
            [ '-2 minutes', '2 minutes ago'],
137
            [ '-30 minutes', 'about an hour ago'],
138
            [ '-10 hours', 'about 10 hours ago'],
139
            [ '-25 hours', 'yesterday'],
140
            [ '-3 days', 'about 3 days ago'],
141
            [ '-8 days', 'last week'],
142
            [ '-3 weeks', 'about 3 weeks ago'],
143
            [ '-1 month', 'last month' ],
144
            [ '-2 months', 'about 2 months ago' ],
145
            [ '-12 months', 'last year' ],
146
            [ '-1 year', 'last year' ],
147
            [ '-4 years', 'about 4 years ago' ],
148
        ];
149
    }
150
151
    /**
152
     * Verify error behavior of asAgoString().
153
     *
154
     * @test
155
     * @covers ::asAgoString
156
     * @expectedException \DomainException
157
     *
158
     * @return void
159
     */
160
    public function asAgoStringWithFutureDate()
161
    {
162
        DateTimeUtil::asAgoString(new DateTime('tomorrow'));
163
    }
164
}
165

tests/Util/DateTimeTest.php 1 location

@@ 13-161 (lines=149) @@
10
 * @coversDefaultClass \SubjectivePHP\Util\DateTime
11
 * @covers ::<private>
12
 */
13
final class DateTimeTest extends TestCase
14
{
15
    /**
16
     * Verify basic behavior of isWeekDay().
17
     *
18
     * @test
19
     * @covers ::isWeekDay
20
     *
21
     * @return void
22
     */
23
    public function isWeekDay()
24
    {
25
        $this->assertTrue(DateTime::isWeekDay(new \DateTime('2014-07-02')));
26
        $this->assertFalse(DateTime::isWeekDay(new \DateTime('2014-07-05')));
27
    }
28
29
    /**
30
     * Verify basic behavior of isWeekendDay().
31
     *
32
     * @test
33
     * @covers ::isWeekendDay
34
     *
35
     * @return void
36
     */
37
    public function isWeekendDay()
38
    {
39
        $this->assertFalse(DateTime::isWeekendDay(new \DateTime('2014-07-02')));
40
        $this->assertTrue(DateTime::isWeekendDay(new \DateTime('2014-07-05')));
41
    }
42
43
    /**
44
     * Verify basic behavior of isSameDay().
45
     *
46
     * @test
47
     * @covers ::isSameDay
48
     *
49
     * @return void
50
     */
51
    public function isSameDay()
52
    {
53
        $thisDate = new \DateTime('2015-01-01 12:00:00', new \DateTimeZone('Pacific/Fiji'));
54
        $thatDate = new \DateTime('2014-12-31 12:00:00', new \DateTimeZone('America/New_York'));
55
56
        $this->assertNotEquals($thisDate->format('Y-m-d'), $thatDate->format('Y-m-d'));
57
        $this->assertTrue(DateTime::isSameDay($thisDate, $thatDate));
58
    }
59
60
    /**
61
     * Verify basic behavior of isDaylightSavings().
62
     *
63
     * @test
64
     * @covers ::isDaylightSavings
65
     *
66
     * @return void
67
     */
68
    public function isDaylightSavings()
69
    {
70
        $dateTime = new \DateTime('now', new \DateTimeZone('Pacific/Honolulu'));
71
        $this->assertFalse(DateTime::isDaylightSavings($dateTime));
72
    }
73
74
    /**
75
     * Verify basic behavior of isInRange().
76
     *
77
     * @test
78
     * @covers ::isInRange
79
     *
80
     * @return void
81
     */
82
    public function isInRange()
83
    {
84
        $currentDateTime = new \DateTime('now');
85
        $startDateTime = new \DateTime('last year');
86
        $endDateTime = new \DateTime('next year');
87
        $this->assertTrue(DateTime::isInRange($currentDateTime, $startDateTime, $endDateTime));
88
    }
89
90
    /**
91
     * Verify error behavior of isInRange().
92
     *
93
     * @test
94
     * @covers ::isInRange
95
     * @expectedException \DomainException
96
     *
97
     * @return void
98
     */
99
    public function isInRangeWithInvalidRange()
100
    {
101
        $currentDateTime = new \DateTime('now');
102
        $startDateTime = new \DateTime('next year');
103
        $endDateTime = new \DateTime('last year');
104
        DateTime::isInRange($currentDateTime, $startDateTime, $endDateTime);
105
    }
106
107
    /**
108
     * Verify basic behavior of asAgoString().
109
     *
110
     * @test
111
     * @covers ::asAgoString
112
     * @dataProvider provideAgoStringData
113
     *
114
     * @param string $dateTimeString    The date/time string.
115
     * @param string $expectedAgoString The expected ago string.
116
     *
117
     * @return void
118
     */
119
    public function asAgoString($dateTimeString, $expectedAgoString)
120
    {
121
        $this->assertSame($expectedAgoString, DateTime::asAgoString(new \DateTime($dateTimeString)));
122
    }
123
124
    /**
125
     * Returns data for the asAgoString test.
126
     *
127
     * @return array
128
     */
129
    public function provideAgoStringData()
130
    {
131
        return [
132
            [ '-1 minute', 'just now'],
133
            [ '-2 minutes', '2 minutes ago'],
134
            [ '-30 minutes', 'about an hour ago'],
135
            [ '-10 hours', 'about 10 hours ago'],
136
            [ '-25 hours', 'yesterday'],
137
            [ '-3 days', 'about 3 days ago'],
138
            [ '-8 days', 'last week'],
139
            [ '-3 weeks', 'about 3 weeks ago'],
140
            [ '-1 month', 'last month' ],
141
            [ '-2 months', 'about 2 months ago' ],
142
            [ '-12 months', 'last year' ],
143
            [ '-1 year', 'last year' ],
144
            [ '-4 years', 'about 4 years ago' ],
145
        ];
146
    }
147
148
    /**
149
     * Verify error behavior of asAgoString().
150
     *
151
     * @test
152
     * @covers ::asAgoString
153
     * @expectedException \DomainException
154
     *
155
     * @return void
156
     */
157
    public function asAgoStringWithFutureDate()
158
    {
159
        DateTime::asAgoString(new \DateTime('tomorrow'));
160
    }
161
}
162