Skip to content

Commit

Permalink
minor #575 [Documentation] Add unit testing section (AlexandreGerault…
Browse files Browse the repository at this point in the history
…, 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
  • Loading branch information
weaverryan committed Dec 1, 2022
2 parents e03f9c0 + 47f15c0 commit 25b7635
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Autocomplete/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,30 @@ Beyond ``url``, the Stimulus controller has various other values,
including ``tomSelectOptions``. See the `controller.ts`_ file for
the full list.

Unit testing
------------

When writing unit tests for your form, using the ``TypeTestCase`` class, you
consider registering the needed type extension ``AutocompleteChoiceTypeExtension`` like so::

// tests/Form/Type/TestedTypeTest.php
namespace App\Tests\Form\Type;
use Symfony\Component\Form\Test\TypeTestCase;
use Symfony\UX\Autocomplete\Form\AutocompleteChoiceTypeExtension;
class TestedTypeTest extends TypeTestCase
{
protected function getTypeExtensions(): array
{
return [
new AutocompleteChoiceTypeExtension(),
];
}
// ... your tests
}

Backward Compatibility promise
------------------------------

Expand Down

0 comments on commit 25b7635

Please sign in to comment.