<?php

namespace App\tests\Unit\Service\File\Utils;

use App\Entity\Core\File;
use App\Service\Utils\FileUtils;
use App\Tests\Unit\TestToolsTrait;
use Liip\ImagineBundle\Imagine\Data\DataManager;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

class FileUtilsTest extends TestCase
{
    use TestToolsTrait;

    private MockObject|DataManager $dataManager;
    private MockObject|FilterManager $filterManager;
    private MockObject|LoggerInterface $logger;

    public function setUp(): void
    {
        $this->dataManager = $this->getMockBuilder(DataManager::class)->disableOriginalConstructor()->getMock();
        $this->filterManager = $this->getMockBuilder(FilterManager::class)->disableOriginalConstructor()->getMock();
        $this->logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
    }

    public function getFileUtilsMockFor(string $methodName): FileUtils|MockObject
    {
        return $this->getMockBuilder(FileUtils::class)
            ->setConstructorArgs([$this->dataManager, $this->filterManager, $this->logger])
            ->setMethodsExcept([$methodName])
            ->getMock();
    }

    /**
     * @return void
     *
     *@see FileUtils::isImage()
     */
    public function testIsImage()
    {
        $file = $this->getMockBuilder(File::class)->getMock();
        $file->method('getMimeType')->willReturn('image/jpeg');

        $FileUtils = $this->getFileUtilsMockFor('isImage');

        $this->assertTrue($FileUtils->isImage($file));
    }
}
