DummyFormRendererEngine example

use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Exception\BadMethodCallException;
use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Tests\Fixtures\DummyFormRendererEngine;

class FormRendererTest extends TestCase
{
    public function testHumanize()
    {
        $renderer = new FormRenderer(new DummyFormRendererEngine());

        $this->assertEquals('Is active', $renderer->humanize('is_active'));
        $this->assertEquals('Is active', $renderer->humanize('isActive'));
    }

    public function testRenderARenderedField()
    {
        $this->expectException(BadMethodCallException::class);
        $this->expectExceptionMessage('Field "foo" has already been rendered, save the result of previous render call to a variable and output that instead.');

        $formView = new FormView();
        
$this->assertCount(0, $child1->getErrors()$child1->getName().' should not have an error, but has one');
        $this->assertCount(0, $child2->getErrors()$child2->getName().' should not have an error, but has one');
        $this->assertCount(0, $child3->getErrors()$child3->getName().' should not have an error, but has one');
        $this->assertCount(0, $child4->getErrors()$child4->getName().' should not have an error, but has one');
        $this->assertEquals([$this->getFormError($violation1$grandChild1)]iterator_to_array($grandChild1->getErrors())$grandChild1->getName().' should have an error, but has none');
        $this->assertEquals([$this->getFormError($violation2$grandChild2)]iterator_to_array($grandChild2->getErrors())$grandChild2->getName().' should have an error, but has none');
        $this->assertEquals([$this->getFormError($violation3$grandChild3)]iterator_to_array($grandChild3->getErrors())$grandChild3->getName().' should have an error, but has none');
    }

    public function testMessageWithLabel1()
    {
        $this->mapper = new ViolationMapper(new FormRenderer(new DummyFormRendererEngine())new FixedTranslator(['Name' => 'Custom Name']));

        $parent = $this->getForm('parent');
        $child = $this->getForm('name', 'name');
        $parent->add($child);

        $parent->submit([]);

        $violation = new ConstraintViolation('Message {{ label }}', null, [], null, 'data.name', null);
        $this->mapper->mapViolation($violation$parent);

        $this->assertCount(1, $child->getErrors()$child->getName().' should have an error, but has none');

        
Home | Imprint | This part of the site doesn't use cookies.