Skip to content

[Form] Fix "Adding custom extensions" section #5225

Closed
@webmozart

Description

@webmozart

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    FormactionableClear and specific issues ready for anyone to take them.good first issueIdeal for your first contribution! (some Symfony experience may be required)hasPRA Pull Request has already been submitted for this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions