Skip to content

Commit b75755c

Browse files
Merge branch '2.7' into 2.8
* 2.7: [Config] Fix enum default value in Yaml dumper Finnish translation fix [CssSelector] Optimize regexs matching simple selectors Fix the phpdoc in the CssSelector TranslatorInterface [Console] Add clock mock to fix transient test on HHVM [DomCrawler] Optimize the regex used to find namespace prefixes [EventDispatcher] skip one lazy loading call [EventDispatcher] fix memory leak in a getListeners Default to stderr for console helpers (only merge if #15794 gets merged)
2 parents 74c24a5 + b6604f3 commit b75755c

File tree

22 files changed

+129
-84
lines changed

22 files changed

+129
-84
lines changed

src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private function writeNode(NodeInterface $node, $depth = 0)
9393
}
9494
} elseif ($node instanceof EnumNode) {
9595
$comments[] = 'One of '.implode('; ', array_map('json_encode', $node->getValues()));
96-
$default = '~';
96+
$default = $node->hasDefaultValue() ? Inline::dump($node->getDefaultValue()) : '~';
9797
} else {
9898
$default = '~';
9999

src/Symfony/Component/Config/Tests/Definition/Dumper/XmlReferenceDumperTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ private function getConfigurationAsString()
3737
return str_replace("\n", PHP_EOL, <<<EOL
3838
<!-- Namespace: http://example.org/schema/dic/acme_root -->
3939
<!-- scalar-required: Required -->
40+
<!-- enum-with-default: One of "this"; "that" -->
4041
<!-- enum: One of "this"; "that" -->
4142
<config
4243
boolean="true"
@@ -48,6 +49,7 @@ private function getConfigurationAsString()
4849
scalar-array-empty=""
4950
scalar-array-defaults="elem1,elem2"
5051
scalar-required=""
52+
enum-with-default="this"
5153
enum=""
5254
>
5355

src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private function getConfigurationAsString()
4343
- elem1
4444
- elem2
4545
scalar_required: ~ # Required
46+
enum_with_default: this # One of "this"; "that"
4647
enum: ~ # One of "this"; "that"
4748
4849
# some info

src/Symfony/Component/Config/Tests/Fixtures/Configuration/ExampleConfiguration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function getConfigTreeBuilder()
3434
->scalarNode('scalar_array_empty')->defaultValue(array())->end()
3535
->scalarNode('scalar_array_defaults')->defaultValue(array('elem1', 'elem2'))->end()
3636
->scalarNode('scalar_required')->isRequired()->end()
37+
->enumNode('enum_with_default')->values(array('this', 'that'))->defaultValue('this')->end()
3738
->enumNode('enum')->values(array('this', 'that'))->end()
3839
->arrayNode('array')
3940
->info('some info')

src/Symfony/Component/Console/Helper/ProcessHelper.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Console\Helper;
1313

14+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516
use Symfony\Component\Process\Exception\ProcessFailedException;
1617
use Symfony\Component\Process\Process;
@@ -37,6 +38,10 @@ class ProcessHelper extends Helper
3738
*/
3839
public function run(OutputInterface $output, $cmd, $error = null, $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
3940
{
41+
if ($output instanceof ConsoleOutputInterface) {
42+
$output = $output->getErrorOutput();
43+
}
44+
4045
$formatter = $this->getHelperSet()->get('debug_formatter');
4146

4247
if (is_array($cmd)) {
@@ -109,6 +114,10 @@ public function mustRun(OutputInterface $output, $cmd, $error = null, $callback
109114
*/
110115
public function wrapCallback(OutputInterface $output, Process $process, $callback = null)
111116
{
117+
if ($output instanceof ConsoleOutputInterface) {
118+
$output = $output->getErrorOutput();
119+
}
120+
112121
$formatter = $this->getHelperSet()->get('debug_formatter');
113122

114123
$that = $this;

src/Symfony/Component/Console/Helper/ProgressBar.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Console\Helper;
1313

14+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516

1617
/**
@@ -54,6 +55,10 @@ class ProgressBar
5455
*/
5556
public function __construct(OutputInterface $output, $max = 0)
5657
{
58+
if ($output instanceof ConsoleOutputInterface) {
59+
$output = $output->getErrorOutput();
60+
}
61+
5762
$this->output = $output;
5863
$this->setMaxSteps($max);
5964

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Console\Helper;
1313

1414
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1516
use Symfony\Component\Console\Output\OutputInterface;
1617
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
1718
use Symfony\Component\Console\Question\Question;
@@ -41,6 +42,10 @@ class QuestionHelper extends Helper
4142
*/
4243
public function ask(InputInterface $input, OutputInterface $output, Question $question)
4344
{
45+
if ($output instanceof ConsoleOutputInterface) {
46+
$output = $output->getErrorOutput();
47+
}
48+
4449
if (!$input->isInteractive()) {
4550
return $question->getDefault();
4651
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Helper;
13+
14+
use Symfony\Component\Console\Tests;
15+
16+
function time()
17+
{
18+
return Tests\time();
19+
}
20+
21+
namespace Symfony\Component\Console\Tests;
22+
23+
function with_clock_mock($enable = null)
24+
{
25+
static $enabled;
26+
27+
if (null === $enable) {
28+
return $enabled;
29+
}
30+
31+
$enabled = $enable;
32+
}
33+
34+
function time()
35+
{
36+
if (!with_clock_mock()) {
37+
return \time();
38+
}
39+
40+
return $_SERVER['REQUEST_TIME'];
41+
}

src/Symfony/Component/Console/Tests/Helper/LegacyProgressHelperTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,25 @@
1313

1414
use Symfony\Component\Console\Helper\ProgressHelper;
1515
use Symfony\Component\Console\Output\StreamOutput;
16+
use Symfony\Component\Console\Tests;
17+
18+
require_once __DIR__.'/../ClockMock.php';
1619

1720
/**
1821
* @group legacy
1922
*/
2023
class LegacyProgressHelperTest extends \PHPUnit_Framework_TestCase
2124
{
25+
protected function setUp()
26+
{
27+
Tests\with_clock_mock(true);
28+
}
29+
30+
protected function tearDown()
31+
{
32+
Tests\with_clock_mock(false);
33+
}
34+
2235
public function testAdvance()
2336
{
2437
$progress = new ProgressHelper();

src/Symfony/Component/CssSelector/Parser/Shortcut/ClassParser.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ public function parse($source)
3333
{
3434
// Matches an optional namespace, optional element, and required class
3535
// $source = 'test|input.ab6bd_field';
36-
// $matches = array (size=5)
37-
// 0 => string 'test:input.ab6bd_field' (length=22)
38-
// 1 => string 'test:' (length=5)
39-
// 2 => string 'test' (length=4)
40-
// 3 => string 'input' (length=5)
41-
// 4 => string 'ab6bd_field' (length=11)
42-
if (preg_match('/^(([a-z]+)\|)?([\w-]+|\*)?\.([\w-]+)$/i', trim($source), $matches)) {
36+
// $matches = array (size=4)
37+
// 0 => string 'test|input.ab6bd_field' (length=22)
38+
// 1 => string 'test' (length=4)
39+
// 2 => string 'input' (length=5)
40+
// 3 => string 'ab6bd_field' (length=11)
41+
if (preg_match('/^(?:([a-z]++)\|)?+([\w-]++|\*)?+\.([\w-]++)$/i', trim($source), $matches)) {
4342
return array(
44-
new SelectorNode(new ClassNode(new ElementNode($matches[2] ?: null, $matches[3] ?: null), $matches[4])),
43+
new SelectorNode(new ClassNode(new ElementNode($matches[1] ?: null, $matches[2] ?: null), $matches[3])),
4544
);
4645
}
4746

0 commit comments

Comments
 (0)