<?php

namespace NoahVet\Reef\Test\A_Unit\Symfony;

use NoahVet\Reef\Domain\Security\Policy\PolicyInterface;
use NoahVet\Reef\Domain\Security\Port\ResourceFinderInterface;
use NoahVet\Reef\Infrastructure\Security\IAM\Generator\InternalGeneratorInterface;
use NoahVet\Reef\Infrastructure\Security\IAM\Mapper\InternalResourceMapperInterface;
use NoahVet\Reef\Security\User\Provider\ReefOAuthUserProviderInterface;
use NoahVet\Reef\Symfony\ReefApiClientBundle;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class ReefApiClientBundleTest extends TestCase
{
    public function testConstruction(): void
    {
        $bundle = new ReefApiClientBundle();

        /** @var ContainerBuilder|\PHPUnit\Framework\MockObject\MockObject $containerBuilder */
        $containerBuilder = $this->getMockBuilder(ContainerBuilder::class)
            ->disableOriginalConstructor()
            ->getMock()
        ;
        $containerBuilder
            ->expects($this->exactly(5))
            ->method('registerForAutoconfiguration')
            ->willReturnCallback(static function (string $class): ChildDefinition {
                static $index = 0;
                ++$index;

                if (1 === $index) {
                    self::assertSame(InternalResourceMapperInterface::class, $class);
                }

                if (2 === $index) {
                    self::assertSame(InternalGeneratorInterface::class, $class);
                }

                if (3 === $index) {
                    self::assertSame(PolicyInterface::class, $class);
                }

                if (4 === $index) {
                    self::assertSame(ResourceFinderInterface::class, $class);
                }

                if (5 === $index) {
                    self::assertSame(ReefOAuthUserProviderInterface::class, $class);
                }

                return new ChildDefinition('');
            })
        ;

        $bundle->build($containerBuilder);
        self::assertTrue(true);
    }
}
