format backend code

This commit is contained in:
Yisroel Baum 2026-05-25 20:24:59 +03:00
parent 9577367622
commit 67dd376a2f
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
40 changed files with 146 additions and 71 deletions

View file

@ -31,7 +31,7 @@ class AuthMiddlewareTest extends TestCase
'2026-04-29T12:00:00',
new DateTimeZone('UTC')
);
$this->sessionRepo = new FakeSessionRepository;
$this->sessionRepo = new FakeSessionRepository();
$this->clock = new FakeClock($this->now);
$this->middleware = new AuthMiddleware(
$this->sessionRepo,
@ -58,7 +58,7 @@ class AuthMiddlewareTest extends TestCase
};
}
public function test_missing_cookie_returns_unauthorized_json(): void
public function testMissingCookieReturnsUnauthorizedJson(): void
{
$captured = null;
$response = $this->middleware->handle(
@ -74,7 +74,7 @@ class AuthMiddlewareTest extends TestCase
$this->assertNull($captured);
}
public function test_unknown_token_returns_unauthorized(): void
public function testUnknownTokenReturnsUnauthorized(): void
{
$captured = null;
$response = $this->middleware->handle(
@ -86,7 +86,7 @@ class AuthMiddlewareTest extends TestCase
$this->assertNull($captured);
}
public function test_expired_session_returns_unauthorized_and_is_deleted(): void
public function testExpiredSessionReturnsUnauthorizedAndIsDeleted(): void
{
$user = new User(
id: 7,
@ -113,7 +113,7 @@ class AuthMiddlewareTest extends TestCase
);
}
public function test_valid_session_attaches_user_and_calls_next(): void
public function testValidSessionAttachesUserAndCallsNext(): void
{
$user = new User(
id: 7,

View file

@ -25,7 +25,10 @@ class AuthenticateUserTest extends TestCase
$this->userRepo = new FakeUserRepository();
$this->hasher = new FakeHasher();
$this->authenticateUser = new AuthenticateUser($this->userRepo, $this->hasher);
$this->authenticateUser = new AuthenticateUser(
$this->userRepo,
$this->hasher
);
}
public function testAuthenticatesValidUser(): void

View file

@ -44,8 +44,14 @@ class CreateSessionTest extends TestCase
$this->assertSame('fake-token-123', $session->getToken());
$this->assertSame($user, $session->getUser());
$this->assertFalse($session->isExpired($this->clock->now()));
$this->assertSame('2026-05-18 12:00:00', $session->getCreatedAt()->format('Y-m-d H:i:s'));
$this->assertSame('2026-05-25 12:00:00', $session->getExpiresAt()->format('Y-m-d H:i:s'));
$this->assertSame(
'2026-05-18 12:00:00',
$session->getCreatedAt()->format('Y-m-d H:i:s')
);
$this->assertSame(
'2026-05-25 12:00:00',
$session->getExpiresAt()->format('Y-m-d H:i:s')
);
$stored = $this->sessionRepo->findByToken($session->getToken());
$this->assertNotNull($stored);

View file

@ -25,11 +25,11 @@ class LogoutTest extends TestCase
'2026-04-29T12:00:00',
new DateTimeZone('UTC')
);
$this->sessionRepo = new FakeSessionRepository;
$this->sessionRepo = new FakeSessionRepository();
$this->useCase = new Logout($this->sessionRepo);
}
public function test_existing_token_session_is_removed(): void
public function testExistingTokenSessionIsRemoved(): void
{
$this->sessionRepo->create(new CreateSessionDto(
token: 'token-abc',
@ -47,7 +47,7 @@ class LogoutTest extends TestCase
$this->assertNull($this->sessionRepo->findByToken('token-abc'));
}
public function test_unknown_token_does_not_throw(): void
public function testUnknownTokenDoesNotThrow(): void
{
$this->useCase->execute('unknown-token');

View file

@ -73,7 +73,7 @@ class AuthControllerTest extends TestCase
);
}
public function test_login_returns_200_and_sets_cookie_on_success(): void
public function testLoginReturns200AndSetsCookieOnSuccess(): void
{
$email = 'user@example.com';
$password = 'password';
@ -104,21 +104,21 @@ class AuthControllerTest extends TestCase
);
}
public function test_login_returns_400_when_email_missing(): void
public function testLoginReturns400WhenEmailMissing(): void
{
$request = new Request(['password' => 'correctpassword']);
$response = $this->controller->login($request);
$this->assertEquals(400, $response->getStatusCode());
}
public function test_login_returns_400_when_password_missing(): void
public function testLoginReturns400WhenPasswordMissing(): void
{
$request = new Request(['email' => 'user@example.com']);
$response = $this->controller->login($request);
$this->assertEquals(400, $response->getStatusCode());
}
public function test_login_returns_401_when_credentials_invalid(): void
public function testLoginReturns401WhenCredentialsInvalid(): void
{
$this->seedStartupUser('user@example.com', 'correctpassword');
@ -130,7 +130,7 @@ class AuthControllerTest extends TestCase
$this->assertEquals(401, $response->getStatusCode());
}
public function test_logout_returns_204_and_clears_cookie(): void
public function testLogoutReturns204AndClearsCookie(): void
{
$this->seedStartupUser('user@example.com', 'correctpassword');
$loginRequest = new Request([
@ -139,7 +139,7 @@ class AuthControllerTest extends TestCase
]);
$this->controller->login($loginRequest);
$logoutRequest = new Request;
$logoutRequest = new Request();
$logoutRequest->cookies->set(
AuthMiddleware::COOKIE_NAME,
'session-token-1'
@ -160,7 +160,7 @@ class AuthControllerTest extends TestCase
$this->assertSame('', $cookies[0]->getValue());
}
public function test_me_returns_200_with_user_when_authenticated(): void
public function testMeReturns200WithUserWhenAuthenticated(): void
{
$email = 'me@example.com';
$user = $this->userRepo->create(
@ -170,7 +170,7 @@ class AuthControllerTest extends TestCase
)
);
$request = new Request;
$request = new Request();
$request->attributes->set('user', $user);
$response = $this->controller->me($request);