-
Notifications
You must be signed in to change notification settings - Fork 11.3k
/
Copy pathFoundationInteractsWithTimeTest.php
78 lines (61 loc) · 1.98 KB
/
FoundationInteractsWithTimeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Illuminate\Tests\Foundation;
use Illuminate\Foundation\Testing\Concerns\InteractsWithTime;
use Illuminate\Support\Carbon;
use PHPUnit\Framework\TestCase;
class FoundationInteractsWithTimeTest extends TestCase
{
use InteractsWithTime;
public function tearDown(): void
{
parent::tearDown();
Carbon::setTestNow();
}
public function testFreezeTimeReturnsFrozenTime()
{
$actual = $this->freezeTime();
$this->assertTrue(Carbon::hasTestNow());
$this->assertInstanceOf(\DateTimeInterface::class, $actual);
$this->assertTrue(Carbon::getTestNow()->eq($actual));
}
public function testFreezeTimeReturnsCallbackResult()
{
$actual = $this->freezeTime(function () {
return 12345;
});
$this->assertSame(12345, $actual);
$this->assertFalse(Carbon::hasTestNow());
}
public function testFreezeTimeReturnsCallbackResultEvenWhenNull()
{
$actual = $this->freezeTime(function () {
return null;
});
$this->assertNull($actual);
$this->assertFalse(Carbon::hasTestNow());
}
public function testFreezeSecondReturnsFrozenTime()
{
$actual = $this->freezeSecond();
$this->assertTrue(Carbon::hasTestNow());
$this->assertInstanceOf(\DateTimeInterface::class, $actual);
$this->assertTrue(Carbon::getTestNow()->eq($actual));
$this->assertSame(0, $actual->milliseconds);
}
public function testFreezeSecondReturnsCallbackResult()
{
$actual = $this->freezeSecond(function () {
return 12345;
});
$this->assertSame(12345, $actual);
$this->assertFalse(Carbon::hasTestNow());
}
public function testFreezeSecondReturnsCallbackResultEvenWhenNull()
{
$actual = $this->freezeSecond(function () {
return null;
});
$this->assertNull($actual);
$this->assertFalse(Carbon::hasTestNow());
}
}