Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0255cb1

Browse files
committed
Merge branch '2.8' into 3.1
* 2.8: [Translation][fallback] add missing resources in parent catalogues. removed a deprecation notice [Form] Fix show float values as choices values in ChoiceType Remove double use Statement Improved the design of the metrics in the profiler [Console] Fix infinite loop on missing input [HttpFoundation][Session] memcached connection should not be closed
2 parents ba8a12a + a66e9ff commit 0255cb1

File tree

12 files changed

+102
-26
lines changed

12 files changed

+102
-26
lines changed

src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
4949

5050
return $node;
5151
} else {
52-
$var = $env->getParser()->getVarName();
52+
$var = $this->getVarName();
5353
$name = new \Twig_Node_Expression_AssignName($var, $node->getTemplateLine());
5454
$this->scope->set('domain', new \Twig_Node_Expression_Name($var, $node->getTemplateLine()));
5555

@@ -123,4 +123,9 @@ private function isNamedArguments($arguments)
123123

124124
return false;
125125
}
126+
127+
private function getVarName()
128+
{
129+
return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false));
130+
}
126131
}

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,19 @@
6060
<span class="label">Symfony initialization</span>
6161
</div>
6262

63+
{% if profile.collectors.memory %}
64+
<div class="metric">
65+
<span class="value">{{ '%.2f'|format(profile.collectors.memory.memory / 1024 / 1024) }} <span class="unit">MB</span></span>
66+
<span class="label">Peak memory usage</span>
67+
</div>
68+
{% endif %}
69+
6370
{% if profile.children|length > 0 %}
71+
<div class="metric-divider"></div>
72+
6473
<div class="metric">
6574
<span class="value">{{ profile.children|length }}</span>
66-
<span class="label">Sub-Requests</span>
75+
<span class="label">Sub-Request{{ profile.children|length > 1 ? 's' }}</span>
6776
</div>
6877

6978
{% set subrequests_time = 0 %}
@@ -73,14 +82,7 @@
7382

7483
<div class="metric">
7584
<span class="value">{{ subrequests_time }} <span class="unit">ms</span></span>
76-
<span class="label">Sub-Requests time</span>
77-
</div>
78-
{% endif %}
79-
80-
{% if profile.collectors.memory %}
81-
<div class="metric">
82-
<span class="value">{{ '%.2f'|format(profile.collectors.memory.memory / 1024 / 1024) }} <span class="unit">MB</span></span>
83-
<span class="label">Peak memory usage</span>
85+
<span class="label">Sub-Request{{ profile.children|length > 1 ? 's' }} time</span>
8486
</div>
8587
{% endif %}
8688
</div>

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/profiler.css.twig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,12 @@ table tbody ul {
254254
{# Metrics
255255
------------------------------------------------------------------------- #}
256256
.metrics {
257-
margin: 1em 0;
257+
margin: 1em 0 0;
258258
overflow: auto;
259259
}
260260
.metrics .metric {
261261
float: left;
262-
margin-right: 1em;
262+
margin: 0 1em 1em 0;
263263
}
264264

265265
.metric {
@@ -314,6 +314,12 @@ table tbody ul {
314314
vertical-align: middle;
315315
}
316316

317+
.metric-divider {
318+
float: left;
319+
margin: 0 1em;
320+
min-height: 1px; {# required to apply 'margin' to an empty 'div' #}
321+
}
322+
317323
{# Cards
318324
------------------------------------------------------------------------- #}
319325
.card {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private function doAsk(OutputInterface $output, Question $question)
132132
if (false === $ret) {
133133
$ret = fgets($inputStream, 4096);
134134
if (false === $ret) {
135-
throw new \RuntimeException('Aborted');
135+
throw new RuntimeException('Aborted');
136136
}
137137
$ret = trim($ret);
138138
}
@@ -395,6 +395,8 @@ private function validateAttempts(callable $interviewer, OutputInterface $output
395395

396396
try {
397397
return call_user_func($question->getValidator(), $interviewer());
398+
} catch (RuntimeException $e) {
399+
throw $e;
398400
} catch (\Exception $error) {
399401
}
400402
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,37 @@ public function testChoiceOutputFormattingQuestionForUtf8Keys()
402402
$dialog->ask($this->createInputInterfaceMock(), $output, $question);
403403
}
404404

405+
/**
406+
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
407+
* @expectedExceptionMessage Aborted
408+
*/
409+
public function testAskThrowsExceptionOnMissingInput()
410+
{
411+
$dialog = new QuestionHelper();
412+
$dialog->setInputStream($this->getInputStream(''));
413+
414+
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), new Question('What\'s your name?'));
415+
}
416+
417+
/**
418+
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
419+
* @expectedExceptionMessage Aborted
420+
*/
421+
public function testAskThrowsExceptionOnMissingInputWithValidator()
422+
{
423+
$dialog = new QuestionHelper();
424+
$dialog->setInputStream($this->getInputStream(''));
425+
426+
$question = new Question('What\'s your name?');
427+
$question->setValidator(function () {
428+
if (!$value) {
429+
throw new \Exception('A value is required.');
430+
}
431+
});
432+
433+
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
434+
}
435+
405436
protected function getInputStream($input)
406437
{
407438
$stream = fopen('php://memory', 'r+', false);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ public function testAskEscapeLabel()
101101
$this->assertOutputContains('Do you want a \?', $output);
102102
}
103103

104+
/**
105+
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
106+
* @expectedExceptionMessage Aborted
107+
*/
108+
public function testAskThrowsExceptionOnMissingInput()
109+
{
110+
$dialog = new SymfonyQuestionHelper();
111+
112+
$dialog->setInputStream($this->getInputStream(''));
113+
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), new Question('What\'s your name?'));
114+
}
115+
104116
protected function getInputStream($input)
105117
{
106118
$stream = fopen('php://memory', 'r+', false);

src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ private function castableToString(array $choices, array &$cache = array())
230230
continue;
231231
} elseif (!is_scalar($choice)) {
232232
return false;
233-
} elseif (isset($cache[$choice])) {
233+
}
234+
235+
$choice = false === $choice ? '0' : (string) $choice;
236+
237+
if (isset($cache[$choice])) {
234238
return false;
235239
}
236240

src/Symfony/Component/Form/Tests/ChoiceList/ArrayChoiceListTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ protected function createChoiceList()
3434

3535
protected function getChoices()
3636
{
37-
return array(0, 1, '1', 'a', false, true, $this->object, null);
37+
return array(0, 1, 1.5, '1', 'a', false, true, $this->object, null);
3838
}
3939

4040
protected function getValues()
4141
{
42-
return array('0', '1', '2', '3', '4', '5', '6', '7');
42+
return array('0', '1', '2', '3', '4', '5', '6', '7', '8');
4343
}
4444

4545
public function testCreateChoiceListWithValueCallback()
@@ -154,4 +154,13 @@ public function testGetChoicesForValuesWithContainingEmptyStringAndBooleans()
154154
$this->assertSame(array(0 => true), $choiceList->getChoicesForValues(array('1')));
155155
$this->assertSame(array(0 => false), $choiceList->getChoicesForValues(array('0')));
156156
}
157+
158+
public function testGetChoicesForValuesWithContainingEmptyStringAndFloats()
159+
{
160+
$choiceList = new ArrayChoiceList(array('Empty String' => '', '1/3' => 0.3, '1/2' => 0.5));
161+
162+
$this->assertSame(array(0 => ''), $choiceList->getChoicesForValues(array('')));
163+
$this->assertSame(array(0 => 0.3), $choiceList->getChoicesForValues(array('0.3')));
164+
$this->assertSame(array(0 => 0.5), $choiceList->getChoicesForValues(array('0.5')));
165+
}
157166
}

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcacheSessionHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function open($savePath, $sessionName)
7171
*/
7272
public function close()
7373
{
74-
return $this->memcache->close();
74+
return true;
7575
}
7676

7777
/**

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ public function testOpenSession()
5656

5757
public function testCloseSession()
5858
{
59-
$this->memcache
60-
->expects($this->once())
61-
->method('close')
62-
->will($this->returnValue(true))
63-
;
64-
6559
$this->assertTrue($this->storage->close());
6660
}
6761

src/Symfony/Component/Translation/MessageCatalogue.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ public function addFallbackCatalogue(MessageCatalogueInterface $catalogue)
178178
if ($c->getLocale() === $catalogue->getLocale()) {
179179
throw new \LogicException(sprintf('Circular reference detected when adding a fallback catalogue for locale "%s".', $catalogue->getLocale()));
180180
}
181+
182+
foreach ($catalogue->getResources() as $resource) {
183+
$c->addResource($resource);
184+
}
181185
} while ($c = $c->parent);
182186

183187
$catalogue->parent = $this;

src/Symfony/Component/Translation/Tests/MessageCatalogueTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,25 @@ public function testAddFallbackCatalogue()
110110
$r1 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface');
111111
$r1->expects($this->any())->method('__toString')->will($this->returnValue('r1'));
112112

113-
$catalogue = new MessageCatalogue('en_US', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
113+
$r2 = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface');
114+
$r2->expects($this->any())->method('__toString')->will($this->returnValue('r2'));
115+
116+
$catalogue = new MessageCatalogue('fr_FR', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
114117
$catalogue->addResource($r);
115118

116-
$catalogue1 = new MessageCatalogue('en', array('domain1' => array('foo' => 'bar', 'foo1' => 'foo1')));
119+
$catalogue1 = new MessageCatalogue('fr', array('domain1' => array('foo' => 'bar', 'foo1' => 'foo1')));
117120
$catalogue1->addResource($r1);
118121

122+
$catalogue2 = new MessageCatalogue('en');
123+
$catalogue2->addResource($r2);
124+
119125
$catalogue->addFallbackCatalogue($catalogue1);
126+
$catalogue1->addFallbackCatalogue($catalogue2);
120127

121128
$this->assertEquals('foo', $catalogue->get('foo', 'domain1'));
122129
$this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
123130

124-
$this->assertEquals(array($r, $r1), $catalogue->getResources());
131+
$this->assertEquals(array($r, $r1, $r2), $catalogue->getResources());
125132
}
126133

127134
/**

0 commit comments

Comments
 (0)