diff --git a/cookbook/form/unit_testing.rst b/cookbook/form/unit_testing.rst index 8522f39efa9..9e0d84b2b63 100644 --- a/cookbook/form/unit_testing.rst +++ b/cookbook/form/unit_testing.rst @@ -117,7 +117,7 @@ might look like this:: To create your form correctly, you need to make the type available to the form factory in your test. The easiest way is to register it manually -before creating the parent form:: +before creating the parent form using PreloadedExtension class:: // src/Acme/TestBundle/Tests/Form/Type/TestedTypeTests.php namespace Acme\TestBundle\Tests\Form\Type; @@ -125,13 +125,20 @@ before creating the parent form:: use Acme\TestBundle\Form\Type\TestedType; use Acme\TestBundle\Model\TestObject; use Symfony\Component\Form\Test\TypeTestCase; + use Symfony\Component\Form\PreloadedExtension; class TestedTypeTest extends TypeTestCase { - public function testSubmitValidData() + protected function getExtensions() { - $this->factory->addType(new TestChildType()); + $childType = new TestChildType(); + return array(new PreloadedExtension(array( + $childType->getName() => $childType, + ), array())); + } + public function testSubmitValidData() + { $type = new TestedType(); $form = $this->factory->create($type); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy