1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the daikon-cqrs/value-object project. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Daikon\Tests\ValueObject; |
10
|
|
|
|
11
|
|
|
use Daikon\ValueObject\Timestamp; |
|
|
|
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
final class TimestampTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
private const FIXED_TIMESTAMP_EUR = '2016-07-04T19:27:07.123000+02:00'; |
17
|
|
|
|
18
|
|
|
private const FIXED_TIMESTAMP_UTC = '2016-07-04T17:27:07.123000+00:00'; |
19
|
|
|
|
20
|
|
|
private const FIXED_EARLY_TIMESTAMP_UTC = '2016-07-03T17:17:07.122999+00:00'; |
21
|
|
|
|
22
|
|
|
private const FIXED_LATE_TIMESTAMP_UTC = '2016-07-05T17:27:07.123000+00:00'; |
23
|
|
|
|
24
|
|
|
private Timestamp $timestamp; |
25
|
|
|
|
26
|
1 |
|
public function testToNative(): void |
27
|
|
|
{ |
28
|
1 |
|
$this->assertEquals(self::FIXED_TIMESTAMP_UTC, $this->timestamp->toNative()); |
29
|
1 |
|
$this->assertEquals(null, Timestamp::fromNative(null)->toNative()); |
30
|
1 |
|
} |
31
|
|
|
|
32
|
1 |
|
public function testEquals(): void |
33
|
|
|
{ |
34
|
1 |
|
$equalTs = Timestamp::fromString('2016-07-04T17:27:07.123000', 'Y-m-d\\TH:i:s.u'); |
35
|
1 |
|
$this->assertTrue($this->timestamp->equals($equalTs)); |
36
|
1 |
|
$differentTs = Timestamp::fromString('+1 year', 'Y-m-d\\TH:i:s.u'); |
37
|
1 |
|
$this->assertFalse($this->timestamp->equals($differentTs)); |
38
|
1 |
|
} |
39
|
|
|
|
40
|
1 |
|
public function testToString(): void |
41
|
|
|
{ |
42
|
1 |
|
$this->assertEquals(self::FIXED_TIMESTAMP_UTC, (string)$this->timestamp); |
43
|
1 |
|
} |
44
|
|
|
|
45
|
1 |
|
public function testToTime(): void |
46
|
|
|
{ |
47
|
1 |
|
$this->assertEquals('1578687888', Timestamp::fromNative('1578687888')->toTime()); |
48
|
1 |
|
$this->assertSame(1578687889, Timestamp::fromNative(1578687889)->toTime()); |
49
|
1 |
|
} |
50
|
|
|
|
51
|
1 |
|
public function testIsEmpty(): void |
52
|
|
|
{ |
53
|
1 |
|
$this->assertTrue(Timestamp::fromNative(null)->isEmpty()); |
54
|
1 |
|
$this->assertTrue(Timestamp::makeEmpty()->isEmpty()); |
55
|
1 |
|
} |
56
|
|
|
|
57
|
1 |
|
public function testIsBefore(): void |
58
|
|
|
{ |
59
|
1 |
|
$nullTs = Timestamp::fromNative(null); |
60
|
1 |
|
$earlyTs = Timestamp::fromString(self::FIXED_TIMESTAMP_UTC); |
61
|
1 |
|
$lateTs = Timestamp::fromString(self::FIXED_LATE_TIMESTAMP_UTC); |
62
|
1 |
|
$this->assertTrue($nullTs->isBefore($earlyTs)); |
63
|
1 |
|
$this->assertFalse($earlyTs->isBefore($nullTs)); |
64
|
1 |
|
$this->assertTrue($earlyTs->isBefore($lateTs)); |
65
|
1 |
|
$this->assertFalse($lateTs->isBefore($earlyTs)); |
66
|
1 |
|
} |
67
|
|
|
|
68
|
1 |
|
public function testIsAfter(): void |
69
|
|
|
{ |
70
|
1 |
|
$nullTs = Timestamp::fromNative(null); |
71
|
1 |
|
$earlyTs = Timestamp::fromString(self::FIXED_TIMESTAMP_UTC); |
72
|
1 |
|
$lateTs = Timestamp::fromString(self::FIXED_LATE_TIMESTAMP_UTC); |
73
|
1 |
|
$this->assertFalse($nullTs->isAfter($earlyTs)); |
74
|
1 |
|
$this->assertTrue($earlyTs->isAfter($nullTs)); |
75
|
1 |
|
$this->assertFalse($earlyTs->isAfter($lateTs)); |
76
|
1 |
|
$this->assertTrue($lateTs->isAfter($earlyTs)); |
77
|
1 |
|
} |
78
|
|
|
|
79
|
1 |
|
public function testModify(): void |
80
|
|
|
{ |
81
|
1 |
|
$addTs1 = $this->timestamp->modify('+1 day'); |
82
|
1 |
|
$addTs2 = $this->timestamp->modify('+24 hours'); |
83
|
1 |
|
$this->assertEquals(self::FIXED_LATE_TIMESTAMP_UTC, (string)$addTs1); |
84
|
1 |
|
$this->assertEquals(self::FIXED_LATE_TIMESTAMP_UTC, (string)$addTs2); |
85
|
|
|
|
86
|
1 |
|
$subTs1 = $this->timestamp->modify('-1 day - 10 minutes - 1 microsecond'); |
87
|
1 |
|
$subTs2 = $this->timestamp->modify('-24 hours - 600 seconds - 1 microsecond'); |
88
|
1 |
|
$this->assertEquals(self::FIXED_EARLY_TIMESTAMP_UTC, (string)$subTs1); |
89
|
1 |
|
$this->assertEquals(self::FIXED_EARLY_TIMESTAMP_UTC, (string)$subTs2); |
90
|
|
|
|
91
|
1 |
|
$this->expectWarning(); |
92
|
1 |
|
$this->timestamp->modify('bogus'); |
93
|
|
|
} |
94
|
|
|
|
95
|
8 |
|
protected function setUp(): void |
96
|
|
|
{ |
97
|
8 |
|
$this->timestamp = Timestamp::fromNative(self::FIXED_TIMESTAMP_EUR); |
98
|
8 |
|
} |
99
|
|
|
} |
100
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths