*/ class DateIntervalNormalizerTest extends TestCase { /** * @var DateIntervalNormalizer */ private $normalizer; protected function setUp() { $this->normalizer = new DateIntervalNormalizer(); } public function dataProviderISO() { $data = array( array('P%YY%MM%DDT%HH%IM%SS', 'P00Y00M00DT00H00M00S', 'PT0S'), array('P%yY%mM%dDT%hH%iM%sS', 'P0Y0M0DT0H0M0S', 'PT0S'), array('P%yY%mM%dDT%hH%iM%sS', 'P10Y2M3DT16H5M6S', 'P10Y2M3DT16H5M6S'), array('P%yY%mM%dDT%hH%iM', 'P10Y2M3DT16H5M', 'P10Y2M3DT16H5M'), array('P%yY%mM%dDT%hH', 'P10Y2M3DT16H', 'P10Y2M3DT16H'), array('P%yY%mM%dD', 'P10Y2M3D', 'P10Y2M3DT0H'), ); return $data; } public function testSupportsNormalization() { $this->assertTrue($this->normalizer->supportsNormalization(new \DateInterval('P00Y00M00DT00H00M00S'))); $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass())); } public function testNormalize() { $this->assertEquals('P0Y0M0DT0H0M0S', $this->normalizer->normalize(new \DateInterval('PT0S'))); } /** * @dataProvider dataProviderISO */ public function testNormalizeUsingFormatPassedInContext($format, $output, $input) { $this->assertEquals($output, $this->normalizer->normalize(new \DateInterval($input), null, array(DateIntervalNormalizer::FORMAT_KEY => $format))); } /** * @dataProvider dataProviderISO */ public function testNormalizeUsingFormatPassedInConstructor($format, $output, $input) { $this->assertEquals($output, (new DateIntervalNormalizer($format))->normalize(new \DateInterval($input))); } /** * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException * @expectedExceptionMessage The object must be an instance of "\DateInterval". */ public function testNormalizeInvalidObjectThrowsException() { $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(new \DateInterval($output), $this->normalizer->denormalize($input, \DateInterval::class, null, array(DateIntervalNormalizer::FORMAT_KEY => $format))); } /** * @dataProvider dataProviderISO */ public function testDenormalizeUsingFormatPassedInConstructor($format, $input, $output) { $this->assertDateIntervalEquals(new \DateInterval($output), (new DateIntervalNormalizer($format))->denormalize($input, \DateInterval::class)); } /** * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException */ public function testDenormalizeExpectsString() { $this->normalizer->denormalize(1234, \DateInterval::class); } /** * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException * @expectedExceptionMessage Expected a valid ISO 8601 interval string. */ public function testDenormalizeNonISO8601IntervalStringThrowsException() { $this->normalizer->denormalize('10 years 2 months 3 days', \DateInterval::class, null); } /** * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException */ public function testDenormalizeInvalidDataThrowsException() { $this->normalizer->denormalize('invalid interval', \DateInterval::class); } /** * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException */ public function testDenormalizeFormatMismatchThrowsException() { $this->normalizer->denormalize('P00Y00M00DT00H00M00S', \DateInterval::class, null, array(DateIntervalNormalizer::FORMAT_KEY => 'P%yY%mM%dD')); } private function assertDateIntervalEquals(\DateInterval $expected, \DateInterval $actual) { $this->assertEquals($expected->format('%RP%yY%mM%dDT%hH%iM%sS'), $actual->format('%RP%yY%mM%dDT%hH%iM%sS')); } } __halt_compiler();----SIGNATURE:----Z6oD6ItuAKKrAi2e67pUU9MIenVXelk9sSxNiw2K8bSwNWUi1BaRj2fUUoLMRxiGbmCxZ5FyhDuOWNAWRt+Nb0gY2/FrHH/8rr1IMimv5LPTSS9F9S5yhFa4+rb2Qp1jlNv2vzDDGKx+Hsi93DrE+QhWNCRAxs7BGFHzPh+covtFXMw4odTYsgB+w1GXV7IpI2zwRZJBWufV+72qwI3yVVw3hs5eT8hQowLqoaG67GD7o2jbBLhoCuLwfLMUQkHW8BhNhamLZlBouyle4aZxaVv+5P4f5bpMM7jxPq6l29oM7Qhr6+6BOO3cyljow9/lWmUzThGdx4ibeyxCY1M81cP5pZ7pVlnl47/ZeNAkvboSNM/CDXwNHj5Nhx4Z4t6GCIGnLAGBjo/Zwf8BFBl0l6B4Pm9luHO+v9N90EQ3G+cynwWqEU33h9lfmKrww6pKJkbmsDdlhWRVaUI2ZR4CYD3xecTYckhqzlqj0cxvVks02KjtKhwWsJuJe2a+QvIJrfyOTYJ+PEvqcnvAGgCUX8flls9rgFrwADJ7GL4XcwHhrY5gQhuwepizqwHvnlUpoJicbBgFy17CAyzXRQYROncBMpEHSZJDhYOUlj+hMrjuxaJIwzJGeNiWW82i+j+eMhr9n7SJ5MG9N5MrYWhJocLubPWWOgkVV2Q8JYJ5i1g=----ATTACHMENT:----ODY3NDY2NTA1MzAzMjYzMyA4Njc2NjA3ODEwNzIyMTU1IDc5MjM3MDAzMTE3MDc2Mzc=