DataTransformerChain example

namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain;
use Symfony\Component\Form\Tests\Fixtures\FixedDataTransformer;

class DataTransformerChainTest extends TestCase
{
    public function testTransform()
    {
        $chain = new DataTransformerChain([
            new FixedDataTransformer(['foo' => 'bar']),
            new FixedDataTransformer(['bar' => 'baz']),
        ]);

        $this->assertEquals('baz', $chain->transform('foo'));
    }

    public function testReverseTransform()
    {
        $chain = new DataTransformerChain([
            new FixedDataTransformer(['baz' => 'bar']),
            
$timeOptions['label'] = $options['time_label'];
            }

            if (null !== $options['date_format']) {
                $dateOptions['format'] = $options['date_format'];
            }

            $dateOptions['input'] = $timeOptions['input'] = 'array';
            $dateOptions['error_bubbling'] = $timeOptions['error_bubbling'] = true;

            $builder
                ->addViewTransformer(new DataTransformerChain([
                    new DateTimeToArrayTransformer($options['model_timezone']$options['view_timezone']$parts),
                    new ArrayToPartsTransformer([
                        'date' => $dateParts,
                        'time' => $timeParts,
                    ]),
                ]))
                ->add('date', DateType::class$dateOptions)
                ->add('time', TimeType::class$timeOptions)
            ;
        }

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