<?php

declare(strict_types=1);

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Tests\Form\Admin;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Admin\ProductTypeType;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\FormBuilderInterface;

final class ProductTypeTypeTest extends TestCase
{
    public function testSkuCodeIsRequiredAndExplained(): void
    {
        $codeOptions = null;
        $builder = $this->createMock(FormBuilderInterface::class);
        $builder->method('add')
            ->willReturnCallback(static function (mixed $child, ?string $type = null, array $options = []) use (&$codeOptions, $builder): FormBuilderInterface {
                if ('code' === $child) {
                    $codeOptions = $options;
                }

                return $builder;
            });

        new ProductTypeType()->buildForm($builder, []);

        self::assertIsArray($codeOptions);
        self::assertTrue($codeOptions['required']);
        self::assertSame('product_type.sku_code.label', $codeOptions['label']);
        self::assertSame('product_type.sku_code.help', $codeOptions['help']);
    }
}
