public function testCreateBuilder() { $parentType = $this->getMockFormType(); $type = $this->getMockFormType(); $extension1 = $this->getMockFormTypeExtension(); $extension2 = $this->getMockFormTypeExtension(); $parentResolvedType = new ResolvedFormType($parentType); $resolvedType = new ResolvedFormType($type, array($extension1, $extension2), $parentResolvedType); $test = $this; $i = 0; $assertIndex = function ($index) use(&$i, $test) { return function () use(&$i, $test, $index) { /* @var \PHPUnit_Framework_TestCase $test */ $test->assertEquals($index, $i, 'Executed at index ' . $index); ++$i; }; }; $assertIndexAndAddOption = function ($index, $option, $default) use($assertIndex) { $assertIndex = $assertIndex($index); return function (OptionsResolverInterface $resolver) use($assertIndex, $index, $option, $default) { $assertIndex(); $resolver->setDefaults(array($option => $default)); }; }; // First the default options are generated for the super type $parentType->expects($this->once())->method('setDefaultOptions')->will($this->returnCallback($assertIndexAndAddOption(0, 'a', 'a_default'))); // The form type itself $type->expects($this->once())->method('setDefaultOptions')->will($this->returnCallback($assertIndexAndAddOption(1, 'b', 'b_default'))); // And its extensions $extension1->expects($this->once())->method('setDefaultOptions')->will($this->returnCallback($assertIndexAndAddOption(2, 'c', 'c_default'))); $extension2->expects($this->once())->method('setDefaultOptions')->will($this->returnCallback($assertIndexAndAddOption(3, 'd', 'd_default'))); $givenOptions = array('a' => 'a_custom', 'c' => 'c_custom'); $resolvedOptions = array('a' => 'a_custom', 'b' => 'b_default', 'c' => 'c_custom', 'd' => 'd_default'); // Then the form is built for the super type $parentType->expects($this->once())->method('buildForm')->with($this->anything(), $resolvedOptions)->will($this->returnCallback($assertIndex(4))); // Then the type itself $type->expects($this->once())->method('buildForm')->with($this->anything(), $resolvedOptions)->will($this->returnCallback($assertIndex(5))); // Then its extensions $extension1->expects($this->once())->method('buildForm')->with($this->anything(), $resolvedOptions)->will($this->returnCallback($assertIndex(6))); $extension2->expects($this->once())->method('buildForm')->with($this->anything(), $resolvedOptions)->will($this->returnCallback($assertIndex(7))); $factory = $this->getMockFormFactory(); $builder = $resolvedType->createBuilder($factory, 'name', $givenOptions); $this->assertSame($resolvedType, $builder->getType()); }
/** * {@inheritdoc} */ public function finishView(FormView $view, FormInterface $form, array $options) { parent::finishView($view, $form, $options); $children = $view->children; $view->children = array(); foreach ($this->orderer->order($form) as $name) { $view->children[$name] = $children[$name]; unset($children[$name]); } foreach ($children as $name => $child) { $view->children[$name] = $child; } }
/** * @dataProvider provideTypeClassBlockPrefixTuples */ public function testBlockPrefixDefaultsToFQCNIfNoName($typeClass, $blockPrefix) { $resolvedType = new ResolvedFormType(new $typeClass()); $this->assertSame($blockPrefix, $resolvedType->getBlockPrefix()); }
/** * Creates a new builder instance. * * Override this method if you want to customize the builder class. * * @param string $name The name of the builder. * @param string $dataClass The data class. * @param FormFactoryInterface $factory The current form factory. * @param array $options The builder options. * * @return FormBuilderInterface The new builder instance. */ protected function newBuilder($name, $dataClass, FormFactoryInterface $factory, array $options) { parent::newBuilder($name, $dataClass, $factory, $options); return new FormBuilder($name, $dataClass, new EventDispatcher(), $factory, $options); }