Skip to content

Commit 10990e0

Browse files
committed
test: refactor time depnedent tests
1 parent 6c9cb8a commit 10990e0

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

tests/Controllers/LoginTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public function testLoginBadEmail(): void
6464

6565
public function testLoginActionEmailSuccess(): void
6666
{
67+
Time::setTestNow('March 10, 2017', 'America/Chicago');
68+
6769
$this->user->createEmailIdentity([
6870
'email' => 'foo@example.com',
6971
'password' => 'secret123',
@@ -87,7 +89,7 @@ public function testLoginActionEmailSuccess(): void
8789
]);
8890
// Last Used date should have been set
8991
$identity = $this->user->getEmailIdentity();
90-
$this->assertCloseEnough($identity->last_used_at->getTimestamp(), Time::now()->getTimestamp());
92+
$this->assertSame(Time::now()->getTimestamp(), $identity->last_used_at->getTimestamp());
9193

9294
// Session should have `logged_in` value with user's id
9395
$this->assertSame($this->user->id, session('user')['id']);
@@ -111,6 +113,8 @@ public function testAfterLoggedInNotDesplayLoginPage(): void
111113

112114
public function testLoginActionUsernameSuccess(): void
113115
{
116+
Time::setTestNow('March 10, 2017', 'America/Chicago');
117+
114118
// Change the validation rules
115119
$config = new class () extends Validation {
116120
public $login = [
@@ -143,7 +147,7 @@ public function testLoginActionUsernameSuccess(): void
143147
]);
144148
// Last Used date should have been set
145149
$identity = $this->user->getEmailIdentity();
146-
$this->assertCloseEnough($identity->last_used_at->getTimestamp(), Time::now()->getTimestamp());
150+
$this->assertSame(Time::now()->getTimestamp(), $identity->last_used_at->getTimestamp());
147151

148152
// Session should have `logged_in` value with user's id
149153
$this->assertSame($this->user->id, session('user')['id']);

0 commit comments

Comments
 (0)