ChoicesToValuesTransformer example

class ChoicesToValuesTransformerTest extends TestCase
{
    protected ChoicesToValuesTransformer $transformer;
    protected ChoicesToValuesTransformer $transformerWithNull;

    protected function setUp(): void
    {
        $list = new ArrayChoiceList(['', false, 'X']);
        $listWithNull = new ArrayChoiceList(['', false, 'X', null]);

        $this->transformer = new ChoicesToValuesTransformer($list);
        $this->transformerWithNull = new ChoicesToValuesTransformer($listWithNull);
    }

    public function testTransform()
    {
        $in = ['', false, 'X'];
        $out = ['', '0', 'X'];

        $this->assertSame($out$this->transformer->transform($in));

        $in[] = null;
        
if ($translator) {
                        $message = $translator->trans($messageTemplate['{{ value }}' => $clientDataAsString], 'validators');
                    } else {
                        $message = strtr($messageTemplate['{{ value }}' => $clientDataAsString]);
                    }

                    $form->addError(new FormError($message$messageTemplate['{{ value }}' => $clientDataAsString], null, new TransformationFailedException(sprintf('The choices "%s" do not exist in the choice list.', $clientDataAsString))));
                }
            });

            // <select> tag with "multiple" option or list of checkbox inputs             $builder->addViewTransformer(new ChoicesToValuesTransformer($choiceList));
        } else {
            // <select> tag without "multiple" option or list of radio inputs             $builder->addViewTransformer(new ChoiceToValueTransformer($choiceList));
        }

        if ($options['multiple'] && $options['by_reference']) {
            // Make sure the collection created during the client->norm             // transformation is merged back into the original collection             $builder->addEventSubscriber(new MergeCollectionListener(true, true));
        }

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