8000 Merge branch '4.4' into 5.2 · grasmash/symfony@6e1015f · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e1015f

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: skip intl dependent tests if the extension is missing make DateCaster tests timezone-agnostic error if the input string couldn't be parsed as a date IntegerType: Always use en for IntegerToLocalizedStringTransformer Fixes symfony#40456 Uses the correct assignment action for console options depending if they are short or long [HttpKernel] ConfigDataCollector to return known data without the need of a Kernel [HttpClient] fix using stream_copy_to_stream() with responses cast to php streams FIx Trying to clone an uncloneable object of class
2 parents 36cc161 + 1a27291 commit 6e1015f

File tree

13 files changed

+111
-23
lines changed

13 files changed

+111
-23
lines changed

src/Symfony/Component/Console/Input/ArrayInput.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,13 @@ public function __toString()
108108
$params = [];
109109
foreach ($this->parameters as $param => $val) {
110110
if ($param && \is_string($param) && '-' === $param[0]) {
111+
$glue = ('-' === $param[1]) ? '=' : ' ';
111112
if (\is_array($val)) {
112113
foreach ($val as $v) {
113-
$params[] = $param.('' != $v ? '='.$this->escapeToken($v) : '');
114+
$params[] = $param.('' != $v ? $glue.$this->escapeToken($v) : '');
114115
}
115116
} else {
116-
$params[] = $param.('' != $val ? '='.$this->escapeToken($val) : '');
117+
$params[] = $param.('' != $val ? $glue.$this->escapeToken($val) : '');
117118
}
118119
} else {
119120
$params[] = \is_array($val) ? implode(' ', array_map([$this, 'escapeToken'], $val)) : $this->escapeToken($val);

src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ public function provideInvalidInput()
162162
public function testToString()
163163
{
164164
$input = new ArrayInput(['-f' => null, '-b' => 'bar', '--foo' => 'b a z', '--lala' => null, 'test' => 'Foo', 'test2' => "A\nB'C"]);
165-
$this->assertEquals('-f -b=bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input);
165+
$this->assertEquals('-f -b bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input);
166166

167167
$input = new ArrayInput(['-b' => ['bval_1', 'bval_2'], '--f' => ['fval_1', 'fval_2']]);
168-
$this->assertSame('-b=bval_1 -b=bval_2 --f=fval_1 --f=fval_2', (string) $input);
168+
$this->assertSame('-b bval_1 -b bval_2 --f=fval_1 --f=fval_2', (string) $input);
169169

170170
$input = new ArrayInput(['array_arg' => ['val_1', 'val_2']]);
171171
$this->assertSame('val_1 val_2', (string) $input);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ public function reverseTransform($value)
130130
} elseif ($timestamp > 253402214400) {
131131
// This timestamp represents UTC midnight of 9999-12-31 to prevent 5+ digit years
132132
throw new TransformationFailedException('Years beyond 9999 are not supported.');
133+
} elseif (false === $timestamp) {
134+
// the value couldn't be parsed but the Intl extension didn't report an error code, this
135+
// could be the case when the Intl polyfill is used which always returns 0 as the error code
136+
throw new TransformationFailedException(sprintf('"%s" could not be parsed as a date.', $value));
133137
}
134138

135139
try {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransfo
2424
/**
2525
* Constructs a transformer.
2626
*
27-
* @param bool $grouping Whether thousands should be grouped
28-
* @param int $roundingMode One of the ROUND_ constants in this class
27+
* @param bool $grouping Whether thousands should be grouped
28+
* @param int $roundingMode One of the ROUND_ constants in this class
29+
* @param string|null $locale locale used for transforming
2930
*/
30-
public function __construct(?bool $grouping = false, ?int $roundingMode = \NumberFormatter::ROUND_DOWN)
31+
public function __construct(?bool $grouping = false, ?int $roundingMode = \NumberFormatter::ROUND_DOWN, ?string $locale)
3132
{
32-
parent::__construct(0, $grouping, $roundingMode);
33+
parent::__construct(0, $grouping, $roundingMode, $locale);
3334
}
3435

3536
/**

src/Symfony/Component/Form/Extension/Core/Type/IntegerType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class IntegerType extends AbstractType
2626
*/
2727
public function buildForm(FormBuilderInterface $builder, array $options)
2828
{
29-
$builder->addViewTransformer(new IntegerToLocalizedStringTransformer($options['grouping'], $options['rounding_mode']));
29+
$builder->addViewTransformer(new IntegerToLocalizedStringTransformer($options['grouping'], $options['rounding_mode'], !$options['grouping'] ? 'en' : null));
3030
}
3131

3232
/**

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,48 @@ class IntegerTypeTest extends BaseTypeTest
1717
{
1818
public const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\IntegerType';
1919

20+
private $previousLocale;
21+
2022
protected function setUp(): void
2123
{
2224
IntlTestHelper::requireIntl($this, false);
23-
25+
$this->previousLocale = \Locale::getDefault();
2426
parent::setUp();
2527
}
2628

29+
protected function tearDown(): void
30+
{
31+
\Locale::setDefault($this->previousLocale);
32+
}
33+
34+
/**
35+
* @requires extension intl
36+
*/
37+
public function testArabicLocale()
38+
{
39+
\Locale::setDefault('ar');
40+
41+
$form = $this->factory->create(static::TESTED_TYPE);
42+
$form->submit('123456');
43+
44+
$this->assertSame(123456, $form->getData());
45+
$this->assertSame('123456', $form->getViewData());
46+
}
47+
48+
/**
49+
* @requires extension intl
50+
*/
51+
public function testArabicLocaleNonHtml5()
52+
{
53+
\Locale::setDefault('ar');
54+
55+
$form = $this->factory->create(static::TESTED_TYPE, null, ['grouping' => true]);
56+
$form->submit('123456');
57+
58+
$this->assertSame(123456, $form->getData());
59+
$this->assertSame('١٢٣٬٤٥٦', $form->getViewData());
60+
}
61+
2762
public function testSubmitRejectsFloats()
2863
{
2964
$form = $this->factory->create(static::TESTED_TYPE);

src/Symfony/Component/HttpClient/Response/StreamWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public function stream_stat(): array
289289
'uid' => 0,
290290
'gid' => 0,
291291
'rdev' => 0,
292-
'size' => (int) ($headers['content-length'][0] ?? 0),
292+
'size' => (int) ($headers['content-length'][0] ?? -1),
293293
'atime' => 0,
294294
'mtime' => strtotime($headers['last-modified'][0] ?? '') ?: 0,
295295
'ctime' => 0,

src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ public function testToStream()
7575
$this->assertTrue(feof($stream));
7676
}
7777

78+
public function testStreamCopyToStream()
79+
{
80+
$client = $this->getHttpClient(__FUNCTION__);
81+
$response = $client->request('GET', 'http://localhost:8057');
82+
$h = fopen('php://temp', 'w+');
83+
stream_copy_to_stream($response->toStream(), $h);
84+
85+
$this->assertTrue(rewind($h));
86+
$this->assertSame("{\n \"SER", fread($h, 10));
87+
$this->assertSame('VER_PROTOCOL', fread($h, 12));
88+
$this->assertFalse(feof($h));
89+
}
90+
7891
public function testToStream404()
7992
{
8093
$client = $this->getHttpClient(__FUNCTION__);

src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,17 @@ public function setKernel(KernelInterface $kernel = null)
4242
*/
4343
public function collect(Request $request, Response $response, \Throwable $exception = null)
4444
{
45+
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE);
46+
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE);
47+
4548
$this->data = [
4649
'token' => $response->headers->get('X-Debug-Token'),
4750
'symfony_version' => Kernel::VERSION,
48-
'symfony_state' => 'unknown',
51+
'symfony_minor_version' => sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION),
52+
'symfony_lts' => 4 === Kernel::MINOR_VERSION,
53+
'symfony_state' => $this->determineSymfonyState(),
54+
'symfony_eom' => $eom->format('F Y'),
55+
'symfony_eol' => $eol->format('F Y'),
4956
'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
5057
'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
5158
'php_version' => \PHP_VERSION,
@@ -63,14 +70,6 @@ public function collect(Request $request, Response $response, \Throwable $except
6370
foreach ($this->kernel->getBundles() as $name => $bundle) {
6471
$this->data['bundles'][$name] = new ClassStub(\get_class($bundle));
6572
}
66-
67-
$this->data['symfony_state'] = $this->determineSymfonyState();
68-
$this->data['symfony_minor_version'] = sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION);
69-
$this->data['symfony_lts'] = 4 === Kernel::MINOR_VERSION;
70-
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE);
71-
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE);
72-
$this->data['symfony_eom'] = $eom->format('F Y');
73-
$this->data['symfony_eol'] = $eol->format('F Y');
7473
}
7574

7675
if (preg_match('~^(\d+(?:\.\d+)*)(.+)?$~', $this->data['php_version'], $matches) && isset($matches[2])) {

src/Symfony/Component/HttpKernel/Tests/DataCollector/ConfigDataCollectorTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,41 @@ public function testCollect()
4141
$this->assertSame(\extension_loaded('xdebug'), $c->hasXDebug());
4242
$this->assertSame(\extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN), $c->hasZendOpcache());
4343
$this->assertSame(\extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN), $c->hasApcu());
44+
$this->assertSame(sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION), $c->getSymfonyMinorVersion());
45+
$this->assertContains($c->getSymfonyState(), ['eol', 'eom', 'dev', 'stable']);
46+
47+
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE)->format('F Y');
48+
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE)->format('F Y');
49+
$this->assertSame($eom, $c->getSymfonyEom());
50+
$this->assertSame($eol, $c->getSymfonyEol());
51+
}
52+
53+
public function testCollectWithoutKernel()
54+
{
55+
$c = new ConfigDataCollector();
56+
$c->collect(new Request(), new Response());
57+
58+
$this->assertSame('n/a', $c->getEnv());
59+
$this->assertSame('n/a', $c->isDebug());
60+
$this->assertSame('config', $c->getName());
61+
$this->assertMatchesRegularExpression('~^'.preg_quote($c->getPhpVersion(), '~').'~', \PHP_VERSION);
62+
$this->assertMatchesRegularExpression('~'.preg_quote((string) $c->getPhpVersionExtra(), '~').'$~', \PHP_VERSION);
63+
$this->assertSame(\PHP_INT_SIZE * 8, $c->getPhpArchitecture());
64+
$this->assertSame(class_exists(\Locale::class, false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', $c->getPhpIntlLocale());
65+
$this->assertSame(date_default_timezone_get(), $c->getPhpTimezone());
66+
$this->assertSame(Kernel::VERSION, $c->getSymfonyVersion());
67+
$this->assertSame(4 === Kernel::MINOR_VERSION, $c->isSymfonyLts());
68+
$this->assertNull($c->getToken());
69+
$this->assertSame(\extension_loaded('xdebug'), $c->hasXDebug());
70+
$this->assertSame(\extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN), $c->hasZendOpcache());
71+
$this->assertSame(\extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN), $c->hasApcu());
72+
$this->assertSame(sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION), $c->getSymfonyMinorVersion());
73+
$this->assertContains($c->getSymfonyState(), ['eol', 'eom', 'dev', 'stable']);
74+
75+
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE)->format('F Y');
76+
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE)->format('F Y');
77+
$this->assertSame($eom, $c->getSymfonyEom());
78+
$this->assertSame($eol, $c->getSymfonyEol());
4479
}
4580
}
4681

src/Symfony/Component/Lock/Tests/Store/StoreFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testCreateStore($connection, string $expectedStoreClass)
4343
public function validConnections()
4444
{
4545
if (class_exists(\Redis::class)) {
46-
yield [$this->createMock(\Redis::class), RedisStore::class];
46+
yield [new \Redis(), RedisStore::class];
4747
}
4848
if (class_exists(RedisProxy::class)) {
4949
yield [$this->createMock(RedisProxy::class), RedisStore::class];

src/Symfony/Component/VarDumper/Caster/DateCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static function castPeriod(\DatePeriod $p, array $a, Stub $stub, bool $is
9191
$dates = [];
9292
foreach (clone $p as $i => $d) {
9393
if (self::PERIOD_LIMIT === $i) {
94-
$now = new \DateTimeImmutable();
94+
$now = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
9595
$dates[] = sprintf('%s more', ($end = $p->getEndDate())
9696
? ceil(($end->format('U.u') - $d->format('U.u')) / ((int) $now->add($p->getDateInterval())->format('U.u') - (int) $now->format('U.u')))
9797
: $p->recurrences - $i

src/Symfony/Component/VarDumper/Tests/Caster/DateCasterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public function testDumpPeriod($start, $interval, $end, $options, $expected)
341341
*/
342342
public function testCastPeriod($start, $interval, $end, $options, $xPeriod, $xDates)
343343
{
344-
$p = new \DatePeriod(new \DateTime($start), new \DateInterval($interval), \is_int($end) ? $end : new \DateTime($end), $options);
344+
$p = new \DatePeriod(new \DateTime($start, new \DateTimeZone('UTC')), new \DateInterval($interval), \is_int($end) ? $end : new \DateTime($end, new \DateTimeZone('UTC')), $options);
345345
$stub = new Stub();
346346

347347
$cast = DateCaster::castPeriod($p, [], $stub, false, 0);

0 commit comments

Comments
 (0)
0