8000 Merge branch '4.0' · symfony/symfony@87adf25 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 87adf25

Browse files
Merge branch '4.0'
* 4.0: Have weak_vendors ignore deprecations from outside [HttpFoundation] fixed return type of method HeaderBag::get [HttpFoundation] Added "resource" type on Request::create docblock [Console] Fix using finally where the catch can also fail [Process] Skip environment variables with false value in Process Revert "bug #25789 Enableable ArrayNodeDefinition is disabled for empty configuration (kejwmen)" Formatting fix in upgrade 3.0 document don't split lines on carriage returns when dumping trim spaces from unquoted scalar values Revert "bug #25851 [Validator] Conflict with egulias/email-validator 2.0 (emodric)" [DI] compilation perf tweak [Validator] Conflict with egulias/email-validator 2.0 [Validator] add missing parent isset and add test
2 parents f456b0f + ee04e5b commit 87adf25

File tree

23 files changed

+156
-66
lines changed

23 files changed

+156
-66
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ public static function register($mode = 0)
7575
}
7676
}
7777
}
78-
$path = realpath($path) ?: $path;
78+
$realPath = realpath($path);
79+
if (false === $realPath && '-' !== $path && 'Standard input code' !== $path) {
80+
return true;
81+
}
7982
foreach ($vendors as $vendor) {
80-
if (0 === strpos($path, $vendor) && false !== strpbrk(substr($path, strlen($vendor), 1), '/'.DIRECTORY_SEPARATOR)) {
83+
if (0 === strpos($realPath, $vendor) && false !== strpbrk(substr($realPath, strlen($vendor), 1), '/'.DIRECTORY_SEPARATOR)) {
8184
return true;
8285
}
8386
}
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
@trigger_error('I come from… afar! :D', E_USER_DEPRECATED);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
$phar = new Phar(__DIR__.DIRECTORY_SEPARATOR.'deprecation.phar', 0, 'deprecation.phar');
4+
$phar->buildFromDirectory(__DIR__.DIRECTORY_SEPARATOR.'deprecation');
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Test DeprecationErrorHandler in weak vendors mode on eval()'d deprecation
3+
--FILE--
4+
<?php
5+
6+
putenv('SYMFONY_DEPRECATIONS_HELPER=weak_vendors');
7+
putenv('ANSICON');
8+
putenv('ConEmuANSI');
9+
putenv('TERM');
10+
11+
$vendor = __DIR__;
12+
while (!file_exists($vendor.'/vendor')) {
13+
$vendor = dirname($vendor);
14+
}
15+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
16+
require PHPUNIT_COMPOSER_INSTALL;
17+
require_once __DIR__.'/../../bootstrap.php';
18+
eval("@trigger_error('who knows where I come from?', E_USER_DEPRECATED);")
19+
20+
?>
21+
--EXPECTF--
22+
23+
Other deprecation notices (1)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Test DeprecationErrorHandler in weak vendors mode on eval()'d deprecation
3+
The phar can be regenerated by running php src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/generate_phar.php
4+
--FILE--
5+
<?php
6+
7+
putenv('SYMFONY_DEPRECATIONS_HELPER=weak_vendors');
8+
putenv('ANSICON');
9+
putenv('ConEmuANSI');
10+
putenv('TERM');
11+
12+
$vendor = __DIR__;
13+
while (!file_exists($vendor.'/vendor')) {
14+
$vendor = dirname($vendor);
15+
}
16+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
17+
require PHPUNIT_COMPOSER_INSTALL;
18+
require_once __DIR__.'/../../bootstrap.php';
19+
\Phar::loadPhar(__DIR__.'/deprecation.phar', 'deprecation.phar');
20+
include 'phar://deprecation.phar/deprecation.php';
21+
22+
?>
23+
--EXPECTF--
24+
25+
Other deprecation notices (1)

src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,7 @@ public function canBeEnabled()
283283
->beforeNormalization()
284284
->ifArray()
285285
->then(function ($v) {
286-
if (!isset($v['enabled'])) {
287-
$v['enabled'] = !empty($v);
288-
}
286+
$v['enabled'] = isset($v['enabled']) ? $v['enabled'] : true;
289287

290288
return $v;
291289
})

src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,6 @@ public function testCanBeDisabled()
208208
$this->assertTrue($this->getField($enabledNode, 'defaultValue'));
209209
}
210210

211-
public function testEnableableNodeIsDisabledForEmptyConfigurationWhenNormalized()
212-
{
213-
$config = array();
214-
215-
$node = new ArrayNodeDefinition('root');
216-
$node->canBeEnabled();
217-
218-
$this->assertEquals(
219-
array('enabled' => false),
220-
$node->getNode()->normalize($config),
221-
'An enableable node is disabled by default'
222-
);
223-
}
224-
225211
public function testIgnoreExtraKeys()
226212
{
227213
$node = new ArrayNodeDefinition('root');
@@ -297,7 +283,6 @@ public function getEnableableNodeFixtures()
297283
array(array('enabled' => true, 'foo' => 'baz'), array(array('foo' => 'baz')), 'any configuration enables an enableable node'),
298284
array(array('enabled' => false, 'foo' => 'baz'), array(array(' 433 ;foo' => 'baz', 'enabled' => false)), 'An enableable node can be disabled'),
299285
array(array('enabled' => false, 'foo' => 'bar'), array(false), 'false disables an enableable node'),
300-
array(array('enabled' => false, 'foo' => 'bar'), array(), 'enableable node is disabled by default'),
301286
);
302287
}
303288

src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Config\Tests\Definition\Builder;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\Config\Definition\Processor;
1615
use Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder as CustomNodeBuilder;
1716
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1817

@@ -133,24 +132,6 @@ public function testDefinitionExampleGetsTransferredToNode()
133132
$this->assertEquals('example', $children['child']->getExample());
134133
}
135134

136-
public function testRootNodeThatCanBeEnabledIsDisabledByDefault()
137-
{
138-
$builder = new TreeBuilder();
139-
140-
$builder->root('test')
141-
->canBeEnabled();
142-
143-
$tree = $builder->buildTree();
144-
$children = $tree->getChildren();
145-
146-
$this->assertFalse($children['enabled']->getDefaultValue());
147-
148-
$processor = new Processor();
149-
$result = $processor->process($tree, array());
150-
151-
$this->assertEquals(array('enabled' => false), $result);
152-
}
153-
154135
public function testDefaultPathSeparatorIsDot()
155136
{
156137
$builder = new TreeBuilder();

src/Symfony/Component/Console/Application.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
874874
}
875875

876876
$event = new ConsoleCommandEvent($command, $input, $output);
877+
$e = null;
877878

878879
try {
879880
$this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
@@ -886,13 +887,18 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
886887
} catch (\Throwable $e) {
887888
$event = new ConsoleErrorEvent($input, $output, $e, $command);
888889
$this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
890+
$e = $event->getError();
889891

890-
if (0 !== $exitCode = $event->getExitCode()) {
891-
throw $event->getError();
892+
if (0 === $exitCode = $event->getExitCode()) {
893+
$e = null;
892894
}
893-
} finally {
894-
$event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
895-
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
895+
}
896+
897+
$event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
898+
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
899+
900+
if (null !== $e) {
901+
throw $e;
896902
}
897903

898904
return $event->getExitCode();

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,34 @@ public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEn
15531553
}
15541554
}
15551555

1556+
/**
1557+
* @expectedException \RuntimeException
1558+
* @expectedExceptionMessage foo
1559+
*/
1560+
public function testThrowingErrorListener()
1561+
{
1562+
$dispatcher = $this->getDispatcher();
1563+
$dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) {
1564+
throw new \RuntimeException('foo');
1565+
});
1566+
1567+
$dispatcher->addListener('console.command', function () {
1568+
throw new \RuntimeException('bar');
1569+
});
1570+
1571+
$application = new Application();
1572+
$application->setDispatcher($dispatcher);
1573+
$application->setAutoExit(false);
1574+
$application->setCatchExceptions(false);
1575+
1576+
$application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {
1577+
$output->write('foo.');
1578+
});
1579+
1580+
$tester = new ApplicationTester($application);
1581+
$tester->run(array('command' => 'foo'));
1582+
}
1583+
15561584
protected function tearDown()
15571585
{
15581586
putenv('SHELL_VERBOSITY');

src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function process(ContainerBuilder $container)
5252
*/
5353
protected function processValue($value, $isRoot = false)
5454
{
55-
if (is_array($value)) {
55+
if (\is_array($value)) {
5656
foreach ($value as $k => $v) {
5757
if ($isRoot) {
5858
$this->currentId = $k;

src/Symfony/Component/HttpFoundation/HeaderBag.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ public function add(array $headers)
101101
/**
102102
* Returns a header value by name.
103103
*
104-
* @param string $key The header name
105-
* @param mixed $default The default value
106-
* @param bool $first Whether to return the first value or all header values
104+
* @param string $key The header name
105+
* @param string|string[] $default The default value
106+
* @param bool $first Whether to return the first value or all header values
107107
*
108-
* @return string|array The first header value if $first is true, an array of values otherwise
108+
* @return string|string[] The first header value or default value if $first is true, an array of values otherwise
109109
*/
110110
public function get($key, $default = null, $first = true)
111111
{
@@ -130,9 +130,9 @@ public function get($key, $default = null, $first = true)
130130
/**
131131
* Sets a header by name.
132132
*
133-
* @param string $key The key
134-
* @param string|array $values The value or an array of values
135-
* @param bool $replace Whether to replace the actual value or not (true by default)
133+
* @param string $key The key
134+
* @param string|string[] $values The value or an array of values
135+
* @param bool $replace Whether to replace the actual value or not (true by default)
136136
*/
137137
public function set($key, $values, $replace = true)
138138
{

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,13 @@ public static function createFromGlobals()
296296
* The information contained in the URI always take precedence
297297
* over the other information (server and parameters).
298298
*
299-
* @param string $uri The URI
300-
* @param string $method The HTTP method
301-
* @param array $parameters The query (GET) or request (POST) parameters
302-
* @param array $cookies The request cookies ($_COOKIE)
303-
* @param array $files The request files ($_FILES)
304-
* @param array $server The server parameters ($_SERVER)
305-
* @param string $content The raw body data
299+
* @param string $uri The URI
300+
* @param string $method The HTTP method
301+
* @param array $parameters The query (GET) or request (POST) parameters
302+
* @param array $cookies The request cookies ($_COOKIE)
303+
* @param array $files The request files ($_FILES)
304+
* @param array $server The server parameters ($_SERVER)
305+
* @param string|resource $content The raw body data
306306
*
307307
* @return static
308308
*/

src/Symfony/Component/Process/Process.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ public function start(callable $callback = null, array $env = array())
291291

292292
$envPairs = array();
293293
foreach ($env as $k => $v) {
294-
$envPairs[] = $k.'='.$v;
294+
if (false !== $v) {
295+
$envPairs[] = $k.'='.$v;
296+
}
295297
}
296298

297299
if (!is_dir($this->cwd)) {

src/Symfony/Component/Validator/Constraint.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,16 @@ public function __get($option)
214214
throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, get_class($this)), array($option));
215215
}
216216

217+
/**
218+
* @param string $option The option name
219+
*
220+
* @return bool
221+
*/
222+
public function __isset($option)
223+
{
224+
return 'groups' === $option;
225+
}
226+
217227
/**
218228
* Adds the given group if this constraint is in the Default group.
219229
*

src/Symfony/Component/Validator/Tests/Constraints/FileTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ public function testMaxSize($maxSize, $bytes, $binaryFormat)
2626

2727
$this->assertSame($bytes, $file->maxSize);
2828
$this->assertSame($binaryFormat, $file->binaryFormat);
29+
$this->assertTrue($file->__isset('maxSize'));
30+
}
31+
32+
public function testMagicIsset()
33+
{
34+
$file = new File(array('maxSize' => 1));
35+
36+
$this->assertTrue($file->__isset('maxSize'));
37+
$this->assertTrue($file->__isset('groups'));
38+
$this->assertFalse($file->__isset('toto'));
2939
}
3040

3141
/**

src/Symfony/Component/Yaml/Dumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0):
6262
$dumpAsMap = Inline::isHash($input);
6363

6464
foreach ($input as $key => $value) {
65-
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n")) {
65+
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n") && false === strpos($value, "\r\n")) {
6666
$output .= sprintf("%s%s%s |\n", $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', '');
6767

6868
foreach (preg_split('/\n|\r\n/', $value) as $row) {

src/Symfony/Component/Yaml/Inline.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ public static function parseScalar(string $scalar, int $flags = 0, array $delimi
286286
} elseif (Parser::preg_match('/^(.*?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
287287
$output = $match[1];
288288
$i += strlen($output);
289+
$output = trim($output);
289290
} else {
290291
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $scalar), self::$parsedLineNumber + 1, null, self::$parsedFilename);
291292
}

src/Symfony/Component/Yaml/Tests/DumperTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ public function testDumpMultiLineStringAsScalarBlock()
377377
$data = array(
378378
'data' => array(
379379
'single_line' => 'foo bar baz',
380-
'multi_line' => "foo\nline with trailing spaces:\n \nbar\r\ninteger like line:\n123456789\nempty line:\n\nbaz",
380+
'multi_line' => "foo\nline with trailing spaces:\n \nbar\ninteger like line:\n123456789\nempty line:\n\nbaz",
381+
'multi_line_with_carriage_return' => "foo\nbar\r\nbaz",
381382
'nested_inlined_multi_line_string' => array(
382383
'inlined_multi_line' => "foo\nbar\r\nempty line:\n\nbaz",
383384
),
@@ -387,6 +388,11 @@ public function testDumpMultiLineStringAsScalarBlock()
387388
$this->assertSame(file_get_contents(__DIR__.'/Fixtures/multiple_lines_as_literal_block.yml'), $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
388389
}
389390

391+
public function testCarriageReturnIsMaintainedWhenDumpingAsMultiLineLiteralBlock()
392+
{
393+
$this->assertSame("- \"a\\r\\nb\\nc\"\n", $this->dumper->dump(array("a\r\nb\nc"), 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
394+
}
395+
390396
/**
391397
* @expectedException \InvalidArgumentException
392398
* @expectedExceptionMessage The indentation must be greater than zero

src/Symfony/Component/Yaml/Tests/Fixtures/multiple_lines_as_literal_block.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ data:
1010
empty line:
1111
1212
baz
13+
multi_line_with_carriage_return: "foo\nbar\r\nbaz"
1314
nested_inlined_multi_line_string: { inlined_multi_line: "foo\nbar\r\nempty line:\n\nbaz" }

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ public function testParseUnquotedScalarStartingWithReservedIndicator($indicator)
252252
{
253253
if (method_exists($this, 'expectExceptionMessage')) {
254254
$this->expectException(ParseException::class);
255-
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
255+
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
256256
} else {
257-
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
257+
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
258258
}
259259

260260
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
@@ -272,9 +272,9 @@ public function testParseUnquotedScalarStartingWithScalarIndicator($indicator)
272272
{
273273
if (method_exists($this, 'expectExceptionMessage')) {
274274
$this->expectException(ParseException::class);
275-
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
275+
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
276276
} else {
277-
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
277+
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
278278
}
279279

280280
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,10 @@ public function taggedValuesProvider()
16021602
- !quz {foo: bar, quz: !bar {one: bar}}
16031603
YAML
16041604
),
1605+
'spaces-around-tag-value-in-sequence' => array(
1606+
array(new TaggedValue('foo', 'bar')),
1607+
'[ !foo bar ]',
1608+
),
16051609
);
16061610
}
16071611

0 commit comments

Comments
 (0)
0