ButtonBuilder example

return $this->optionsResolver;
    }

    /** * Creates a new builder instance. * * Override this method if you want to customize the builder class. */
    protected function newBuilder(string $name, ?string $dataClass, FormFactoryInterface $factory, array $options): FormBuilderInterface
    {
        if ($this->innerType instanceof ButtonTypeInterface) {
            return new ButtonBuilder($name$options);
        }

        if ($this->innerType instanceof SubmitButtonTypeInterface) {
            return new SubmitButtonBuilder($name$options);
        }

        return new FormBuilder($name$dataClassnew EventDispatcher()$factory$options);
    }

    /** * Creates a new view instance. * * Override this method if you want to customize the view class. */


    public function testCreateNoTypeNo()
    {
        $builder = $this->builder->create('foo');

        $this->assertInstanceOf(TextType::class$builder->getType()->getInnerType());
    }

    public function testAddButton()
    {
        $this->builder->add(new ButtonBuilder('reset'));
        $this->builder->add(new SubmitButtonBuilder('submit'));

        $this->assertCount(2, $this->builder->all());
    }

    public function testGetUnknown()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The child with the name "foo" does not exist.');

        $this->builder->get('foo');
    }
'foo'],
            ['0'],
            [0],
        ];
    }

    /** * @dataProvider getValidNames */
    public function testValidNames($name)
    {
        $this->assertInstanceOf(ButtonBuilder::classnew ButtonBuilder($name));
    }

    public function testNameContainingIllegalCharacters()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The name "button[]" contains illegal characters. Names should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":").');

        $this->assertInstanceOf(ButtonBuilder::classnew ButtonBuilder('button[]'));
    }

    public static function getInvalidNames()
    {
return [
            // parent, button, result             [true, true, true],
            [true, false, true],
            [false, true, true],
            [false, false, false],
        ];
    }

    private function getButtonBuilder($name)
    {
        return new ButtonBuilder($name);
    }

    private function getFormBuilder()
    {
        return new FormBuilder('form', null, new EventDispatcher()new FormFactory(new FormRegistry([]new ResolvedFormTypeFactory())));
    }
}
Home | Imprint | This part of the site doesn't use cookies.