8000 Merge branch '2.7' into 2.8 · symfony/symfony@d49005a · GitHub
[go: up one dir, main page]

Skip to content

Commit d49005a

Browse files
Merge branch '2.7' into 2.8
* 2.7: Lighten tests output by removing composer suggestions CS: Remove invisible chars Disable resource tracking if the config component is missing [EventDispatcher] Remove unneded count() Fix tests expecting a valid date [Console] Fix table cell styling [Console] Revised exception rendering [WebProfilerBundle] Normalize whitespace in exceptions passed in headers Disable color support detection for tests [Form] Improve the exceptions when trying to get the data in a PRE_SET_DATA listener and the data has not already been set
2 parents 994e90c + 85ae039 commit d49005a

File tree

18 files changed

+169
-25
lines changed

18 files changed

+169
-25
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ install:
7979
- export COMPOSER_ROOT_VERSION=$SYMFONY_VERSION.x-dev
8080
- if [[ ! $skip && $deps ]]; then export SYMFONY_DEPRECATIONS_HELPER=weak; fi
8181
- if [[ ! $skip && $deps ]]; then mv composer.json.phpunit composer.json; fi
82-
- if [[ ! $skip ]]; then composer update; fi
82+
- if [[ ! $skip ]]; then composer update --no-suggest; fi
8383
- if [[ ! $skip ]]; then ./phpunit install; fi
8484
- if [[ ! $skip && ! $PHP = hhvm* ]]; then php -i; else hhvm --php -r 'print_r($_SERVER);print_r(ini_get_all());'; fi
8585

@@ -90,5 +90,5 @@ script:
9090
- if [[ ! $deps && ! $PHP = hhvm* ]]; then echo -e "\\nRunning tests requiring tty"; $PHPUNIT --group tty; fi
9191
- if [[ ! $deps && $PHP = hhvm* ]]; then $PHPUNIT --exclude-group benchmark,intl-data; fi
9292
- if [[ ! $deps && $PHP = ${MIN_PHP%.*} ]]; then echo -e "1\\n0" | xargs -I{} sh -c 'echo "\\nPHP --enable-sigchild enhanced={}" && ENHANCE_SIGCHLD={} php-$MIN_PHP/sapi/cli/php .phpunit/phpunit-4.8/phpunit --colors=always src/Symfony/Component/Process/'; fi
93-
- if [[ $deps = high ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --ansi; $PHPUNIT --exclude-group tty,benchmark,intl-data'$LEGACY"$REPORT"; fi
94-
- if [[ $deps = low ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --ansi --prefer-lowest --prefer-stable; $PHPUNIT --exclude-group tty,benchmark,intl-data'"$REPORT"; fi
93+
- if [[ $deps = high ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --no-suggest --ansi; $PHPUNIT --exclude-group tty,benchmark,intl-data'$LEGACY"$REPORT"; fi
94+
- if [[ $deps = low ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --no-suggest --ansi --prefer-lowest --prefer-stable; $PHPUNIT --exclude-group tty,benchmark,intl-data'"$REPORT"; fi

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ install:
5454
- copy /Y .composer\* %APPDATA%\Composer\
5555
- php .github/build-packages.php "HEAD^" src\Symfony\Bridge\PhpUnit
5656
- IF %APPVEYOR_REPO_BRANCH%==master (SET COMPOSER_ROOT_VERSION=dev-master) ELSE (SET COMPOSER_ROOT_VERSION=%APPVEYOR_REPO_BRANCH%.x-dev)
57-
- php composer.phar update --no-progress --ansi
57+
- php composer.phar update --no-progress --no-suggest --ansi
5858
- php phpunit install
5959

6060
test_script:

src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function onKernelResponse(FilterResponseEvent $event)
6868
$this->urlGenerator->generate('_profiler', array('token' => $response->headers->get('X-Debug-Token')), UrlGeneratorInterface::ABSOLUTE_URL)
6969
);
7070
} catch (\Exception $e) {
71-
$response->headers->set('X-Debug-Error', get_class($e).': '.$e->getMessage());
71+
$response->headers->set('X-Debug-Error', get_class($e).': '.preg_replace('/\s+/', ' ', $e->getMessage()));
7272
}
7373
}
7474

src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,27 @@ public function testThrowingUrlGenerator()
245245
$this->assertEquals('Exception: foo', $response->headers->get('X-Debug-Error'));
246246
}
247247

248+
public function testThrowingErrorCleanup()
249+
{
250+
$response = new Response();
251+
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
252+
253+
$urlGenerator = $this->getUrlGeneratorMock();
254+
$urlGenerator
255+
->expects($this->once())
256+
->method('generate')
257+
->with('_profiler', array('token' => 'xxxxxxxx'))
258+
->will($this->throwException(new \Exception("This\nmultiline\r\ntabbed text should\tcome out\r on\n \ta single plain\r\nline")))
259+
;
260+
261+
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
262+
263+
$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, 'bottom', $urlGenerator);
264+
$listener->onKernelResponse($event);
265+
266+
$this->assertEquals('Exception: This multiline tabbed text should come out on a single plain line', $response->headers->get('X-Debug-Error'));
267+
}
268+
248269
protected function getRequestMock($isXmlHttpRequest = false, $requestFormat = 'html', $hasSession = true)
249270
{
250271
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->setMethods(array('getSession', 'isXmlHttpRequest', 'getRequestFormat'))->disableOriginalConstructor()->getMock();

src/Symfony/Component/Console/Application.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -653,28 +653,27 @@ public function renderException($e, $output)
653653
if (defined('HHVM_VERSION') && $width > 1 << 31) {
654654
$width = 1 << 31;
655655
}
656-
$formatter = $output->getFormatter();
657656
$lines = array();
658-
foreach (preg_split('/\r?\n/', OutputFormatter::escape($e->getMessage())) as $line) {
657+
foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) {
659658
foreach ($this->splitStringByWidth($line, $width - 4) as $line) {
660659
// pre-format lines to get the right string length
661-
$lineLength = $this->stringWidth(preg_replace('/\[[^m]*m/', '', $formatter->format($line))) + 4;
660+
$lineLength = $this->stringWidth($line) + 4;
662661
$lines[] = array($line, $lineLength);
663662

664663
$len = max($lineLength, $len);
665664
}
666665
}
667666

668667
$messages = array();
669-
$messages[] = $emptyLine = $formatter->format(sprintf('<error>%s</error>', str_repeat(' ', $len)));
670-
$messages[] = $formatter->format(sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - $this->stringWidth($title)))));
668+
$messages[] = $emptyLine = sprintf('<error>%s</error>', str_repeat(' ', $len));
669+
$messages[] = sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - $this->stringWidth($title))));
671670
foreach ($lines as $line) {
672-
$messages[] = $formatter->format(sprintf('<error> %s %s</error>', $line[0], str_repeat(' ', $len - $line[1])));
671+
$messages[] = sprintf('<error> %s %s</error>', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1]));
673672
}
674673
$messages[] = $emptyLine;
675674
$messages[] = '';
676675

677-
$output->writeln($messages, OutputInterface::OUTPUT_RAW | OutputInterface::VERBOSITY_QUIET);
676+
$output->writeln($messages, OutputInterface::VERBOSITY_QUIET);
678677

679678
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
680679
$output->writeln('<comment>Exception trace:</comment>', OutputInterface::VERBOSITY_QUIET);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ public static function formatMemory($memory)
105105
}
106106

107107
public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, $string)
108+
{
109+
return self::strlen(self::removeDecoration($formatter, $string));
110+
}
111+
112+
public static function removeDecoration(OutputFormatterInterface $formatter, $string)
108113
{
109114
$isDecorated = $formatter->isDecorated();
110115
$formatter->setDecorated(false);
@@ -114,6 +119,6 @@ public static function strlenWithoutDecoration(OutputFormatterInterface $formatt
114119
$string = preg_replace("/\033\[[^m]*m/", '', $string);
115120
$formatter->setDecorated($isDecorated);
116121

117-
return self::strlen($string);
122+
return $string;
118123
}
119124
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ private function buildTableRows($rows)
387387
if (!strstr($cell, "\n")) {
388388
continue;
389389
}
390-
$lines = explode("\n", $cell);
390+
$lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
391391
foreach ($lines as $lineKey => $line) {
392392
if ($cell instanceof TableCell) {
393393
$line = new TableCell($line, array('colspan' => $cell->getColspan()));
@@ -428,7 +428,7 @@ private function fillNextRows($rows, $line)
428428
$nbLines = $cell->getRowspan() - 1;
429429
$lines = array($cell);
430430
if (strstr($cell, "\n")) {
431-
$lines = explode("\n", $cell);
431+
$lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
432432
$nbLines = count($lines) > $nbLines ? substr_count($cell, "\n") : $nbLines;
433433

434434
$rows[$line][$column] = new TableCell($lines[0], array('colspan' => $cell->getColspan()));
@@ -563,9 +563,10 @@ private function calculateColumnsWidth($rows)
563563

564564
foreach ($row as $i => $cell) {
565565
if ($cell instanceof TableCell) {
566-
$textLength = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
566+
$textContent = Helper::removeDecoration($this->output->getFormatter(), $cell);
567+
$textLength = Helper::strlen($textContent);
567568
if ($textLength > 0) {
568-
$contentColumns = str_split($cell, ceil($textLength / $cell->getColspan()));
569+
$contentColumns = str_split($textContent, ceil($textLength / $cell->getColspan()));
569570
foreach ($contentColumns as $position => $content) {
570571
$row[$i + $position] = $content;
571572
}

src/Symfony/Component/Console/Tester/CommandTester.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ public function execute(array $input, array $options = array())
7070
}
7171

7272
$this->output = new StreamOutput(fopen('php://memory', 'w', false));
73-
if (isset($options['decorated'])) {
74-
$this->output->setDecorated($options['decorated']);
75-
}
73+
$this->output->setDecorated(isset($options['decorated']) ? $options['decorated'] : false);
7674
if (isset($options['verbosity'])) {
7775
$this->output->setVerbosity($options['verbosity']);
7876
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,22 @@ public function testRenderExceptionWithDoubleWidthCharacters()
595595
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_doublewidth2.txt', $tester->getDisplay(true), '->renderException() wraps messages when they are bigger than the terminal');
596596
}
597597

598+
public function testRenderExceptionEscapesLines()
599+
{
600+
$application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(array('getTerminalWidth'))->getMock();
601+
$application->setAutoExit(false);
602+
$application->expects($this->any())
603+
->method('getTerminalWidth')
604+
->will($this->returnValue(22));
605+
$application->register('foo')->setCode(function () {
606+
throw new \Exception('dont break here <info>!</info>');
607+
});
608+
$tester = new ApplicationTester($application);
609+
610+
$tester->run(array('command' => 'foo'), array('decorated' => false));
611+
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_escapeslines.txt', $tester->getDisplay(true), '->renderException() escapes lines containing formatting');
612+
}
613+
598614
public function testRun()
599615
{
600616
$application = new Application();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
[Exception]
4+
dont break here <
5+
info>!</info>
6+
7+
8+
foo
9+

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,35 @@ public function renderProvider()
511511
| Dante Alighieri | J. R. R. Tolkien | J. R. R |
512512
+-----------------+------------------+---------+
513513
514+
TABLE
515+
,
516+
true,
517+
),
518+
'Row with formatted cells containing a newline' => array(
519+
array(),
520+
array(
521+
array(
522+
new TableCell('<error>Dont break'."\n".'here</error>', array('colspan' => 2)),
523+
),
524+
new TableSeparator(),
525+
array(
526+
'foo',
527+
new TableCell('<error>Dont break'."\n".'here</error>', array('rowspan' => 2)),
528+
),
529+
array(
530+
'bar',
531+
),
532+
),
533+
'default',
< CDA2 /code>
534+
<<<'TABLE'
535+
+-------+------------+
536+
| Dont break |
537+
| here |
538+
+-------+------------+
539+
| foo | Dont break |
540+
| bar | here |
541+
+-------+------------+
542+
514543
TABLE
515544
,
516545
true,

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Symfony\Component\Config\Resource\ResourceInterface;
2727
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface;
2828
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\RealServiceInstantiator;
29+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
2930
use Symfony\Component\ExpressionLanguage\Expression;
3031
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
3132

@@ -73,7 +74,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
7374
*/
7475
private $compiler;
7576

76-
private $trackResources = true;
77+
private $trackResources;
7778

7879
/**
7980
* @var InstantiatorInterface|null
@@ -90,6 +91,13 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
9091
*/
9192
private $expressionLanguageProviders = array();
9293

94+
public function __construct(ParameterBagInterface $parameterBag = null)
95+
{
96+
parent::__construct($parameterBag);
97+
98+
$this->trackResources = interface_exists('Symfony\Component\Config\Resource\ResourceInterface');
99+
}
100+
93101
/**
94102
* @var string[] with tag names used by findTaggedServiceIds
95103
*/

src/Symfony/Component/EventDispatcher/EventDispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function getListenerPriority($eventName, $listener)
103103
*/
104104
public function hasListeners($eventName = null)
105105
{
106-
return (bool) count($this->getListeners($eventName));
106+
return (bool) $this->getListeners($eventName);
107107
}
108108

109109
/**

src/Symfony/Component/Form/Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function reverseTransform($value)
120120

121121
$formatter = $this->getNumberFormatter();
122122
// replace normal spaces so that the formatter can read them
123-
$value = $formatter->parse(str_replace(' ', ' ', $value));
123+
$value = $formatter->parse(str_replace(' ', "\xc2\xa0", $value));
124124

125125
if (intl_is_failure($formatter->getErrorCode())) {
126126
throw new TransformationFailedException($formatter->getErrorMessage());

src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct($validator)
6060

6161
public function loadTypeGuesser()
6262
{
63-
// 2.5 API
63+
// 2.5 API
6464
if ($this->validator instanceof ValidatorInterface) {
6565
return new ValidatorTypeGuesser($this->validator);
6666
}

src/Symfony/Component/Form/Form.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ public function getData()
408408
}
409409

410410
if (!$this->defaultDataSet) {
411+
if ($this->lockSetData) {
412+
throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getData() if the form data has not already been set. You should call getData() on the FormEvent object instead.');
413+
}
414+
411415
$this->setData($this->config->getData());
412416
}
413417

@@ -428,6 +432,10 @@ public function getNormData()
428432
}
429433

430434
if (!$this->defaultDataSet) {
435+
if ($this->lockSetData) {
436+
throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getNormData() if the form data has not already been set.');
437+
}
438+
431439
$this->setData($this->config->getData());
432440
}
433441

@@ -448,6 +456,10 @@ public function getViewData()
448456
}
449457

450458
if (!$this->defaultDataSet) {
459+
if ($this->lockSetData) {
460+
throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getViewData() if the form data has not already been set.');
461+
}
462+
451463
$this->setData($this->config->getData());
452464
}
453465

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ public function testIsSynchronizedReturnsTrueIfChoiceAndCompletelyFilled()
608608
));
609609

610610
$form->submit(array(
611-
'day' => '0',
611+
'day' => '1',
612612
'month' => '6',
613613
'year' => '2010',
614614
));

src/Symfony/Component/Form/Tests/SimpleFormTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ public function testViewDataMustBeObjectIfDataClassIsSet()
903903

904904
/**
905905
* @expectedException \Symfony\Component\Form\Exception\RuntimeException
906+
* @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call setData(). You should call setData() on the FormEvent object instead.
906907
*/
907908
public function testSetDataCannotInvokeItself()
908909
{
@@ -1084,6 +1085,51 @@ public function testCustomOptionsResolver()
10841085
$fooType->setDefaultOptions($resolver);
10851086
}
10861087

1088+
/**
1089+
* @expectedException \Symfony\Component\Form\Exception\RuntimeException
1090+
* @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call getData() if the form data has not already been set. You should call getData() on the FormEvent object instead.
1091+
*/
1092+
public function testCannotCallGetDataInPreSetDataListenerIfDataHasNotAlreadyBeenSet()
1093+
{
1094+
$config = new FormConfigBuilder('name', 'stdClass', $this->dispatcher);
1095+
$config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
1096+
$event->getForm()->getData();
1097+
});
1098+
$form = new Form($config);
1099+
1100+
$form->setData('foo');
1101+
}
1102+
1103+
/**
1104+
* @expectedException \Symfony\Component\Form\Exception\RuntimeException
1105+
* @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call getNormData() if the form data has not already been set.
1106+
*/
1107+
public function testCannotCallGetNormDataInPreSetDataListener()
1108+
{
1109+
$config = new FormConfigBuilder('name', 'stdClass', $this->dispatcher);
1110+
$config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
1111+
$event->getForm()->getNormData();
1112+
});
1113+
$form = new Form($config);
1114+
1115+
$form->setData('foo');
1116+
}
1117+
1118+
/**
1119+
* @expectedException \Symfony\Component\Form\Exception\RuntimeException
1120+
* @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call getViewData() if the form data has not already been set.
1121+
*/
1122+
public function testCannotCallGetViewDataInPreSetDataListener()
1123+
{
1124+
$config = new FormConfigBuilder('name', 'stdClass', $this->dispatcher);
1125+
$config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
1126+
$event->getForm()->getViewData();
1127+
});
1128+
$form = new Form($config);
1129+
1130+
$form->setData('foo');
1131+
}
1132+
10871133
protected function createForm()
10881134
{
10891135
return $this->getBuilder()->getForm();

0 commit comments

Comments
 (0)
0