instances added god may help

This commit is contained in:
2026-02-23 12:58:19 +01:00
parent 25370a1a55
commit 99db252f60
290 changed files with 9858 additions and 4914 deletions

View File

@@ -0,0 +1,27 @@
<?php
namespace MintyPHP\Tests\Service\User;
use MintyPHP\Service\User\UserPasswordPolicyService;
use PHPUnit\Framework\TestCase;
class UserPasswordPolicyServiceTest extends TestCase
{
public function testMinLengthMatchesHints(): void
{
$service = new UserPasswordPolicyService();
$this->assertSame(12, $service->minLength());
$hints = $service->hints();
$this->assertNotEmpty($hints);
$this->assertSame('min', (string) ($hints[0]['rule'] ?? ''));
}
public function testValidateRejectsWeakPassword(): void
{
$service = new UserPasswordPolicyService();
$errors = $service->validate('abc', 'abc', true, 'foo@example.com');
$this->assertNotEmpty($errors);
}
}

View File

@@ -0,0 +1,37 @@
<?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']);
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace MintyPHP\Tests\Service\User;
use MintyPHP\Service\User\UserServicesFactory;
use PHPUnit\Framework\TestCase;
class UserServicesFactoryTest extends TestCase
{
public function testFactoryCachesCoreInstances(): void
{
$factory = new UserServicesFactory();
$this->assertSame($factory->createUserAccountService(), $factory->createUserAccountService());
$this->assertSame($factory->createUserAssignmentService(), $factory->createUserAssignmentService());
$this->assertSame($factory->createUserTenantContextService(), $factory->createUserTenantContextService());
$this->assertSame($factory->createUserPasswordService(), $factory->createUserPasswordService());
$this->assertSame($factory->createUserReadRepository(), $factory->createUserReadRepository());
$this->assertSame($factory->createUserWriteRepository(), $factory->createUserWriteRepository());
$this->assertSame($factory->createUserListQueryRepository(), $factory->createUserListQueryRepository());
$this->assertSame($factory->createUserSavedFilterRepository(), $factory->createUserSavedFilterRepository());
$this->assertSame($factory->createUserTenantRepository(), $factory->createUserTenantRepository());
$this->assertSame($factory->createUserRoleRepository(), $factory->createUserRoleRepository());
$this->assertSame($factory->createUserDepartmentRepository(), $factory->createUserDepartmentRepository());
$this->assertSame($factory->createUserPasswordPolicyService(), $factory->createUserPasswordPolicyService());
$this->assertSame($factory->createUserAvatarService(), $factory->createUserAvatarService());
$this->assertSame($factory->createUserSavedFilterService(), $factory->createUserSavedFilterService());
}
}