From c2ade8a6015570cabe06f085821ee288745d5184 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Fri, 24 Apr 2026 13:21:51 +0300 Subject: [PATCH] test fake session repository --- tests/Unit/Auth/FakeSessionRepositoryTest.php | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/Unit/Auth/FakeSessionRepositoryTest.php diff --git a/tests/Unit/Auth/FakeSessionRepositoryTest.php b/tests/Unit/Auth/FakeSessionRepositoryTest.php new file mode 100644 index 0000000..6e2bce4 --- /dev/null +++ b/tests/Unit/Auth/FakeSessionRepositoryTest.php @@ -0,0 +1,68 @@ +sessionRepo = new FakeSessionRepository(); + } + + public function test_create_and_find_by_token(): void + { + $this->sessionRepo->create(new CreateSessionDto( + token: 'abc123', + userId: 0, + createdAt: new DateTimeImmutable('2025-01-01'), + expiresAt: new DateTimeImmutable('2025-01-08'), + )); + + $session = $this->sessionRepo->findByToken('abc123'); + + $this->assertInstanceOf(Session::class, $session); + $this->assertEquals('abc123', $session->getToken()); + $this->assertEquals(0, $session->getUserId()); + } + + public function test_find_by_token_returns_null_when_missing(): void + { + $this->assertNull($this->sessionRepo->findByToken('nope')); + } + + public function test_find_by_token_returns_fresh_instance(): void + { + $created = $this->sessionRepo->create(new CreateSessionDto( + token: 'abc123', + userId: 0, + createdAt: new DateTimeImmutable('2025-01-01'), + expiresAt: new DateTimeImmutable('2025-01-08'), + )); + + $fetched = $this->sessionRepo->findByToken('abc123'); + + $this->assertNotSame($created, $fetched); + } + + public function test_delete_by_token(): void + { + $this->sessionRepo->create(new CreateSessionDto( + token: 'abc123', + userId: 0, + createdAt: new DateTimeImmutable('2025-01-01'), + expiresAt: new DateTimeImmutable('2025-01-08'), + )); + + $this->sessionRepo->deleteByToken('abc123'); + + $this->assertNull($this->sessionRepo->findByToken('abc123')); + } +}