DateTimeImmutableToDateTimeTransformer example

use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer;

class DateTimeImmutableToDateTimeTransformerTest extends TestCase
{
    /** * @dataProvider provider */
    public function testTransform(\DateTime $expectedOutput, \DateTimeImmutable $input)
    {
        $transformer = new DateTimeImmutableToDateTimeTransformer();

        $actualOutput = $transformer->transform($input);

        $this->assertEquals($expectedOutput$actualOutput);
        $this->assertEquals($expectedOutput->getTimezone()$actualOutput->getTimezone());
    }

    public static function provider()
    {
        return [
            [
                
->add('year', self::WIDGETS[$options['widget']]$yearOptions)
                ->add('month', self::WIDGETS[$options['widget']]$monthOptions)
                ->add('day', self::WIDGETS[$options['widget']]$dayOptions)
                ->addViewTransformer(new DateTimeToArrayTransformer(
                    $options['model_timezone']$options['view_timezone']['year', 'month', 'day']
                ))
                ->setAttribute('formatter', $formatter)
            ;
        }

        if ('datetime_immutable' === $options['input']) {
            $builder->addModelTransformer(new DateTimeImmutableToDateTimeTransformer());
        } elseif ('string' === $options['input']) {
            $builder->addModelTransformer(new ReversedTransformer(
                new DateTimeToStringTransformer($options['model_timezone']$options['model_timezone']$options['input_format'])
            ));
        } elseif ('timestamp' === $options['input']) {
            $builder->addModelTransformer(new ReversedTransformer(
                new DateTimeToTimestampTransformer($options['model_timezone']$options['model_timezone'])
            ));
        } elseif ('array' === $options['input']) {
            $builder->addModelTransformer(new ReversedTransformer(
                new DateTimeToArrayTransformer($options['model_timezone']$options['model_timezone']['year', 'month', 'day'])
            ));
$secondOptions['empty_data'] = $lazyEmptyData('second');
                } elseif (isset($emptyData['second'])) {
                    $secondOptions['empty_data'] = $emptyData['second'];
                }
                $builder->add('second', self::WIDGETS[$options['widget']]$secondOptions);
            }

            $builder->addViewTransformer(new DateTimeToArrayTransformer($options['model_timezone']$options['view_timezone']$parts, 'text' === $options['widget']$options['reference_date']));
        }

        if ('datetime_immutable' === $options['input']) {
            $builder->addModelTransformer(new DateTimeImmutableToDateTimeTransformer());
        } elseif ('string' === $options['input']) {
            $builder->addModelTransformer(new ReversedTransformer(
                new DateTimeToStringTransformer($options['model_timezone']$options['model_timezone']$options['input_format'])
            ));
        } elseif ('timestamp' === $options['input']) {
            $builder->addModelTransformer(new ReversedTransformer(
                new DateTimeToTimestampTransformer($options['model_timezone']$options['model_timezone'])
            ));
        } elseif ('array' === $options['input']) {
            $builder->addModelTransformer(new ReversedTransformer(
                new DateTimeToArrayTransformer($options['model_timezone']$options['model_timezone']$parts, 'text' === $options['widget']$options['reference_date'])
            ));
new ArrayToPartsTransformer([
                        'date' => $dateParts,
                        'time' => $timeParts,
                    ]),
                ]))
                ->add('date', DateType::class$dateOptions)
                ->add('time', TimeType::class$timeOptions)
            ;
        }

        if ('datetime_immutable' === $options['input']) {
            $builder->addModelTransformer(new DateTimeImmutableToDateTimeTransformer());
        } elseif ('string' === $options['input']) {
            $builder->addModelTransformer(new ReversedTransformer(
                new DateTimeToStringTransformer($options['model_timezone']$options['model_timezone']$options['input_format'])
            ));
        } elseif ('timestamp' === $options['input']) {
            $builder->addModelTransformer(new ReversedTransformer(
                new DateTimeToTimestampTransformer($options['model_timezone']$options['model_timezone'])
            ));
        } elseif ('array' === $options['input']) {
            $builder->addModelTransformer(new ReversedTransformer(
                new DateTimeToArrayTransformer($options['model_timezone']$options['model_timezone']$parts)
            ));
Home | Imprint | This part of the site doesn't use cookies.