Sortie du snippet Symfony "Utilisation du validateur UniqueEntity sans utiliser les annotations"

Environement :

  • Strangebuzz Snippet VM : 2.2.1
  • Symfony : 5.1.3

Sortie du code exécuté :

❌ Form is not valid: Error: "ERROR: Cette valeur est déjà utilisée." (slug: "on-using-the-uniqueentity-validator-without-annotation")
✅ Form is valid! slug: "new-unique-slug"
✅ Form is valid! slug: "other-new-unique-slug"

 Retour au code  ≪ this.showUnitTest ? this.trans.hide_unit_test : this.trans.show_unit_test ≫   Lire la doc  Snippet aléatoire

<?php declare(strict_types=1);

namespace App\Tests\Controller\Snippets;

use App\Form\ArticleType;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Form\FormFactoryInterface;

/**
 * @covers Snippet30Trait
 */
final class Snippet30Test extends KernelTestCase
{
    private FormFactoryInterface $formFactory;

    protected function setUp(): void
    {
        self::bootKernel();
        $this->formFactory = self::$container->get('form.factory');
    }

    public function provide(): array
    {
        return [
            ['on-using-the-uniqueentity-validator-without-annotation', false],
            ['new-unique-slug', true],
            ['other-new-unique-slug', true],

        ];
    }

    /**
     * @covers Snippet30Trait::snippet30
     *
     * @dataProvider provide
     */
    public function testSnippet30(string $slug, bool $isValid): void
    {
        $form = $this->formFactory->create(ArticleType::class);
        $form->submit(compact('slug'));
        self::assertSame($form->isValid(), $isValid);
    }
}