Skip to content

Commit

Permalink
Merge branch '5.0'
Browse files Browse the repository at this point in the history
* 5.0:
  [Phpunit] Fix running skipped tests expecting only deprecations
  Fix merge
  [Config] dont catch instances of Error
  [HttpClient] fix HttpClientDataCollector when handling canceled responses
  [FrameworkBundle] remove mention of the old Controller class
  [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
chalasr committed Feb 3, 2020
2 parents 5da9cf3 + 5da1bcf commit 12ca646
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .github/patch-types.php
Expand Up @@ -18,6 +18,8 @@
case false !== strpos($file, '/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Article.php'):
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php'):
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadParent.php'):
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/ParseError.php'):
case false !== strpos($file, '/src/Symfony/Component/Debug/Tests/Fixtures/'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Compiler/OptionalServiceClass.php'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/ParentNotExists.php'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/BadClasses/MissingParent.php'):
Expand Down
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 @@ -51,13 +51,13 @@ public function templateAction(string $template, int $maxAge = null, int $shared
$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
Expand Up @@ -410,8 +410,6 @@ public function load(array $configs, ContainerBuilder $container)
->addTag('controller.argument_value_resolver');
$container->registerForAutoconfiguration(AbstractController::class)
->addTag('controller.service_arguments');
$container->registerForAutoconfiguration('Symfony\Bundle\FrameworkBundle\Controller\Controller')
->addTag('controller.service_arguments');
$container->registerForAutoconfiguration(DataCollectorInterface::class)
->addTag('data_collector');
$container->registerForAutoconfiguration(FormTypeInterface::class)
Expand Down
Expand Up @@ -94,6 +94,8 @@ public function isFresh(int $timestamp): bool
}
} catch (\Throwable $e) {
$exists[1] = $e->getMessage();

throw $e;
} finally {
self::$autoloadedClass = $autoloadedClass;
if (!--self::$autoloadLevel) {
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/Config/Tests/Fixtures/ParseError.php
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Component\Config\Tests\Fixtures;

class ParseError
{
// missing closing bracket
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Config\Resource\ClassExistenceResource;
use Symfony\Component\Config\Tests\Fixtures\BadFileName;
use Symfony\Component\Config\Tests\Fixtures\BadParent;
use Symfony\Component\Config\Tests\Fixtures\ParseError;
use Symfony\Component\Config\Tests\Fixtures\Resource\ConditionalClass;

class ClassExistenceResourceTest extends TestCase
Expand Down Expand Up @@ -115,4 +116,12 @@ public function testConditionalClass()

$this->assertFalse($res->isFresh(0));
}

public function testParseError()
{
$this->expectException('ParseError');

$res = new ClassExistenceResource(ParseError::class, false);
$res->isFresh(0);
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Style/SymfonyStyle.php
Expand Up @@ -290,7 +290,7 @@ public function choice(string $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 @@ -467,7 +459,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
Expand Up @@ -115,7 +115,7 @@ private function collectOnClient(TraceableHttpClient $client): array

unset($info['filetime'], $info['http_code'], $info['ssl_verify_result'], $info['content_type']);

if ($trace['method'] === $info['http_method']) {
if (($info['http_method'] ?? null) === $trace['method']) {
unset($info['http_method']);
}

Expand Down
Expand Up @@ -51,9 +51,6 @@ public function process(ContainerBuilder $container)
}
}
if (!$reason) {
// Deprecated since Symfony 4.1. See Symfony\Component\HttpKernel\Controller\ContainerControllerResolver
$controllers[$id.':'.$action] = $argumentRef;

if ('__invoke' === $action) {
$controllers[$id] = $argumentRef;
}
Expand Down
Expand Up @@ -49,7 +49,7 @@ public function testProcess()

$controllers = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);

$this->assertSame(['c1::fooAction', 'c1:fooAction'], array_keys($controllers));
$this->assertSame(['c1::fooAction'], array_keys($controllers));
$this->assertSame(['bar'], array_keys($container->getDefinition((string) $controllers['c1::fooAction']->getValues()[0])->getArgument(0)));

$expectedLog = [
Expand All @@ -73,7 +73,7 @@ public function testInvoke()
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);

$this->assertEquals(
['invokable::__invoke', 'invokable:__invoke', 'invokable'],
['invokable::__invoke', 'invokable'],
array_keys($container->getDefinition((string) $resolver->getArgument(0))->getArgument(0))
);
}
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 12ca646

Please sign in to comment.