Skip to content

Commit 1b63ba8

Browse files
committed
Formatter config tests
1 parent 2a088c7 commit 1b63ba8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/ClientTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,34 @@ public function testRsaSha256Signer()
148148
);
149149
}
150150

151+
public function testDefaultTimestampFormatter()
152+
{
153+
$time = Carbon::now()->addMinutes(10);
154+
$token = JWT::expiresAt($time)->getToken();
155+
156+
$parts = array_map('base64_decode', explode('.', $token->toString()));
157+
158+
$this->assertEquals(
159+
$time->format('U.u'),
160+
json_decode($parts[1])->exp
161+
);
162+
}
163+
164+
public function testUnixTimestampFormatter()
165+
{
166+
config(['jwt.chained_formatter' => ChainedFormatter::withUnixTimestampDates()]);
167+
168+
$time = Carbon::now()->addMinutes(10);
169+
$token = JWT::expiresAt($time)->getToken();
170+
171+
$parts = array_map('base64_decode', explode('.', $token->toString()));
172+
173+
$this->assertEquals(
174+
$time->format('U'),
175+
json_decode($parts[1])->exp
176+
);
177+
}
178+
151179
public function testQuickGet()
152180
{
153181
$jwt = JWT::get('test-id', ['foo' => 'bar'], 1800);
@@ -168,3 +196,4 @@ public function testQuickGet()
168196
);
169197
}
170198
}
199+

0 commit comments

Comments
 (0)