Skip to content

Commit f7d8f1b

Browse files
Merge branch '3.4' into 4.2
* 3.4: fix inline handling when dumping tagged values [PropertyAccess] Fix PropertyAccessorCollectionTest Typo in web profiler relax some date parser patterns Avoid getting right to left style
2 parents e06b0f0 + 639041c commit f7d8f1b

File tree

10 files changed

+150
-10
lines changed

10 files changed

+150
-10
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@
663663
</table>
664664
{% else %}
665665
<div class="empty">
666-
<p>No options where passed when constructing this form.</p>
666+
<p>No options were passed when constructing this form.</p>
667667
</div>
668668
{% endif %}
669669
</div>

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

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
text-align: left;
5555
text-transform: none;
5656
z-index: 99999;
57+
direction: ltr;
5758

5859
/* neutralize the aliasing defined by external CSS styles */
5960
-webkit-font-smoothing: subpixel-antialiased;

src/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function format(\DateTime $dateTime, int $length): string
3333
*/
3434
public function getReverseMatchingRegExp(int $length): string
3535
{
36-
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
36+
return 1 === $length ? '\d{1,2}' : '\d{1,'.$length.'}';
3737
}
3838

3939
/**

src/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function getReverseMatchingRegExp(int $length): string
104104
$regExp = '[JFMASOND]';
105105
break;
106106
default:
107-
$regExp = '\d{'.$length.'}';
107+
$regExp = '\d{1,'.$length.'}';
108108
break;
109109
}
110110

src/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function format(\DateTime $dateTime, int $length): string
3737
*/
3838
public function getReverseMatchingRegExp(int $length): string
3939
{
40-
return 2 === $length ? '\d{2}' : '\d{4}';
40+
return 2 === $length ? '\d{2}' : '\d{1,4}';
4141
}
4242

4343
/**

src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ public function parseMonthProvider()
600600
{
601601
return [
602602
['y-M-d', '1970-1-1', 0],
603+
['y-MM-d', '1970-1-1', 0],
603604
['y-MMM-d', '1970-Jan-1', 0],
604605
['y-MMMM-d', '1970-January-1', 0],
605606
];
@@ -618,6 +619,7 @@ public function parseDayProvider()
618619
{
619620
return [
620621
['y-M-d', '1970-1-1', 0],
622+
['y-M-dd', '1970-1-1', 0],
621623
['y-M-dd', '1970-1-01', 0],
622624
['y-M-ddd', '1970-1-001', 0],
623625
];

src/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ public function parseQuarterProvider()
183183
return $this->notImplemented(parent::parseQuarterProvider());
184184
}
185185

186+
public function testParseThreeDigitsYears()
187+
{
188+
if (PHP_INT_SIZE < 8) {
189+
$this->markTestSkipped('Parsing three digits years requires a 64bit PHP.');
190+
}
191+
192+
$formatter = $this->getDefaultDateFormatter('yyyy-M-d');
193+
$this->assertSame(-32157648000, $formatter->parse('950-12-19'));
194+
$this->assertIsIntlSuccess($formatter, 'U_ZERO_ERROR', IntlGlobals::U_ZERO_ERROR);
195+
}
196+
186197
protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null)
187198
{
188199
return new IntlDateFormatter($locale, $datetype, $timetype, $timezone, $calendar, $pattern);

src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php

+27-5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,28 @@ public function getAxes()
4343
}
4444
}
4545

46+
class PropertyAccessorCollectionTest_CarOnlyAdder
47+
{
48+
public function addAxis($axis)
49+
{
50+
}
51+
52+
public function getAxes()
53+
{
54+
}
55+
}
56+
57+
class PropertyAccessorCollectionTest_CarOnlyRemover
58+
{
59+
public function removeAxis($axis)
60+
{
61+
}
62+
63+
public function getAxes()
64+
{
65+
}
66+
}
67+
4668
class PropertyAccessorCollectionTest_CarNoAdderAndRemover
4769
{
4870
public function getAxes()
@@ -143,25 +165,25 @@ public function testSetValueFailsIfNoAdderNorRemoverFound()
143165

144166
public function testIsWritableReturnsTrueIfAdderAndRemoverExists()
145167
{
146-
$car = $this->getMockBuilder(__CLASS__.'_Car')->getMock();
168+
$car = new PropertyAccessorCollectionTest_Car();
147169
$this->assertTrue($this->propertyAccessor->isWritable($car, 'axes'));
148170
}
149171

150172
public function testIsWritableReturnsFalseIfOnlyAdderExists()
151173
{
152-
$car = $this->getMockBuilder(__CLASS__.'_CarOnlyAdder')->getMock();
174+
$car = new PropertyAccessorCollectionTest_CarOnlyAdder();
153175
$this->assertFalse($this->propertyAccessor->isWritable($car, 'axes'));
154176
}
155177

156178
public function testIsWritableReturnsFalseIfOnlyRemoverExists()
157179
{
158-
$car = $this->getMockBuilder(__CLASS__.'_CarOnlyRemover')->getMock();
180+
$car = new PropertyAccessorCollectionTest_CarOnlyRemover();
159181
$this->assertFalse($this->propertyAccessor->isWritable($car, 'axes'));
160182
}
161183

162184
public function testIsWritableReturnsFalseIfNoAdderNorRemoverExists()
163185
{
164-
$car = $this->getMockBuilder(__CLASS__.'_CarNoAdderAndRemover')->getMock();
186+
$car = new PropertyAccessorCollectionTest_CarNoAdderAndRemover();
165187
$this->assertFalse($this->propertyAccessor->isWritable($car, 'axes'));
166188
}
167189

@@ -171,7 +193,7 @@ public function testIsWritableReturnsFalseIfNoAdderNorRemoverExists()
171193
*/
172194
public function testSetValueFailsIfAdderAndRemoverExistButValueIsNotTraversable()
173195
{
174-
$car = $this->getMockBuilder(__CLASS__.'_Car')->getMock();
196+
$car = new PropertyAccessorCollectionTest_Car();
175197

176198
$this->propertyAccessor->setValue($car, 'axes', 'Not an array or Traversable');
177199
}

src/Symfony/Component/Yaml/Dumper.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Yaml;
1313

14+
use Symfony\Component\Yaml\Tag\TaggedValue;
15+
1416
/**
1517
* Dumper dumps PHP variables to YAML strings.
1618
*
@@ -56,7 +58,7 @@ public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0):
5658
$dumpObjectAsInlineMap = empty((array) $input);
5759
}
5860

59-
if ($inline <= 0 || (!\is_array($input) && $dumpObjectAsInlineMap) || empty($input)) {
61+
if ($inline <= 0 || (!\is_array($input) && !$input instanceof TaggedValue && $dumpObjectAsInlineMap) || empty($input)) {
6062
$output .= $prefix.Inline::dump($input, $flags);
6163
} else {
6264
$dumpAsMap = Inline::isHash($input);
@@ -75,6 +77,19 @@ public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0):
7577
continue;
7678
}
7779

80+
if ($value instanceof TaggedValue) {
81+
$output .= sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag());
82+
83+
if ($inline - 1 <= 0) {
84+
$output .= ' '.$this->dump($value->getValue(), $inline - 1, 0, $flags)."\n";
85+
} else {
86+
$output .= "\n";
87+
$output .= $this->dump($value->getValue(), $inline - 1, $dumpAsMap ? $indent + $this->indentation : $indent + 2, $flags);
88+
}
89+
90+
continue;
91+
}
92+
7893
$dumpObjectAsInlineMap = true;
7994

8095
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \ArrayObject || $value instanceof \stdClass)) {

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

+89
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Yaml\Dumper;
1616
use Symfony\Component\Yaml\Parser;
17+
use Symfony\Component\Yaml\Tag\TaggedValue;
1718
use Symfony\Component\Yaml\Yaml;
1819

1920
class DumperTest extends TestCase
@@ -368,6 +369,94 @@ public function testDumpingStdClassInstancesRespectsInlineLevel()
368369
inner2: c
369370
inner3: { deep1: d, deep2: e }
370371
372+
YAML;
373+
$this->assertSame($expected, $yaml);
374+
}
375+
376+
public function testDumpingTaggedValueSequenceRespectsInlineLevel()
377+
{
378+
$data = [
379+
new TaggedValue('user', [
380+
'username' => 'jane',
381+
]),
382+
new TaggedValue('user', [
383+
'username' => 'john',
384+
]),
385+
];
386+
387+
$yaml = $this->dumper->dump($data, 2);
388+
389+
$expected = <<<YAML
390+
- !user
391+
username: jane
392+
- !user
393+
username: john
394+
395+
YAML;
396+
$this->assertSame($expected, $yaml);
397+
}
398+
399+
public function testDumpingTaggedValueSequenceWithInlinedTagValues()
400+
{
401+
$data = [
402+
new TaggedValue('user', [
403+
'username' => 'jane',
404+
]),
405+
new TaggedValue('user', [
406+
'username' => 'john',
407+
]),
408+
];
409+
410+
$yaml = $this->dumper->dump($data, 1);
411+
412+
$expected = <<<YAML
413+
- !user { username: jane }
414+
- !user { username: john }
415+
416+
YAML;
417+
$this->assertSame($expected, $yaml);
418+
}
419+
420+
public function testDumpingTaggedValueMapRespectsInlineLevel()
421+
{
422+
$data = [
423+
'user1' => new TaggedValue('user', [
424+
'username' => 'jane',
425+
]),
426+
'user2' => new TaggedValue('user', [
427+
'username' => 'john',
428+
]),
429+
];
430+
431+
$yaml = $this->dumper->dump($data, 2);
432+
433+
$expected = <<<YAML
434+
user1: !user
435+
username: jane
436+
user2: !user
437+
username: john
438+
439+
YAML;
440+
$this->assertSame($expected, $yaml);
441+
}
442+
443+
public function testDumpingTaggedValueMapWithInlinedTagValues()
444+
{
445+
$data = [
446+
'user1' => new TaggedValue('user', [
447+
'username' => 'jane',
448+
]),
449+
'user2' => new TaggedValue('user', [
450+
'username' => 'john',
451+
]),
452+
];
453+
454+
$yaml = $this->dumper->dump($data, 1);
455+
456+
$expected = <<<YAML
457+
user1: !user { username: jane }
458+
user2: !user { username: john }
459+
371460
YAML;
372461
$this->assertSame($expected, $yaml);
373462
}

0 commit comments

Comments
 (0)