<?php

namespace Tests\Traits;

use App\Services\Article\ArticleFetcher;
use App\Services\Log\LogSaver;
use Mockery;
use Mockery\MockInterface;

trait CreatesArticleFetcher
{
    protected function createArticleFetcher(?LogSaver $logSaver = null): ArticleFetcher
    {
        if (! $logSaver) {
            $logSaver = Mockery::mock(LogSaver::class);
            $logSaver->shouldReceive('info')->zeroOrMoreTimes();
            $logSaver->shouldReceive('warning')->zeroOrMoreTimes();
            $logSaver->shouldReceive('error')->zeroOrMoreTimes();
            $logSaver->shouldReceive('debug')->zeroOrMoreTimes();
        }

        return new ArticleFetcher($logSaver);
    }

    /** @return array{ArticleFetcher, MockInterface} */
    protected function createArticleFetcherWithMockedLogSaver(): array
    {
        $logSaver = Mockery::mock(LogSaver::class);
        $logSaver->shouldReceive('info')->zeroOrMoreTimes();
        $logSaver->shouldReceive('warning')->zeroOrMoreTimes();
        $logSaver->shouldReceive('error')->zeroOrMoreTimes();
        $logSaver->shouldReceive('debug')->zeroOrMoreTimes();

        $articleFetcher = new ArticleFetcher($logSaver);

        return [$articleFetcher, $logSaver];
    }
}
