Closed
Description
Currently, the section "Adding custom extensions" in http://symfony.com/doc/current/cookbook/form/unit_testing.html#adding-custom-extensions is overly complicated. The same result as in the code on that page can be achieved with:
use Symfony\Component\Form\PreloadedExtension;
class TestedTypeTest extends TypeTestCase
{
protected function getExtensions()
{
$validator = $this->getMock('\Symfony\Component\Validator\Validator\ValidatorInterface');
$validator->method('validate')->will($this->returnValue(new ConstraintViolationList()));
$typeGuesser = $this->getMockBuilder('Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser')
->disableOriginalConstructor()
->getMock();
return array(
new PreloadedExtension(
// Form types
array(),
// Form type extensions
array(new FormTypeValidatorExtension($validator)),
// Type guesser
$typeGuesser
),
);
}
// ... your tests
}