userRepository = new FakeUserRepository(); $this->passwordHasher = new FakeHasher(); $this->ensureInitialAdmin = new EnsureInitialAdmin( $this->userRepository, $this->passwordHasher, ); } public function testCreatesInitialAdminWhenEmailIsMissing(): void { $this->ensureInitialAdmin->execute( new EnsureInitialAdminRequest( email: 'admin@example.com', password: 'secret-password', ) ); $createdUser = $this->userRepository->findByEmail( new EmailAddress('admin@example.com') ); $this->assertNotNull($createdUser); $this->assertSame( 'hashed-secret-password', $createdUser->getPasswordHash(), ); } public function testLeavesExistingAdminPasswordUnchanged(): void { $this->userRepository->create( new CreateUserDto( email: new EmailAddress('admin@example.com'), passwordHash: 'existing-password-hash', ) ); $this->ensureInitialAdmin->execute( new EnsureInitialAdminRequest( email: 'admin@example.com', password: 'new-secret-password', ) ); $existingUser = $this->userRepository->findByEmail( new EmailAddress('admin@example.com') ); $this->assertNotNull($existingUser); $this->assertSame( 'existing-password-hash', $existingUser->getPasswordHash(), ); } }