Skip to content

Commit

Permalink
Merge branch '3.4' into 4.4
Browse files Browse the repository at this point in the history
* 3.4:
  [Phpunit] Fix running skipped tests expecting only deprecations
  [DependencyInjection] #35505 Fix typo in test name
  [Yaml][Inline] Fail properly on empty object tag and empty const tag
  Check non-null type for numeric type
  Check value isset to avoid PHP notice
  bug #28179 [DomCrawler] Skip disabled fields processing in Form
  • Loading branch information
nicolas-grekas committed Feb 3, 2020
2 parents 774a161 + af46fd6 commit ed7bb82
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 22 deletions.
Expand Up @@ -211,6 +211,10 @@ public function startTest($test)
}
}

if (!$test->getTestResultObject()) {
return;
}

$annotations = Test::parseTestMethodAnnotations(\get_class($test), $test->getName(false));

if (isset($annotations['class']['expectedDeprecation'])) {
Expand Down
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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.');
}
}
Expand Up @@ -55,17 +55,17 @@ public function templateAction(string $template, int $maxAge = null, int $shared
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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Style/SymfonyStyle.php
Expand Up @@ -295,7 +295,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));
Expand Down
Expand Up @@ -1097,7 +1097,7 @@ public function testThrowsExceptionWhenSetServiceOnACompiledContainer()
$container->set('a', new \stdClass());
}

public function testThrowsExceptionWhenAddServiceOnACompiledContainer()
public function testNoExceptionWhenAddServiceOnACompiledContainer()
{
$container = new ContainerBuilder();
$container->compile();
Expand Down
10 changes: 1 addition & 9 deletions src/Symfony/Component/DomCrawler/Form.php
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -473,7 +465,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;
}

Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/DomCrawler/Tests/FormTest.php
Expand Up @@ -158,12 +158,12 @@ public function testConstructorHandlesFormValues()
public function testMultiValuedFields()
{
$form = $this->createForm('<form>
<input type="text" name="foo[4]" value="foo" disabled="disabled" />
<input type="text" name="foo" value="foo" disabled="disabled" />
<input type="text" name="foo[2]" value="foo" disabled="disabled" />
<input type="text" name="foo[]" value="foo" disabled="disabled" />
<input type="text" name="bar[foo][]" value="foo" disabled="disabled" />
<input type="text" name="bar[foo][foobar]" value="foo" disabled="disabled" />
<input type="text" name="foo[4]" value="foo" />
<input type="text" name="foo" value="foo" />
<input type="text" name="foo[2]" value="foo" />
<input type="text" name="foo[]" value="foo" />
<input type="text" name="bar[foo][]" value="foo" />
<input type="text" name="bar[foo][foobar]" value="foo" />
<input type="submit" />
</form>
');
Expand Down Expand Up @@ -226,10 +226,10 @@ public function provideInitializeValues()
[],
],
[
'takes into account disabled input fields',
'skips disabled input fields',
'<input type="text" name="foo" value="foo" disabled="disabled" />
<input type="submit" />',
['foo' => ['InputFormField', 'foo']],
[],
],
[
'appends the submitted button value',
Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/Yaml/Inline.php
Expand Up @@ -589,6 +589,10 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere
return substr($scalar, 2);
case 0 === strpos($scalar, '!php/object'):
if (self::$objectSupport) {
if (!isset($scalar[12])) {
return false;
}

return unserialize(self::parseScalar(substr($scalar, 12)));
}

Expand All @@ -599,6 +603,10 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere
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);
Expand Down
43 changes: 43 additions & 0 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Expand Up @@ -738,6 +738,49 @@ public function getTestsForOctalNumbers()
];
}

/**
* @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}'],
];
}

/**
* @dataProvider unquotedExclamationMarkThrowsProvider
*/
Expand Down

0 comments on commit ed7bb82

Please sign in to comment.