|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ArpTest\DateTime\Psr; |
|
6
|
|
|
|
|
7
|
|
|
use Arp\DateTime\DateTimeImmutableFactory; |
|
8
|
|
|
use Arp\DateTime\Psr\Clock; |
|
9
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
use Psr\Clock\ClockInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @covers \Arp\DateTime\Psr\Clock |
|
15
|
|
|
*/ |
|
16
|
|
|
final class ClockTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var DateTimeImmutableFactory&MockObject |
|
20
|
|
|
*/ |
|
21
|
|
|
private DateTimeImmutableFactory $dateTimeImmutableFactory; |
|
22
|
|
|
|
|
23
|
|
|
public function setUp(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$this->dateTimeImmutableFactory = $this->createMock(DateTimeImmutableFactory::class); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testImplementsClockInterface(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$this->assertInstanceOf(ClockInterface::class, new Clock($this->dateTimeImmutableFactory)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @dataProvider getNowData |
|
35
|
|
|
* |
|
36
|
|
|
* @throws \Exception |
|
37
|
|
|
*/ |
|
38
|
|
|
public function testNow(string|\DateTimeZone|null $timeZone): void |
|
39
|
|
|
{ |
|
40
|
|
|
$clock = new Clock($this->dateTimeImmutableFactory, $timeZone); |
|
41
|
|
|
|
|
42
|
|
|
$dateTimeImmutable = new \DateTimeImmutable( |
|
43
|
|
|
'now', |
|
44
|
|
|
is_string($timeZone) ? new \DateTimeZone($timeZone) : $timeZone |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
$this->dateTimeImmutableFactory->expects($this->once()) |
|
|
|
|
|
|
48
|
|
|
->method('createDateTime') |
|
49
|
|
|
->with('now', $timeZone) |
|
50
|
|
|
->willReturn($dateTimeImmutable); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertSame($dateTimeImmutable, $clock->now()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return array<int, array<mixed>> |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getNowData(): array |
|
59
|
|
|
{ |
|
60
|
|
|
return [ |
|
61
|
|
|
[null], |
|
62
|
|
|
['UTC'], |
|
63
|
|
|
['Europe/London'], |
|
64
|
|
|
['Europe/Rome'], |
|
65
|
|
|
['America/New_York'], |
|
66
|
|
|
['America/Los_Angeles'], |
|
67
|
|
|
[new \DateTimeZone('UTC')], |
|
68
|
|
|
[new \DateTimeZone('Europe/London')], |
|
69
|
|
|
[new \DateTimeZone('America/Los_Angeles')], |
|
70
|
|
|
[new \DateTimeZone('Europe/Paris')], |
|
71
|
|
|
]; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.