<?php

namespace MintyPHP\Tests\Service\Access;

use MintyPHP\Repository\Access\PermissionRepository;
use MintyPHP\Repository\Access\RolePermissionRepository;
use MintyPHP\Repository\Access\UserRoleRepository;
use MintyPHP\Service\Access\AccessServicesFactory;
use MintyPHP\Service\Access\PermissionGateway;
use PHPUnit\Framework\TestCase;

class AccessServicesFactoryTest extends TestCase
{
    public function testFactoryReturnsStableInstancesPerFactoryObject(): void
    {
        $factory = new AccessServicesFactory();

        $this->assertInstanceOf(PermissionRepository::class, $factory->createPermissionRepository());
        $this->assertSame($factory->createPermissionRepository(), $factory->createPermissionRepository());

        $this->assertInstanceOf(RolePermissionRepository::class, $factory->createRolePermissionRepository());
        $this->assertSame($factory->createRolePermissionRepository(), $factory->createRolePermissionRepository());

        $this->assertInstanceOf(UserRoleRepository::class, $factory->createUserRoleRepository());
        $this->assertSame($factory->createUserRoleRepository(), $factory->createUserRoleRepository());

        $this->assertInstanceOf('MintyPHP\\Service\\Access\\PermissionService', $factory->createPermissionService());
        $this->assertSame($factory->createPermissionService(), $factory->createPermissionService());

        $this->assertInstanceOf(PermissionGateway::class, $factory->createPermissionGateway());
        $this->assertSame($factory->createPermissionGateway(), $factory->createPermissionGateway());
    }
}
