Skip to content

Commit 83641f8

Browse files
Ulrichweaverryan
Ulrich
authored andcommitted
Update how to add custom Type
New in sf2.3, update the way we have to use to add custom Type.
1 parent ba4a5a8 commit 83641f8

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

cookbook/form/unit_testing.rst

+11-4
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,28 @@ might look like this::
117117

118118
To create your form correctly, you need to make the type available to the
119119
form factory in your test. The easiest way is to register it manually
120-
before creating the parent form::
120+
before creating the parent form using PreloadedExtension class::
121121

122122
// src/Acme/TestBundle/Tests/Form/Type/TestedTypeTests.php
123123
namespace Acme\TestBundle\Tests\Form\Type;
124124

125125
use Acme\TestBundle\Form\Type\TestedType;
126126
use Acme\TestBundle\Model\TestObject;
127-
use Symfony\Component\Form\Tests\Extension\Core\Type\TypeTestCase;
127+
use Symfony\Component\Form\Test\TypeTestCase;
128+
use Symfony\Component\Form\PreloadedExtension;
128129

129130
class TestedTypeTest extends TypeTestCase
130131
{
131-
public function testBindValidData()
132+
protected function getExtensions()
132133
{
133-
$this->factory->addType(new TestChildType());
134+
$childType = new TestChildType();
135+
return array(new PreloadedExtension(array(
136+
$childType->getName() => $childType
137+
), array()));
138+
}
134139

140+
public function testBindValidData()
141+
{
135142
$type = new TestedType();
136143
$form = $this->factory->create($type);
137144

0 commit comments

Comments
 (0)