<?php

namespace MintyPHP\Tests\Service\AddressBook;

use MintyPHP\Service\AddressBook\AddressBookAvatarGateway;
use MintyPHP\Service\AddressBook\AddressBookCustomFieldGateway;
use MintyPHP\Service\AddressBook\AddressBookDirectoryGateway;
use MintyPHP\Service\AddressBook\AddressBookService;
use MintyPHP\Service\AddressBook\AddressBookServicesFactory;
use PHPUnit\Framework\TestCase;

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

        $directoryGatewayA = $factory->createAddressBookDirectoryGateway();
        $directoryGatewayB = $factory->createAddressBookDirectoryGateway();
        $this->assertInstanceOf(AddressBookDirectoryGateway::class, $directoryGatewayA);
        $this->assertSame($directoryGatewayA, $directoryGatewayB);

        $customFieldGatewayA = $factory->createAddressBookCustomFieldGateway();
        $customFieldGatewayB = $factory->createAddressBookCustomFieldGateway();
        $this->assertInstanceOf(AddressBookCustomFieldGateway::class, $customFieldGatewayA);
        $this->assertSame($customFieldGatewayA, $customFieldGatewayB);

        $avatarGatewayA = $factory->createAddressBookAvatarGateway();
        $avatarGatewayB = $factory->createAddressBookAvatarGateway();
        $this->assertInstanceOf(AddressBookAvatarGateway::class, $avatarGatewayA);
        $this->assertSame($avatarGatewayA, $avatarGatewayB);

        $addressBookServiceA = $factory->createAddressBookService();
        $addressBookServiceB = $factory->createAddressBookService();
        $this->assertInstanceOf(AddressBookService::class, $addressBookServiceA);
        $this->assertSame($addressBookServiceA, $addressBookServiceB);
    }
}
