From b28839b7bcf9833ca821684d3781d0636d099b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Parmentier?= Date: Tue, 1 Aug 2017 17:22:43 +0200 Subject: [PATCH 1/8] Add a DateInterval normalizer --- .../FrameworkExtension.php | 8 + .../FrameworkExtensionTest.php | 16 ++ .../Normalizer/DateIntervalNormalizer.php | 106 ++++++++++++ .../Normalizer/DateIntervalNormalizerTest.php | 160 ++++++++++++++++++ 4 files changed, 290 insertions(+) create mode 100644 src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php create mode 100644 src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index ea6dec7fd6bd1..db7a174330ae2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -67,6 +67,7 @@ use Symfony\Component\Serializer\Encoder\YamlEncoder; use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory; use Symfony\Component\Serializer\Normalizer\DataUriNormalizer; +use Symfony\Component\Serializer\Normalizer\DateIntervalNormalizer; use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer; @@ -1522,6 +1523,13 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder $definition->addTag('serializer.normalizer', array('priority' => -920)); } + if (class_exists(DateIntervalNormalizer::class)) { + // Run after serializer.normalizer.object + $definition = $container->register('serializer.normalizer.dateinterval', DateIntervalNormalizer::class); + $definition->setPublic(false); + $definition->addTag('serializer.normalizer', array('priority' => -915)); + } + if (class_exists('Symfony\Component\Serializer\Normalizer\DateTimeNormalizer')) { // Run before serializer.normalizer.object $definition = $container->register('serializer.normalizer.datetime', DateTimeNormalizer::class); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 991eda1ea6ac6..67be87baa8a3b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -34,6 +34,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\PropertyAccess\PropertyAccessor; use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Serializer\Normalizer\DateIntervalNormalizer; use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory; use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader; @@ -776,6 +777,21 @@ public function testDataUriNormalizerRegistered() $this->assertEquals(-920, $tag[0]['priority']); } + public function testDateIntervalNormalizerRegistered() + { + if (!class_exists(DateIntervalNormalizer::class)) { + $this->markTestSkipped('The DateIntervalNormalizer has been introduced in the Serializer Component version 3.4.'); + } + + $container = $this->createContainerFromFile('full'); + + $definition = $container->getDefinition('serializer.normalizer.dateinterval'); + $tag = $definition->getTag('serializer.normalizer'); + + $this->assertEquals(DateIntervalNormalizer::class, $definition->getClass()); + $this->assertEquals(-915, $tag[0]['priority']); + } + public function testDateTimeNormalizerRegistered() { if (!class_exists('Symfony\Component\Serializer\Normalizer\DateTimeNormalizer')) { diff --git a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php new file mode 100644 index 0000000000000..ab0de6af4e714 --- /dev/null +++ b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php @@ -0,0 +1,106 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Serializer\Normalizer; + +use Symfony\Component\Serializer\Exception\InvalidArgumentException; +use Symfony\Component\Serializer\Exception\UnexpectedValueException; + +/** + * Normalizes an instance of {@see \DateInterval} to an interval string. + * Denormalizes an interval string to an instance of {@see \DateInterval}. + * + * @author Jérôme Parmentier + */ +class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterface +{ + const FORMAT_KEY = 'dateinterval_format'; + + /** + * @var string + */ + private $format; + + /** + * @param string $format + */ + public function __construct($format = 'P%yY%mM%dDT%hH%iM%sS') + { + $this->format = $format; + } + + /** + * {@inheritdoc} + * + * @throws InvalidArgumentException + */ + public function normalize($object, $format = null, array $context = array()) + { + if (!$object instanceof \DateInterval) { + throw new InvalidArgumentException('The object must be an instance of "\DateInterval".'); + } + + $dateIntervalFormat = isset($context[self::FORMAT_KEY]) ? $context[self::FORMAT_KEY] : $this->format; + + return $object->format($dateIntervalFormat); + } + + /** + * {@inheritdoc} + */ + public function supportsNormalization($data, $format = null) + { + return $data instanceof \DateInterval; + } + + /** + * {@inheritdoc} + * + * @throws InvalidArgumentException + * @throws UnexpectedValueException + */ + public function denormalize($data, $class, $format = null, array $context = array()) + { + if (!is_string($data)) { + throw new InvalidArgumentException('Data expected to be a string, '.gettype($data).' given.'); + } + + if (!$this->isISO8601($data)) { + throw new UnexpectedValueException('Non ISO 8601 interval strings are not supported yet.'); + } + + $dateIntervalFormat = isset($context[self::FORMAT_KEY]) ? $context[self::FORMAT_KEY] : $this->format; + + $valuePattern = '/^'.preg_replace('/%([yYmMdDhHiIsSwW])(\w)/', '(?P<$1>\d+)$2', $dateIntervalFormat).'$/'; + if (!preg_match($valuePattern, $data)) { + throw new UnexpectedValueException(sprintf('Value "%s" contains intervals not accepted by format "%s".', $data, $dateIntervalFormat)); + } + + try { + return new \DateInterval($data); + } catch (\Exception $e) { + throw new UnexpectedValueException($e->getMessage(), $e->getCode(), $e); + } + } + + /** + * {@inheritdoc} + */ + public function supportsDenormalization($data, $type, $format = null) + { + return $type === \DateInterval::class; + } + + private function isISO8601($string) + { + return preg_match('/^P(?=\w*(?:\d|%\w))(?:\d+Y|%[yY]Y)?(?:\d+M|%[mM]M)?(?:(?:\d+D|%[dD]D)|(?:\d+W|%[wW]W))?(?:T(?:\d+H|[hH]H)?(?:\d+M|[iI]M)?(?:\d+S|[sS]S)?)?$/', $string); + } +} diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php new file mode 100644 index 0000000000000..feb6bad934aad --- /dev/null +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php @@ -0,0 +1,160 @@ + + */ +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 dataProviderDate() + { + $data = array( + array( + '%y years %m months %d days %h hours %i minutes %s seconds', + '10 years 2 months 3 days 16 hours 5 minutes 6 seconds', + 'P10Y2M3DT16H5M6S', + ), + array( + '%y years %m months %d days %h hours %i minutes', + '10 years 2 months 3 days 16 hours 5 minutes', + 'P10Y2M3DT16H5M', + ), + array('%y years %m months %d days %h hours', '10 years 2 months 3 days 16 hours', 'P10Y2M3DT16H'), + array('%y years %m months %d days', '10 years 2 months 3 days', 'P10Y2M3D'), + array('%y years %m months', '10 years 2 months', 'P10Y2M'), + array('%y year', '1 year', 'P1Y'), + ); + + 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); + } + + /** + * @dataProvider dataProviderDate + * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException + * @expectedExceptionMessage Non ISO 8601 interval strings are not supported yet. + */ + public function testDenormalizeNonISO8601IntervalStringThrowsException($format, $input, $output) + { + $this->assertEquals(new \DateInterval($output), $this->normalizer->denormalize($input, \DateInterval::class, null, array(DateIntervalNormalizer::FORMAT_KEY => $format))); + } + + /** + * @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 => 'P10Y2M3D')); + } + + 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')); + } +} From e86f5a1ce1a20a8796231cb0d11a8a6cfd1d2db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Parmentier?= Date: Tue, 1 Aug 2017 18:02:54 +0200 Subject: [PATCH 2/8] Fix wrong format in tests --- .../Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php index feb6bad934aad..2c5e343a14eac 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php @@ -150,7 +150,7 @@ public function testDenormalizeInvalidDataThrowsException() */ public function testDenormalizeFormatMismatchThrowsException() { - $this->normalizer->denormalize('P00Y00M00DT00H00M00S', \DateInterval::class, null, array(DateIntervalNormalizer::FORMAT_KEY => 'P10Y2M3D')); + $this->normalizer->denormalize('P00Y00M00DT00H00M00S', \DateInterval::class, null, array(DateIntervalNormalizer::FORMAT_KEY => 'P%yY%mM%dD')); } private function assertDateIntervalEquals(\DateInterval $expected, \DateInterval $actual) From 643ea739340c9c3b10a8d0a6c10e70224e53cd3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Parmentier?= Date: Wed, 2 Aug 2017 14:18:22 +0200 Subject: [PATCH 3/8] Fix wrong comments --- .../FrameworkBundle/DependencyInjection/FrameworkExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index db7a174330ae2..937fdc5dcb43c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1524,7 +1524,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder } if (class_exists(DateIntervalNormalizer::class)) { - // Run after serializer.normalizer.object + // Run before serializer.normalizer.object $definition = $container->register('serializer.normalizer.dateinterval', DateIntervalNormalizer::class); $definition->setPublic(false); $definition->addTag('serializer.normalizer', array('priority' => -915)); From 71e8fa7a7c6f0589d994ef7dcbac0cbc15dafa52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Parmentier?= Date: Mon, 14 Aug 2017 00:54:36 +0200 Subject: [PATCH 4/8] Update non ISO 8601 interval string exception message + tests --- .../Normalizer/DateIntervalNormalizer.php | 2 +- .../Normalizer/DateIntervalNormalizerTest.php | 29 ++----------------- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php index ab0de6af4e714..0d75df591b9c8 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php @@ -74,7 +74,7 @@ public function denormalize($data, $class, $format = null, array $context = arra } if (!$this->isISO8601($data)) { - throw new UnexpectedValueException('Non ISO 8601 interval strings are not supported yet.'); + throw new UnexpectedValueException('Expected a valid ISO 8601 interval string.'); } $dateIntervalFormat = isset($context[self::FORMAT_KEY]) ? $context[self::FORMAT_KEY] : $this->format; diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php index 2c5e343a14eac..f6dc6c2475e53 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php @@ -34,28 +34,6 @@ public function dataProviderISO() return $data; } - public function dataProviderDate() - { - $data = array( - array( - '%y years %m months %d days %h hours %i minutes %s seconds', - '10 years 2 months 3 days 16 hours 5 minutes 6 seconds', - 'P10Y2M3DT16H5M6S', - ), - array( - '%y years %m months %d days %h hours %i minutes', - '10 years 2 months 3 days 16 hours 5 minutes', - 'P10Y2M3DT16H5M', - ), - array('%y years %m months %d days %h hours', '10 years 2 months 3 days 16 hours', 'P10Y2M3DT16H'), - array('%y years %m months %d days', '10 years 2 months 3 days', 'P10Y2M3D'), - array('%y years %m months', '10 years 2 months', 'P10Y2M'), - array('%y year', '1 year', 'P1Y'), - ); - - return $data; - } - public function testSupportsNormalization() { $this->assertTrue($this->normalizer->supportsNormalization(new \DateInterval('P00Y00M00DT00H00M00S'))); @@ -128,13 +106,12 @@ public function testDenormalizeExpectsString() } /** - * @dataProvider dataProviderDate * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException - * @expectedExceptionMessage Non ISO 8601 interval strings are not supported yet. + * @expectedExceptionMessage Expected a valid ISO 8601 interval string. */ - public function testDenormalizeNonISO8601IntervalStringThrowsException($format, $input, $output) + public function testDenormalizeNonISO8601IntervalStringThrowsException() { - $this->assertEquals(new \DateInterval($output), $this->normalizer->denormalize($input, \DateInterval::class, null, array(DateIntervalNormalizer::FORMAT_KEY => $format))); + $this->normalizer->denormalize('10 years 2 months 3 days', \DateInterval::class, null); } /** From 2d23e5cdc38bcd9215f3d5cfe1cf4ca808e5c40d Mon Sep 17 00:00:00 2001 From: Lctrs Date: Fri, 18 Aug 2017 13:52:22 +0200 Subject: [PATCH 5/8] Switch to sprintf() --- .../Component/Serializer/Normalizer/DateIntervalNormalizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php index 0d75df591b9c8..0fc54b567a8d0 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php @@ -70,7 +70,7 @@ public function supportsNormalization($data, $format = null) public function denormalize($data, $class, $format = null, array $context = array()) { if (!is_string($data)) { - throw new InvalidArgumentException('Data expected to be a string, '.gettype($data).' given.'); + throw new InvalidArgumentException(sprintf('Data expected to be a string, %s given.', gettype($data))); } if (!$this->isISO8601($data)) { From ec7f37fcb35e3516b71f466f75b02de46b694148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Parmentier?= Date: Thu, 31 Aug 2017 13:43:06 +0200 Subject: [PATCH 6/8] Update CHANGELOG.md --- src/Symfony/Component/Serializer/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/Serializer/CHANGELOG.md b/src/Symfony/Component/Serializer/CHANGELOG.md index 2e10bd469bab4..ef59f22499264 100644 --- a/src/Symfony/Component/Serializer/CHANGELOG.md +++ b/src/Symfony/Component/Serializer/CHANGELOG.md @@ -6,6 +6,7 @@ CHANGELOG * added `AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT` context option to disable throwing an `UnexpectedValueException` on a type mismatch + * added support for serializing `DateInterval` objects 3.3.0 ----- From 36acaf07665088c08b6037a12e9327014b257a0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Parmentier?= Date: Thu, 14 Sep 2017 17:11:10 +0200 Subject: [PATCH 7/8] CS --- .../DependencyInjection/FrameworkExtension.php | 4 ++-- .../Tests/DependencyInjection/FrameworkExtensionTest.php | 1 + .../Serializer/Normalizer/DateIntervalNormalizer.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 937fdc5dcb43c..2348a2df79448 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -632,9 +632,9 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $ $transitions = array(); foreach ($workflow['transitions'] as $transition) { - if ($type === 'workflow') { + if ('workflow' === $type) { $transitions[] = new Definition(Workflow\Transition::class, array($transition['name'], $transition['from'], $transition['to'])); - } elseif ($type === 'state_machine') { + } elseif ('state_machine' === $type) { foreach ($transition['from'] as $from) { foreach ($transition['to'] as $to) { $transitions[] = new Definition(Workflow\Transition::class, array($transition['name'], $from, $to)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 67be87baa8a3b..e32db4097da64 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -1104,6 +1104,7 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con if (ChainAdapter::class === $parentDefinition->getClass()) { break; } + // no break case 'cache.adapter.filesystem': $this->assertSame(FilesystemAdapter::class, $parentDefinition->getClass()); break; diff --git a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php index 0fc54b567a8d0..3628cd670b499 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php @@ -96,7 +96,7 @@ public function denormalize($data, $class, $format = null, array $context = arra */ public function supportsDenormalization($data, $type, $format = null) { - return $type === \DateInterval::class; + return \DateInterval::class === $type; } private function isISO8601($string) From db7e9ccecb471c7940a2d5119a47eefd70b26373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Parmentier?= Date: Thu, 14 Sep 2017 18:23:30 +0200 Subject: [PATCH 8/8] Partially revert previous commit --- .../DependencyInjection/FrameworkExtension.php | 4 ++-- .../Tests/DependencyInjection/FrameworkExtensionTest.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 2348a2df79448..937fdc5dcb43c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -632,9 +632,9 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $ $transitions = array(); foreach ($workflow['transitions'] as $transition) { - if ('workflow' === $type) { + if ($type === 'workflow') { $transitions[] = new Definition(Workflow\Transition::class, array($transition['name'], $transition['from'], $transition['to'])); - } elseif ('state_machine' === $type) { + } elseif ($type === 'state_machine') { foreach ($transition['from'] as $from) { foreach ($transition['to'] as $to) { $transitions[] = new Definition(Workflow\Transition::class, array($transition['name'], $from, $to)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index e32db4097da64..67be87baa8a3b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -1104,7 +1104,6 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con if (ChainAdapter::class === $parentDefinition->getClass()) { break; } - // no break case 'cache.adapter.filesystem': $this->assertSame(FilesystemAdapter::class, $parentDefinition->getClass()); break;