Output of the "On using the UniqueEntity validator without annotation" Symfony snippet

Environment:

  • Strangebuzz Snippet VM: 2.2.1
  • Symfony: 5.1.3

Code execution output:

❌ Form is not valid: Error: "ERROR: This value is already used." (slug: "on-using-the-uniqueentity-validator-without-annotation")
✅ Form is valid! slug: "new-unique-slug"
✅ Form is valid! slug: "other-new-unique-slug"

 Back to the code  ≪ this.showUnitTest ? this.trans.hide_unit_test : this.trans.show_unit_test ≫   Read the doc  Random snippet

<?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);
    }
}