Skip to content

Commit 87d1c9a

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 b11b466 + 6fe0729 commit 87d1c9a

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/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()

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 [

src/Symfony/Component/HttpFoundation/Tests/RequestMatcher/MethodRequestMatcherTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ public function test(string $requestMethod, array|string $matcherMethod, bool $i
2727
$this->assertSame($isMatch, $matcher->matches($request));
2828
}
2929

30+
public function testAlwaysMatchesOnEmptyMethod()
31+
{
32+
$matcher = new MethodRequestMatcher([]);
33+
$request = Request::create('https://example.com', 'POST');
34+
$this->assertTrue($matcher->matches($request));
35+
}
36+
3037
public static function getData()
3138
{
3239
return [

src/Symfony/Component/HttpFoundation/Tests/RequestMatcher/SchemeRequestMatcherTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public function test(string $requestScheme, array|string $matcherScheme, bool $i
4242
}
4343
}
4444

45+
public function testAlwaysMatchesOnParamsHeaders()
46+
{
47+
$matcher = new SchemeRequestMatcher([]);
48+
$request = Request::create('sftp://example.com');
49+
$this->assertTrue($matcher->matches($request));
50+
}
51+
4552
public static function getData()
4653
{
4754
return [

0 commit comments

Comments
 (0)