/** * @dataProvider transformerProvider * * @param array $existingTransformers * @param string $type * @param DataTransformerInterface $toReplace * @param array $expected */ public function testReplaceTransformer(array $existingTransformers, $type, $toReplace, array $expected) { $builder = $this->getMock('Symfony\\Component\\Form\\Test\\FormBuilderInterface'); $model = 'model' === $type; $builder->expects($this->once())->method($model ? 'getModelTransformers' : 'getViewTransformers')->willReturn($existingTransformers); $builder->expects($this->once())->method($model ? 'resetModelTransformers' : 'resetViewTransformers'); $newTransformers = []; $builder->expects($this->any())->method($model ? 'addModelTransformer' : 'addViewTransformer')->willReturnCallback(function ($transformer) use(&$newTransformers) { $newTransformers[] = $transformer; }); FormUtils::replaceTransformer($builder, $toReplace, $type); $this->assertSame($expected, $newTransformers); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->remove('year'); FormUtils::replaceTransformer($builder, new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], ['month', 'day']), 'view'); FormUtils::replaceTransformer($builder, new ReversedTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], ['month', 'day']))); }