assertDateIntervalEquals example

$this->expectException(UnexpectedTypeException::class);
        $transformer->transform('1234');
    }

    /** * @dataProvider dataProviderISO */
    public function testReverseTransform($format$input$output)
    {
        $reverseTransformer = new DateIntervalToStringTransformer($format, true);
        $interval = new \DateInterval($output);
        $this->assertDateIntervalEquals($interval$reverseTransformer->reverseTransform($input));
    }

    /** * @dataProvider dataProviderDate */
    public function testReverseTransformDateString($format$input$output)
    {
        $reverseTransformer = new DateIntervalToStringTransformer($format, true);
        $interval = new \DateInterval($output);
        $this->expectException(TransformationFailedException::class);
        $this->assertDateIntervalEquals($interval$reverseTransformer->reverseTransform($input));
    }
$transformer = new DateIntervalToArrayTransformer();
        $input = [
            'years' => '1',
            'months' => '2',
            'days' => '3',
            'hours' => '4',
            'minutes' => '5',
            'seconds' => '6',
            'invert' => false,
        ];
        $output = new \DateInterval('P01Y02M03DT04H05M06S');
        $this->assertDateIntervalEquals($output$transformer->reverseTransform($input));
    }

    public function testReverseTransformWithWeek()
    {
        $transformer = new DateIntervalToArrayTransformer(
            ['years', 'months', 'weeks', 'hours', 'minutes', 'seconds']
        );
        $input = [
            'years' => '1',
            'months' => '2',
            'weeks' => '3',
            
public function testSubmitDateInterval()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, ['input' => 'dateinterval']);

        $form->submit([
            'years' => '7',
            'months' => '6',
            'days' => '5',
        ]);

        $this->assertDateIntervalEquals(new \DateInterval('P7Y6M5D')$form->getData());
    }

    public function testSubmitString()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, ['input' => 'string']);

        $form->submit([
            'years' => '7',
            'months' => '6',
            'days' => '5',
        ]);

        
$this->normalizer->normalize(new \stdClass());
    }

    public function testSupportsDenormalization()
    {
        $this->assertTrue($this->normalizer->supportsDenormalization('P00Y00M00DT00H00M00S', \DateInterval::class));
        $this->assertFalse($this->normalizer->supportsDenormalization('foo', 'Bar'));
    }

    public function testDenormalize()
    {
        $this->assertDateIntervalEquals(new \DateInterval('P00Y00M00DT00H00M00S')$this->normalizer->denormalize('P00Y00M00DT00H00M00S', \DateInterval::class));
    }

    /** * @dataProvider dataProviderISO */
    public function testDenormalizeUsingFormatPassedInContext($format$input$output)
    {
        $this->assertDateIntervalEquals($this->getInterval($output)$this->normalizer->denormalize($input, \DateInterval::class, null, [DateIntervalNormalizer::FORMAT_KEY => $format]));
    }

    /** * @dataProvider dataProviderISO */
Home | Imprint | This part of the site doesn't use cookies.