Skip to content

Commit b9258df

Browse files
committed
move adding detailed JSON error messages to the validate phase
1 parent 9eb3fbb commit b9258df

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $e
11971197
->arrayNode('default_context')
11981198
->normalizeKeys(false)
11991199
->useAttributeAsKey('name')
1200-
->beforeNormalization()
1200+
->validate()
12011201
->ifTrue(fn () => $this->debug && class_exists(JsonParser::class))
12021202
->then(fn (array $v) => $v + [JsonDecode::DETAILED_ERROR_MESSAGES => true])
12031203
->end()

src/Symfony/Bundle/FrameworkBundle/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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy