use FakePasswordHasher in tests to eliminate bcrypt cost

Add a trivial prefix-based PasswordHasher fake and inject it into the
three test files that exercise CreateUser or AuthenticateUser. Drops
the full phpunit suite from ~7.4s to ~30ms (about 224x) without
losing coverage: the round-trip through hash/verify still validates
that CreateUser stores something other than the plaintext and that
AuthenticateUser only succeeds on a matching hash.

CreateUserTest is also refactored to use a setUp method, matching
the pattern already used in AuthenticateUserTest and AuthControllerTest.
This commit is contained in:
Yisroel Baum 2026-04-26 09:06:26 +03:00
parent 632085f5b6
commit bb6bd7cbb3
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
4 changed files with 76 additions and 39 deletions

View file

@ -10,22 +10,31 @@ use App\User\UseCases\CreateUser;
use App\User\UseCases\CreateUserRequest;
use App\User\User;
use PHPUnit\Framework\TestCase;
use Tests\Fakes\FakePasswordHasher;
use Tests\Fakes\FakeUserRepository;
class AuthenticateUserTest extends TestCase
{
private FakeUserRepository $userRepo;
private FakePasswordHasher $passwordHasher;
private AuthenticateUser $useCase;
public function setUp(): void
{
$this->userRepo = new FakeUserRepository();
$createUser = new CreateUser($this->userRepo);
$this->passwordHasher = new FakePasswordHasher();
$createUser = new CreateUser(
$this->userRepo,
$this->passwordHasher,
);
$createUser->execute(new CreateUserRequest(
email: 'test@test.com',
password: 'password1',
));
$this->useCase = new AuthenticateUser($this->userRepo);
$this->useCase = new AuthenticateUser(
$this->userRepo,
$this->passwordHasher,
);
}
public function test_returns_user_on_valid_credentials(): void