<?php

namespace MediaVorus;

use FFMpeg\FFProbe;
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use PHPExiftool\Exiftool;
use PHPExiftool\RDFParser;
use PHPExiftool\Reader;
use PHPExiftool\Writer;

class FileTest extends TestCase
{
    /**
     * Instantiate mediavorus to register the mime types
     */
    public function setUp(): void
    {
        parent::setUp();
        $logger = new Logger('test');
        $logger->pushHandler(new NullHandler());

        $exiftool = new Exiftool($logger);
        $parser = new RDFParser("/tmp", $logger);

        $reader = Reader::create($exiftool, $parser);
        $writer = Writer::create($exiftool);
        $ffprobe = FFProbe::create();

        $mediavorus = new MediaVorus($reader, $writer, $ffprobe);
    }

    /**
     * @covers MediaVorus\File::__construct
     * @covers MediaVorus\File::getMimeType
     */
    public function testGetMimeType()
    {
        $object = new File(__DIR__ . '/../../files/CanonRaw.cr2');
        $this->assertEquals('image/x-tika-canon', $object->getMimeType());
    }

    /**
     * @covers MediaVorus\File::__construct
     * @covers MediaVorus\File::getMimeType
     */
    public function testGetMimeTypeApe()
    {
        $object = new File(__DIR__ . '/../../files/APE.ape');
        $this->assertEquals('audio/x-monkeys-audio', $object->getMimeType());
    }

    /**
     * @covers MediaVorus\File::__construct
     * @covers MediaVorus\Exception\ExceptionInterface
     * @covers MediaVorus\Exception\FileNotFoundException
     */
    public function testFileNotFound()
    {
        $this->expectException(\MediaVorus\Exception\FileNotFoundException::class);
        new File(__DIR__ . '/../../files/nonExistentFile');
    }
}
