44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
// tests/Auth/AuthServiceTest.php
|
|
namespace Tests\Auth;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use App\Auth\AuthService;
|
|
|
|
class AuthServiceTest extends TestCase
|
|
{
|
|
private $authService;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->authService = new AuthService();
|
|
}
|
|
|
|
public function testCreateJWT(): void
|
|
{
|
|
$payload = ['user_id' => 'test_user', 'email' => 'test@example.com'];
|
|
$token = $this->authService->createJWT($payload);
|
|
|
|
$this->assertIsString($token);
|
|
$this->assertNotEmpty($token);
|
|
}
|
|
|
|
public function testVerifyJWT(): void
|
|
{
|
|
$payload = ['user_id' => 'test_user', 'email' => 'test@example.com'];
|
|
$token = $this->authService->createJWT($payload);
|
|
|
|
$decoded = $this->authService->verifyJWT($token);
|
|
|
|
$this->assertIsArray($decoded);
|
|
$this->assertEquals('test_user', $decoded['user_id']);
|
|
$this->assertEquals('test@example.com', $decoded['email']);
|
|
}
|
|
|
|
public function testVerifyInvalidJWT(): void
|
|
{
|
|
$result = $this->authService->verifyJWT('invalid_token');
|
|
|
|
$this->assertNull($result);
|
|
}
|
|
} |