<?php

namespace CpCreation\VitiCore\Tests\Media\Model;

use CpCreation\VitiCore\Media\Model\File;
use CpCreation\VitiCore\Media\Model\Image;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Constraints\File as FileConstraint;

if (!class_exists(File::class, false)) {
    require_once \dirname(__DIR__, 3).'/src/Media/Model/File.php';
}

if (!class_exists(Image::class, false)) {
    require_once \dirname(__DIR__, 3).'/src/Media/Model/Image.php';
}

#[RunTestsInSeparateProcesses]
#[PreserveGlobalState(false)]
final class MediaUploadConstraintTest extends TestCase
{
    #[DataProvider('mediaClasses')]
    public function testMediaUploadsAllowTenMegabytes(string $mediaClass): void
    {
        $attributes = new \ReflectionProperty($mediaClass, 'file')
            ->getAttributes(FileConstraint::class);

        self::assertCount(1, $attributes);

        /** @var FileConstraint $constraint */
        $constraint = $attributes[0]->newInstance();

        self::assertSame(10_000_000, $constraint->maxSize);
    }

    /**
     * @return iterable<string, array{class-string}>
     */
    public static function mediaClasses(): iterable
    {
        yield 'image' => [Image::class];
        yield 'fichier' => [File::class];
    }
}
