Skip to content

Commit 25b7635

Browse files
committed
minor #575 [Documentation] Add unit testing section (AlexandreGerault, weaverryan)
This PR was merged into the 2.x branch. Discussion ---------- [Documentation] 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. | Q | A | ------------- | --- | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | License | MIT Commits ------- 47f15c0 documentation tweaks 9e6c22f Add unit testing section
2 parents e03f9c0 + 47f15c0 commit 25b7635

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Autocomplete/doc/index.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,30 @@ 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
492+
consider registering the needed type extension ``AutocompleteChoiceTypeExtension`` like so::
493+
494+
// tests/Form/Type/TestedTypeTest.php
495+
namespace App\Tests\Form\Type;
496+
497+
use Symfony\Component\Form\Test\TypeTestCase;
498+
use Symfony\UX\Autocomplete\Form\AutocompleteChoiceTypeExtension;
499+
500+
class TestedTypeTest extends TypeTestCase
501+
{
502+
protected function getTypeExtensions(): array
503+
{
504+
return [
505+
new AutocompleteChoiceTypeExtension(),
506+
];
507+
}
508+
509+
// ... your tests
510+
}
511+
488512
Backward Compatibility promise
489513
------------------------------
490514

0 commit comments

Comments
 (0)