1
0
Files
breadcrumb-the-shire/tests/Service/User/UserPasswordServiceTest.php

38 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2026-02-23 12:58:19 +01:00
<?php
namespace MintyPHP\Tests\Service\User;
use MintyPHP\Repository\User\UserWriteRepository;
use MintyPHP\Service\User\UserPasswordPolicyService;
use MintyPHP\Service\User\UserPasswordService;
use PHPUnit\Framework\TestCase;
class UserPasswordServiceTest extends TestCase
{
public function testResetPasswordRejectsWeakPassword(): void
{
$writeRepository = $this->createMock(UserWriteRepository::class);
$writeRepository->expects($this->never())->method('setPassword');
$service = new UserPasswordService(new UserPasswordPolicyService(), $writeRepository);
$result = $service->resetPassword(10, 'abc', 'abc');
$this->assertFalse($result['ok']);
$this->assertNotEmpty($result['errors']);
}
public function testResetPasswordUpdatesRepositoryOnValidInput(): void
{
$writeRepository = $this->createMock(UserWriteRepository::class);
$writeRepository->expects($this->once())
->method('setPassword')
->with(11, 'StrongPass1!')
->willReturn(true);
$service = new UserPasswordService(new UserPasswordPolicyService(), $writeRepository);
$result = $service->resetPassword(11, 'StrongPass1!', 'StrongPass1!');
$this->assertTrue($result['ok']);
}
}