8000 Merge branch '7.1' into 7.2 · symfony/symfony@33d4644 · GitHub
[go: up one dir, main page]

Skip to content

Commit 33d4644

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: [Form] Remove unnecessary imports minor #58472 CS: clean some whitespaces/indentation (keradus) Fix newline harden test to not depend on the system's configured default timezone [Form] Support intl.use_exceptions/error_level in NumberToLocalizedStringTransformer [Doctrine][Messenger] Use common sequence name to get id from Oracle [ExpressionLanguage] Add missing test case for `Lexer` [FrameworkBundle] Fix passing request_stack to session.listener ensure session storages are opened in tests before destroying them [Serializer] Fix `ObjectNormalizer` gives warnings on normalizing with public static property [HttpKernel] Correctly merge `max-age`/`s-maxage` and `Expires` headers [Security][Validator] Check translations for Czech [Security] Fix serialized object representation in tests [DoctrineBridge] Fix risky test warnings [Serializer] Catch `NotNormalizableValueException` for variadic parameters
2 parents 290b04a + f89cf32 commit 33d4644

File tree

28 files changed

+357
-66
lines changed

28 files changed

+357
-66
lines changed

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
class EntityTypePerformanceTest extends FormPerformanceTestCase
2727
{
28-
private const ENTITY_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity';
28+
private const ENTITY_CLASS = SingleIntIdEntity::class;
2929

3030
private EntityManager $em;
3131

src/Symfony/Bundle/FrameworkBundle/Resources/config/session.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
'session_factory' => service('session.factory')->ignoreOnInvalid(),
9191
'logger' => service('logger')->ignoreOnInvalid(),
9292
'session_collector' => service('data_collector.request.session_collector')->ignoreOnInvalid(),
93+
'request_stack' => service('request_stack')->ignoreOnInvalid(),
9394
]),
9495
param('kernel.debug'),
9596
param('session.storage.options'),

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ public function testNullSessionHandler()
689689
$this->assertNull($container->getParameter('session.save_path'));
690690
$this->assertSame('session.handler.native', (string) $container->getAlias('session.handler'));
691691

692-
$expected = ['session_factory', 'logger', 'session_collector'];
692+
$expected = ['session_factory', 'logger', 'session_collector', 'request_stack'];
693693
$this->assertEquals($expected, array_keys($container->getDefinition('session_listener')->getArgument(0)->getValues()));
694694
$this->assertFalse($container->getDefinition('session.storage.factory.native')->getArgument(3));
695695
}
@@ -1926,7 +1926,7 @@ public function testSessionCookieSecureAuto()
19261926
{
19271927
$container = $this->createContainerFromFile('session_cookie_secure_auto');
19281928

1929-
$expected = ['session_factory', 'logger', 'session_collector'];
1929+
$expected = ['session_factory', 'logger', 'session_collector', 'request_stack'];
19301930
$this->assertEquals($expected, array_keys($container->getDefinition('session_listener')->getArgument(0)->getValues()));
19311931
}
19321932

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ private function parseFileToDOM(string $file): \DOMDocument
483483
}
484484
}
485485
if ($errors) {
486-
throw new InvalidArgumentException(\sprintf('Unable to parse file "%s": ', $file).implode('/n', $errors), $e->getCode(), $e);
486+
throw new InvalidArgumentException(\sprintf('Unable to parse file "%s": ', $file).implode("\n", $errors), $e->getCode(), $e);
487487
}
488488
}
489489

src/Symfony/Component/ExpressionLanguage/Tests/LexerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ public function testTokenizeThrowsErrorOnUnclosedBrace()
5151
$this->lexer->tokenize($expression);
5252
}
5353

54+
public function testTokenizeOnNotOpenedBracket()
55+
{
56+
$this->expectException(SyntaxError::class);
57+
$this->expectExceptionMessage('Unexpected ")" around position 7 for expression `service)not.opened.expression.dummyMethod()`.');
58+
59+
$expression = 'service)not.opened.expression.dummyMethod()';
60+
61+
$this->lexer->tokenize($expression);
62+
}
63+
5464
public static function getTokenizeData()
5565
{
5666
return [

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,14 @@ public function reverseTransform(mixed $value): int|float|null
111111
: \NumberFormatter::TYPE_INT32;
112112
}
113113

114-
$result = $formatter->parse($value, $type, $position);
114+
try {
115+
$result = @$formatter->parse($value, $type, $position);
116+
} catch (\IntlException $e) {
117+
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
118+
}
115119

116120
if (intl_is_failure($formatter->getErrorCode())) {
117-
throw new TransformationFailedException($formatter->getErrorMessage());
121+
throw new TransformationFailedException($formatter->getErrorMessage(), $formatter->getErrorCode());
118122
}
119123

120124
if ($result >= \PHP_INT_MAX || $result <= -\PHP_INT_MAX) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,15 @@ public function reverseTransform(mixed $value): int|float|null
131131
$type = \PHP_INT_SIZE === 8 ? \NumberFormatter::TYPE_INT64 : \NumberFormatter::TYPE_INT32;
132132
}
133133

134-
// replace normal spaces so that the formatter can read them
135-
$result = $formatter->parse(str_replace(' ', "\xc2\xa0", $value), $type, $position);
134+
try {
135+
// replace normal spaces so that the formatter can read them
136+
$result = @$formatter->parse(str_replace(' ', "\xc2\xa0", $value), $type, $position);
137+
} catch (\IntlException $e) {
138+
throw new TransformationFailedException($e->getMessage(), 0, $e);
139+
}
136140

137141
if (intl_is_failure($formatter->getErrorCode())) {
138-
throw new TransformationFailedException($formatter->getErrorMessage());
142+
throw new TransformationFailedException($formatter->getErrorMessage(), $formatter->getErrorCode());
139143
}
140144

141145
if (self::FRACTIONAL == $this->type) {

src/Symfony/Component/Form/Test/FormPerformanceTestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ protected function assertPostConditions(): void
4040
if (0 != $this->maxRunningTime && $time > $this->maxRunningTime) {
4141
$this->fail(\sprintf('expected running time: <= %s but was: %s', $this->maxRunningTime, $time));
4242
}
43+
44+
$this->expectNotToPerformAssertions();
4345
}
4446

4547
/**

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function tearDown(): void
5353

5454
if (\extension_loaded('intl')) {
5555
ini_set('intl.use_exceptions', $this->initialTestCaseUseException);
56-
ini_set('intl.error_level', $this->initialTestCaseUseException);
56+
ini_set('intl.error_level', $this->initialTestCaseErrorLevel);
5757
}
5858
}
5959

@@ -338,12 +338,11 @@ public function testReverseTransformFiveDigitYearsWithTimestamp()
338338
$transformer->reverseTransform('20107-03-21 12:34:56');
339339
}
340340

341+
/**
342+
* @requires extension intl
343+
*/
341344
public function testReverseTransformWrapsIntlErrorsWithErrorLevel()
342345
{
343-
if (!\extension_loaded('intl')) {
344-
$this->markTestSkipped('intl extension is not loaded');
345-
}
346-
347346
$errorLevel = ini_set('intl.error_level', \E_WARNING);
348347

349348
try {
@@ -355,12 +354,11 @@ public function testReverseTransformWrapsIntlErrorsWithErrorLevel()
355354
}
356355
}
357356

357+
/**
358+
* @requires extension intl
359+
*/
358360
public function testReverseTransformWrapsIntlErrorsWithExceptions()
359361
{
360-
if (!\extension_loaded('intl')) {
361-
$this->markTestSkipped('intl extension is not loaded');
362-
}
363-
364362
$initialUseExceptions = ini_set('intl.use_exceptions', 1);
365363

366364
try {
@@ -372,12 +370,11 @@ public function testReverseTransformWrapsIntlErrorsWithExceptions()
372370
}
373371
}
374372

373+
/**
374+
* @requires extension intl
375+
*/
375376
public function testReverseTransformWrapsIntlErrorsWithExceptionsAndErrorLevel()
376377
{
377-
if (!\extension_loaded('intl')) {
378-
$this->markTestSkipped('intl extension is not loaded');
379-
}
380-
381378
$initialUseExceptions = ini_set('intl.use_exceptions', 1);
382379
$initialErrorLevel = ini_set('intl.error_level', \E_WARNING);
383380

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,29 @@ class NumberToLocalizedStringTransformerTest extends TestCase
2020
{
2121
private string $defaultLocale;
2222

23+
private $initialTestCaseUseException;
24+
private $initialTestCaseErrorLevel;
25+
2326
protected function setUp(): void
2427
{
28+
// Normalize intl. configuration settings.
29+
if (\extension_loaded('intl')) {
30+
$this->initialTestCaseUseException = ini_set('intl.use_exceptions', 0);
31+
$this->initialTestCaseErrorLevel = ini_set('intl.error_level', 0);
32+
}
33+
2534
$this->defaultLocale = \Locale::getDefault();
2635
\Locale::setDefault('en');
2736
}
2837

2938
protected function tearDown(): void
3039
{
3140
\Locale::setDefault($this->defaultLocale);
41+
42+
if (\extension_loaded('intl')) {
43+
ini_set('intl.use_exceptions', $this->initialTestCaseUseException);
44+
ini_set('intl.error_level', $this->initialTestCaseErrorLevel);
45+
}
3246
}
3347

3448
public static function provideTransformations()
@@ -647,6 +661,56 @@ public function testReverseTransformENotation($output, $input)
647661
$this->assertSame($output, $transformer->reverseTransform($input));
648662
}
649663

664+
/**
665+
* @requires extension intl
666+
*/
667+
public function testReverseTransformWrapsIntlErrorsWithErrorLevel()
668+
{
669+
$errorLevel = ini_set('intl.error_level', \E_WARNING);
670+
671+
try {
672+
$this->expectException(TransformationFailedException::class);
673+
$transformer = new NumberToLocalizedStringTransformer();
674+
$transformer->reverseTransform('invalid_number');
675+
} finally {
676+
ini_set('intl.error_level', $errorLevel);
677+
}
678+
}
679+
680+
/**
681+
* @requires extension intl
682+
*/
683+
public function testReverseTransformWrapsIntlErrorsWithExceptions()
684+
{
685+
$initialUseExceptions = ini_set('intl.use_exceptions', 1);
686+
687+
try {
688+
$this->expectException(TransformationFailedException::class);
689+
$transformer = new NumberToLocalizedStringTransformer();
690+
$transformer->reverseTransform('invalid_number');
691+
} finally {
692+
ini_set('intl.use_exceptions', $initialUseExceptions);
693+
}
694+
}
695+
696+
/**
697+
* @requires extension intl
698+
*/
699+
public function testReverseTransformWrapsIntlErrorsWithExceptionsAndErrorLevel()
700+
{
701+
$initialUseExceptions = ini_set('intl.use_exceptions', 1);
702+
$initialErrorLevel = ini_set('intl.error_level', \E_WARNING);
703+
704+
try {
705+
$this->expectException(TransformationFailedException::class);
706+
$transformer = new NumberToLocalizedStringTransformer();
707+
$transformer->reverseTransform('invalid_number');
708+
} finally {
709+
ini_set('intl.use_exceptions', $initialUseExceptions);
710+
ini_set('intl.error_level', $initialErrorLevel);
711+
}
712+
}
713+
650714
public static function eNotationProvider(): array
651715
{
652716
return [

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/PercentToLocalizedStringTransformerTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,29 @@ class PercentToLocalizedStringTransformerTest extends TestCase
2020
{
2121
private string $defaultLocale;
2222

23+
private $initialTestCaseUseException;
24+
private $initialTestCaseErrorLevel;
25+
2326
protected function setUp(): void
2427
{
28+
// Normalize intl. configuration settings.
29+
if (\extension_loaded('intl')) {
30+
$this->initialTestCaseUseException = ini_set('intl.use_exceptions', 0);
31+
$this->initialTestCaseErrorLevel = ini_set('intl.error_level', 0);
32+
}
33+
2534
$this->defaultLocale = \Locale::getDefault();
2635
\Locale::setDefault('en');
2736
}
2837

2938
protected function tearDown(): void
3039
{
3140
\Locale::setDefault($this->defaultLocale);
41+
42+
if (\extension_loaded('intl')) {
43+
ini_set('intl.use_exceptions', $this->initialTestCaseUseException);
44+
ini_set('intl.error_level', $this->initialTestCaseErrorLevel);
45+
}
3246
}
3347

3448
public function testTransform()
@@ -475,6 +489,56 @@ public function testReverseTransformForHtml5FormatWithScale()
475489

476490
$this->assertEquals(0.1234, $transformer->reverseTransform('12.34'));
477491
}
492+
493+
/**
494+
* @requires extension intl
495+
*/
496+
public function testReverseTransformWrapsIntlErrorsWithErrorLevel()
497+
{
498+
$errorLevel = ini_set('intl.error_level', \E_WARNING);
499+
500+
try {
501+
$this->expectException(TransformationFailedException::class);
502+
$transformer = new PercentToLocalizedStringTransformer(null, null, \NumberFormatter::ROUND_HALFUP);
503+
$transformer->reverseTransform('invalid_number');
504+
} finally {
505+
ini_set('intl.error_level', $errorLevel);
506+
}
507+
}
508+
509+
/**
510+
* @requires extension intl
511+
*/
512+
public function testReverseTransformWrapsIntlErrorsWithExceptions()
513+
{
514+
$initialUseExceptions = ini_set('intl.use_exceptions', 1);
515+
516+
try {
517+
$this->expectException(TransformationFailedException::class);
518+
$transformer = new PercentToLocalizedStringTransformer(null, null, \NumberFormatter::ROUND_HALFUP);
519+
$transformer->reverseTransform('invalid_number');
520+
} finally {
521+
ini_set('intl.use_exceptions', $initialUseExceptions);
522+
}
523+
}
524+
525+
/**
526+
* @requires extension intl
527+
*/
528+
public function testReverseTransformWrapsIntlErrorsWithExceptionsAndErrorLevel()
529+
{
530+
$initialUseExceptions = ini_set('intl.use_exceptions', 1);
531+
$initialErrorLevel = ini_set('intl.error_level', \E_WARNING);
532+
533+
try {
534+
$this->expectException(TransformationFailedException::class);
535+
$transformer = new PercentToLocalizedStringTransformer(null, null, \NumberFormatter::ROUND_HALFUP);
536+
$transformer->reverseTransform('invalid_number');
537+
} finally {
538+
ini_set('intl.use_exceptions', $initialUseExceptions);
539+
ini_set('intl.error_level', $initialErrorLevel);
540+
}
541+
}
478542
}
479543

480544
class PercentToLocalizedStringTransformerWithoutGrouping extends PercentToLocalizedStringTransformer

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function testUseSessionGcMaxLifetimeAsTimeToLive()
8585

8686
public function testDestroySession()
8787
{
88+
$this->storage->open('', '');
8889
$this->redisClient->set(self::PREFIX.'id', 'foo');
8990

9091
$this->assertTrue((bool) $this->redisClient->exists(self::PREFIX.'id'));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public function testWriteSessionWithLargeTTL()
107107

108108
public function testDestroySession()
109109
{
110+
$this->storage->open('', '');
110111
$this->memcached
111112
->expects($this->once())
112113
->method('delete')

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public function testClose()
5252

5353
public function testDestroy()
5454
{
55+
$this->dualHandler->open('/path/to/save/location', 'xyz');
56+
5557
$sessionId = 'xyz';
5658

5759
$this->currentHandler->expects($this->once())

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ public function testDestroy()
164164
$this->storage->write('foo', 'bar');
165165
$this->storage->write('baz', 'qux');
166166

167+
$this->storage->open('test', 'test');
168+
167169
$this->assertTrue($this->storage->destroy('foo'));
168170

169171
$sessions = $this->getSessions();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ public function testWrongUsageStillWorks()
223223
{
224224
// wrong method sequence that should no happen, but still works
225225
$storage = new PdoSessionHandler($this->getMemorySqlitePdo());
226+
$storage->open('', 'sid');
226227
$storage->write('id', 'data');
227228
$storage->write('other_id', 'other_data');
228229
$storage->destroy('inexistent');

0 commit comments

Comments
 (0)
0