From 2a96483ed3a38e14a4203e293a54ea1b4f3edb36 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Sun, 5 Jul 2020 02:19:18 +0100 Subject: [PATCH 1/2] Use ">=" for the "php" requirement --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d9a237e..e5721c6 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": "^7.1.3" + "php": ">=7.1.3" }, "autoload": { "psr-4": { "Symfony\\Component\\OptionsResolver\\": "" }, From 376bd3a02e7946dbf90b01563361b47dde425025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Fri, 10 Jul 2020 11:08:50 +0200 Subject: [PATCH 2/2] [OptionsResolver] Fix force prepend normalizer --- OptionsResolver.php | 1 + Tests/OptionsResolverTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/OptionsResolver.php b/OptionsResolver.php index 3fb3c06..d1aad46 100644 --- a/OptionsResolver.php +++ b/OptionsResolver.php @@ -532,6 +532,7 @@ public function addNormalizer(string $option, \Closure $normalizer, bool $forceP } if ($forcePrepend) { + $this->normalizers[$option] = $this->normalizers[$option] ?? []; array_unshift($this->normalizers[$option], $normalizer); } else { $this->normalizers[$option][] = $normalizer; diff --git a/Tests/OptionsResolverTest.php b/Tests/OptionsResolverTest.php index 8e3c1d3..1fa0e54 100644 --- a/Tests/OptionsResolverTest.php +++ b/Tests/OptionsResolverTest.php @@ -1506,6 +1506,17 @@ public function testForcePrependNormalizerClosure() $this->assertEquals(['foo' => '2nd-normalized-1st-normalized-bar'], $this->resolver->resolve()); } + public function testForcePrependNormalizerForResolverWithoutPreviousNormalizers() + { + // defined by superclass + $this->resolver->setDefault('foo', 'bar'); + $this->resolver->addNormalizer('foo', function (Options $options, $value) { + return '1st-normalized-'.$value; + }, true); + + $this->assertEquals(['foo' => '1st-normalized-bar'], $this->resolver->resolve()); + } + public function testAddNormalizerFailsIfUnknownOption() { $this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');