Skip to content

Commit bad7b25

Browse files
Merge branch '6.4' into 7.0
* 6.4: move adding detailed JSON error messages to the validate phase [HttpFoundation] Add tests for `MethodRequestMatcher` and `SchemeRequestMatcher`
2 parents 87c2b09 + 35bab84 commit bad7b25

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $e
11121112
->arrayNode('default_context')
11131113
->normalizeKeys(false)
11141114
->useAttributeAsKey('name')
1115-
->beforeNormalization()
1115+
->validate()
11161116
->ifTrue(fn () => $this->debug && class_exists(JsonParser::class))
11171117
->then(fn (array $v) => $v + [JsonDecode::DETAILED_ERROR_MESSAGES => true])
11181118
->end()

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\DBAL\Connection;
1515
use PHPUnit\Framework\TestCase;
16+
use Seld\JsonLint\JsonParser;
1617
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration;
1718
use Symfony\Bundle\FullStack;
1819
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
@@ -566,6 +567,63 @@ public function testEnabledLockNeedsResources()
566567
]);
567568
}
568569

570+
public function testSerializerJsonDetailedErrorMessagesEnabledWhenDefaultContextIsConfigured()
571+
{
572+
$processor = new Processor();
573+
$config = $processor->processConfiguration(new Configuration(true), [
574+
[
575+
'serializer' => [
576+
'default_context' => [
577+
'foo' => 'bar',
578+
],
579+
],
580+
],
581+
]);
582+
583+
$this->assertSame(['foo' => 'bar', JsonDecode::DETAILED_ERROR_MESSAGES => true], $config['serializer']['default_context'] ?? []);
584+
}
585+
586+
public function testSerializerJsonDetailedErrorMessagesInDefaultContextCanBeDisabled()
587+
{
588+
$processor = new Processor();
589+
$config = $processor->processConfiguration(new Configuration(true), [
590+
[
591+
'serializer' => [
592+
'default_context' => [
593+
'foo' => 'bar',
594+
JsonDecode::DETAILED_ERROR_MESSAGES => false,
595+
],
596+
],
597+
],
598+
]);
599+
600+
$this->assertSame(['foo' => 'bar', JsonDecode::DETAILED_ERROR_MESSAGES => false], $config['serializer']['default_context'] ?? []);
601+
}
602+
603+
public function testSerializerJsonDetailedErrorMessagesInDefaultContextCanBeDisabledWithSeveralConfigsBeingMerged()
604+
{
605+
$processor = new Processor();
606+
$config = $processor->processConfiguration(new Configuration(true), [
607+
[
608+
'serializer' => [
609+
'default_context' => [
610+
'foo' => 'bar',
611+
JsonDecode::DETAILED_ERROR_MESSAGES => false,
612+
],
613+
],
614+
],
615+
[
616+
'serializer' => [
617+
'default_context' => [
618+
'foobar' => 'baz',
619+
],
620+
],
621+
],
622+
]);
623+
624+
$this->assertSame(['foo' => 'bar', JsonDecode::DETAILED_ERROR_MESSAGES => false, 'foobar' => 'baz'], $config['serializer']['default_context'] ?? []);
625+
}
626+
569627
protected static function getBundleDefaultConfig()
570628
{
571629
return [

0 commit comments

Comments
 (0)