From c73b042044ef26e0d9b7eec2c6ea9db0a74759ef Mon Sep 17 00:00:00 2001 From: Bogdan Scordaliu Date: Tue, 22 Oct 2019 10:54:04 +0200 Subject: [PATCH 1/6] bug symfony#28179 [DomCrawler] Skip disabled fields processing in Form --- src/Symfony/Component/DomCrawler/Form.php | 10 +--------- .../Component/DomCrawler/Tests/FormTest.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Component/DomCrawler/Form.php b/src/Symfony/Component/DomCrawler/Form.php index 87ab31485f39..375ee531c4a0 100644 --- a/src/Symfony/Component/DomCrawler/Form.php +++ b/src/Symfony/Component/DomCrawler/Form.php @@ -89,10 +89,6 @@ public function getValues() { $values = []; foreach ($this->fields->all() as $name => $field) { - if ($field->isDisabled()) { - continue; - } - if (!$field instanceof Field\FileFormField && $field->hasValue()) { $values[$name] = $field->getValue(); } @@ -115,10 +111,6 @@ public function getFiles() $files = []; foreach ($this->fields->all() as $name => $field) { - if ($field->isDisabled()) { - continue; - } - if ($field instanceof Field\FileFormField) { $files[$name] = $field->getValue(); } @@ -463,7 +455,7 @@ private function initialize() private function addField(\DOMElement $node) { - if (!$node->hasAttribute('name') || !$node->getAttribute('name')) { + if (!$node->hasAttribute('name') || !$node->getAttribute('name') || $node->hasAttribute('disabled')) { return; } diff --git a/src/Symfony/Component/DomCrawler/Tests/FormTest.php b/src/Symfony/Component/DomCrawler/Tests/FormTest.php index 504a9bd4251d..50f5a120eaa5 100644 --- a/src/Symfony/Component/DomCrawler/Tests/FormTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/FormTest.php @@ -148,12 +148,12 @@ public function testConstructorHandlesFormValues() public function testMultiValuedFields() { $form = $this->createForm('
- - - - - - + + + + + +
'); @@ -216,10 +216,10 @@ public function provideInitializeValues() [], ], [ - 'takes into account disabled input fields', + 'skips disabled input fields', ' ', - ['foo' => ['InputFormField', 'foo']], + [], ], [ 'appends the submitted button value', From c9072c70efcceb151915cd0909ff819a13228d1c Mon Sep 17 00:00:00 2001 From: Leevi Graham Date: Fri, 25 Oct 2019 21:23:51 +1100 Subject: [PATCH 2/6] Check value isset to avoid PHP notice --- src/Symfony/Component/Console/Style/SymfonyStyle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Style/SymfonyStyle.php b/src/Symfony/Component/Console/Style/SymfonyStyle.php index 4291ada8f6cd..02e9b471b8e6 100644 --- a/src/Symfony/Component/Console/Style/SymfonyStyle.php +++ b/src/Symfony/Component/Console/Style/SymfonyStyle.php @@ -229,7 +229,7 @@ public function choice($question, array $choices, $default = null) { if (null !== $default) { $values = array_flip($choices); - $default = $values[$default]; + $default = isset($values[$default]) ? $values[$default] : $default; } return $this->askQuestion(new ChoiceQuestion($question, $choices, $default)); From 2797867ae95f6c532960078b38315ba59bc2c21f Mon Sep 17 00:00:00 2001 From: Arman Hosseini Date: Thu, 2 Jan 2020 00:53:08 +0330 Subject: [PATCH 3/6] Check non-null type for numeric type $maxAge and $sharedAge can both be zero --- .../FrameworkBundle/Controller/TemplateController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php index f72d556f60b5..52086ef8dd22 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php @@ -75,17 +75,17 @@ public function templateAction($template, $maxAge = null, $sharedAge = null, $pr throw new \LogicException('You can not use the TemplateController if the Templating Component or the Twig Bundle are not available.'); } - if ($maxAge) { + if (null !== $maxAge) { $response->setMaxAge($maxAge); } - if ($sharedAge) { + if (null !== $sharedAge) { $response->setSharedMaxAge($sharedAge); } if ($private) { $response->setPrivate(); - } elseif (false === $private || (null === $private && ($maxAge || $sharedAge))) { + } elseif (false === $private || (null === $private && (null !== $maxAge || null !== $sharedAge))) { $response->setPublic(); } From bdf02c0a7ebd160872116ddb1a15528e2f1ba585 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Tue, 14 Jan 2020 09:16:44 +0100 Subject: [PATCH 4/6] [Yaml][Inline] Fail properly on empty object tag and empty const tag --- src/Symfony/Component/Yaml/Inline.php | 15 ++++++- .../Component/Yaml/Tests/InlineTest.php | 43 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 73aba3cb8b0d..7ad4a64ead96 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -506,7 +506,12 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = [] if ('!php/const' === $key) { $key .= self::parseScalar($mapping, $flags, [':', ' '], $i, false, [], true); - $key = self::evaluateScalar($key, $flags); + if ('!php/const:' === $key && ':' !== $mapping[$i]) { + $key = ''; + --$i; + } else { + $key = self::evaluateScalar($key, $flags); + } } if (':' !== $key && false === $i = strpos($mapping, ':', $i)) { @@ -692,6 +697,10 @@ private static function evaluateScalar($scalar, $flags, $references = []) return null; case 0 === strpos($scalar, '!php/object'): if (self::$objectSupport) { + if (!isset($scalar[12])) { + return false; + } + return unserialize(self::parseScalar(substr($scalar, 12))); } @@ -717,6 +726,10 @@ private static function evaluateScalar($scalar, $flags, $references = []) return null; case 0 === strpos($scalar, '!php/const'): if (self::$constantSupport) { + if (!isset($scalar[11])) { + return ''; + } + $i = 0; if (\defined($const = self::parseScalar(substr($scalar, 11), 0, null, $i, false))) { return \constant($const); diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index 54372d69505b..5b55451e19eb 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -799,4 +799,47 @@ public function getTestsForOctalNumbers() 'negative octal number' => [-28, '-034'], ]; } + + /** + * @dataProvider phpObjectTagWithEmptyValueProvider + */ + public function testPhpObjectWithEmptyValue($expected, $value) + { + $this->assertSame($expected, Inline::parse($value, Yaml::PARSE_OBJECT)); + } + + public function phpObjectTagWithEmptyValueProvider() + { + return [ + [false, '!php/object'], + [false, '!php/object '], + [false, '!php/object '], + [[false], '[!php/object]'], + [[false], '[!php/object ]'], + [[false, 'foo'], '[!php/object , foo]'], + ]; + } + + /** + * @dataProvider phpConstTagWithEmptyValueProvider + */ + public function testPhpConstTagWithEmptyValue($expected, $value) + { + $this->assertSame($expected, Inline::parse($value, Yaml::PARSE_CONSTANT)); + } + + public function phpConstTagWithEmptyValueProvider() + { + return [ + ['', '!php/const'], + ['', '!php/const '], + ['', '!php/const '], + [[''], '[!php/const]'], + [[''], '[!php/const ]'], + [['', 'foo'], '[!php/const , foo]'], + [['' => 'foo'], '{!php/const: foo}'], + [['' => 'foo'], '{!php/const : foo}'], + [['' => 'foo', 'bar' => 'ccc'], '{!php/const : foo, bar: ccc}'], + ]; + } } From 9cbfad5853d29eaaa9e9796c489fcead7a441fd4 Mon Sep 17 00:00:00 2001 From: Signor Pedro <53906348+signor-pedro@users.noreply.github.com> Date: Wed, 29 Jan 2020 11:07:44 +0100 Subject: [PATCH 5/6] [DependencyInjection] #35505 Fix typo in test name Rename testThrowsExceptionWhenAddServiceOnACompiledContainer to testNoExceptionWhenAddServiceOnACompiledContainer. --- .../DependencyInjection/Tests/ContainerBuilderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 53d62a58d214..75b9305ff32d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -1090,7 +1090,7 @@ public function testThrowsExceptionWhenSetServiceOnACompiledContainer() $container->set('a', new \stdClass()); } - public function testThrowsExceptionWhenAddServiceOnACompiledContainer() + public function testNoExceptionWhenAddServiceOnACompiledContainer() { $container = new ContainerBuilder(); $container->compile(); From 6b02362c5b9e1e49cf934aef2d954c1e7d91452a Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Tue, 28 Jan 2020 01:09:27 +0100 Subject: [PATCH 6/6] [Phpunit] Fix running skipped tests expecting only deprecations --- .../Legacy/SymfonyTestsListenerTrait.php | 4 +++ .../OnlyExpectingDeprecationSkippedTest.php | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/Symfony/Bridge/PhpUnit/Tests/OnlyExpectingDeprecationSkippedTest.php diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php index 54c15b67ceed..69bbcfc09eab 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php @@ -222,6 +222,10 @@ public function startTest($test) } } + if (!$test->getTestResultObject()) { + return; + } + $annotations = $Test::parseTestMethodAnnotations(\get_class($test), $test->getName(false)); if (isset($annotations['class']['expectedDeprecation'])) { diff --git a/src/Symfony/Bridge/PhpUnit/Tests/OnlyExpectingDeprecationSkippedTest.php b/src/Symfony/Bridge/PhpUnit/Tests/OnlyExpectingDeprecationSkippedTest.php new file mode 100644 index 000000000000..593e0b4e1434 --- /dev/null +++ b/src/Symfony/Bridge/PhpUnit/Tests/OnlyExpectingDeprecationSkippedTest.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\PhpUnit\Tests; + +use PHPUnit\Framework\TestCase; + +/** + * This test is meant to be skipped. + * + * @requires extension ext-dummy + */ +final class OnlyExpectingDeprecationSkippedTest extends TestCase +{ + /** + * Do not remove this test in the next major versions. + * + * @group legacy + * + * @expectedDeprecation unreachable + */ + public function testExpectingOnlyDeprecations() + { + $this->fail('should never be ran.'); + } +}