forked from fa/breadcrumb-the-shire
38 lines
1.3 KiB
PHP
38 lines
1.3 KiB
PHP
|
|
<?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']);
|
||
|
|
}
|
||
|
|
}
|