<?php

namespace NoahVet\Reef\Infrastructure\Phpunit\Traits;

use NoahVet\Reef\Contract\Phpunit\EndpointTestBuilderInterface;
use NoahVet\Reef\Infrastructure\Phpunit\Builder\EndpointTestBuilder;
use NoahVet\Reef\Infrastructure\Phpunit\Loader\OasExampleLoader;
use NoahVet\Reef\Phpunit\Fixture\FixtureRepository;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;

/**
 * Provides fluent HTTP endpoint testing for WebTestCase subclasses.
 *
 * The using class must have a $client property (KernelBrowser) and must extend
 * WebTestCase (or KernelTestCase) so that static::getContainer() is available.
 */
trait MakesApiRequestsTrait
{
    public function endpoint(string $method, string $path): EndpointTestBuilderInterface
    {
        /** @var KernelBrowser $this->client */
        /** @var FixtureRepository $fixtureRepository */
        $fixtureRepository = static::getContainer()->get(FixtureRepository::class);

        return new EndpointTestBuilder(
            $this->client,
            $method,
            $path,
            $fixtureRepository,
            new OasExampleLoader(),
        );
    }
}
