Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d203ef0

Browse files
Henry Snoekwouterj
Henry Snoek
authored andcommitted
Simplify code example in "Adding custom extensions" section
1 parent 523d08c commit d203ef0

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

cookbook/form/unit_testing.rst

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -173,39 +173,22 @@ on other extensions. You need to add those extensions to the factory object::
173173

174174
use AppBundle\Form\Type\TestedType;
175175
use AppBundle\Model\TestObject;
176-
use Symfony\Component\Form\Test\TypeTestCase;
176+
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
177177
use Symfony\Component\Form\Forms;
178178
use Symfony\Component\Form\FormBuilder;
179-
use Symfony\Component\Form\Extension\Validator\Type\FormTypeValidatorExtension;
179+
use Symfony\Component\Form\Test\TypeTestCase;
180180
use Symfony\Component\Validator\ConstraintViolationList;
181181

182182
class TestedTypeTest extends TypeTestCase
183183
{
184-
protected function setUp()
184+
protected function getExtensions()
185185
{
186-
parent::setUp();
187-
188-
$validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface');
186+
$validator = $this->getMock('\Symfony\Component\Validator\Validator\ValidatorInterface');
189187
$validator->method('validate')->will($this->returnValue(new ConstraintViolationList()));
190188

191-
$this->factory = Forms::createFormFactoryBuilder()
192-
->addExtensions($this->getExtensions())
193-
->addTypeExtension(
194-
new FormTypeValidatorExtension(
195-
$validator
196-
)
197-
)
198-
->addTypeGuesser(
199-
$this->getMockBuilder(
200-
'Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser'
201-
)
202-
->disableOriginalConstructor()
203-
->getMock()
204-
)
205-
->getFormFactory();
206-
207-
$this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
208-
$this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory);
189+
return array(
190+
new ValidatorExtension($validator),
191+
);
209192
}
210193

211194
// ... your tests

0 commit comments

Comments
 (0)