Skip to content

Commit 9e6c22f

Browse files
Add unit testing section
Changing a native `ChoiceType` to an autocomplete field, using [Symfony-UX/autocomplete](https://symfony.com/bundles/ux-autocomplete/current/index.html), might cause unit tests for forms to fail. It needs to register the right TypeExtensions to make it work correctly.
1 parent e03f9c0 commit 9e6c22f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/Autocomplete/doc/index.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,31 @@ Beyond ``url``, the Stimulus controller has various other values,
485485
including ``tomSelectOptions``. See the `controller.ts`_ file for
486486
the full list.
487487

488+
Unit testing
489+
------------
490+
491+
When writing unit tests for your form, using the ``TypeTestCase`` class, you should consider registering the needed type extension ``Symfony\UX\Autocomplete\Form\AutocompleteChoiceTypeExtension`` like so::
492+
493+
// tests/Form/Type/TestedTypeTest.php
494+
namespace App\Tests\Form\Type;
495+
496+
use Symfony\Component\Form\Test\TypeTestCase;
497+
use Symfony\UX\Autocomplete\Form\AutocompleteChoiceTypeExtension;
498+
499+
class TestedTypeTest extends TypeTestCase
500+
{
501+
protected function getTypeExtensions(): array
502+
{
503+
return [
504+
new AutocompleteChoiceTypeExtension(),
505+
];
506+
}
507+
508+
// ... your tests
509+
}
510+
511+
512+
488513
Backward Compatibility promise
489514
------------------------------
490515

0 commit comments

Comments
 (0)