Skip to content

Commit 1a80394

Browse files
Add reproducable after changes
1 parent 9e8e14f commit 1a80394

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

Tests/Functional/Bundle/TestBundle/Controller/SerializerErrorController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
use Symfony\Component\Form\Extension\Core\Type\TextType;
1717
use Symfony\Component\Validator\Constraints\NotBlank;
1818

19+
class CustomArgumentException extends \Exception
20+
{
21+
}
22+
1923
/**
2024
* Controller to test serialization of various errors and exceptions.
2125
*
@@ -38,6 +42,11 @@ public function invalidArgumentExceptionAction()
3842
throw new \InvalidArgumentException('Invalid argument given.');
3943
}
4044

45+
public function customExceptionAction()
46+
{
47+
throw new CustomArgumentException('Custom exception');
48+
}
49+
4150
/**
4251
* @View
4352
*/

Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ test_serializer_error_invalid_form:
1818
path: /serializer-error/invalid-form.{_format}
1919
defaults: { _controller: FOS\RestBundle\Tests\Functional\Bundle\TestBundle\Controller\SerializerErrorController::invalidFormAction }
2020

21+
test_custom_exception_serializer:
22+
path: /serializer-error/custom-argument-exception.{_format}
23+
defaults: { _controller: FOS\RestBundle\Tests\Functional\Bundle\TestBundle\Controller\SerializerErrorController::customExceptionAction }
24+
2125
# Must be defined before test_version
2226
test_version2:
2327
resource: FOS\RestBundle\Tests\Functional\Bundle\TestBundle\Controller\Version2Controller

Tests/Functional/SerializerErrorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class SerializerErrorTest extends WebTestCase
2222
{
2323
public static function tearDownAfterClass(): void
2424
{
25+
self::deleteTmpDir('CustomFlattenExceptionNormalizer');
2526
self::deleteTmpDir('FlattenExceptionHandlerLegacyFormat');
2627
self::deleteTmpDir('FlattenExceptionHandlerRfc7807Format');
2728
self::deleteTmpDir('FlattenExceptionNormalizerLegacyFormat');
@@ -121,6 +122,23 @@ public function testSerializeExceptionCodeMappedToResponseStatusCodeJsonUsingErr
121122
$this->assertEquals(json_encode($expectedJson), $client->getResponse()->getContent());
122123
}
123124

125+
public function testCustomExceptionSerialization()
126+
{
127+
if (!class_exists(SerializerErrorRenderer::class)) {
128+
$this->markTestSkipped();
129+
}
130+
131+
$this->iniSet('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
132+
133+
$client = $this->createClient(['test_case' => 'CustomFlattenExceptionNormalizer', 'debug' => false]);
134+
$client->request('GET', '/serializer-error/custom-argument-exception.json');
135+
136+
$this->assertEquals(
137+
'{"code":409,"message":"Conflict"}',
138+
$client->getResponse()->getContent()
139+
);
140+
}
141+
124142
public function serializeExceptionCodeMappedToResponseStatusCodeJsonProvider(): array
125143
{
126144
return [
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRestBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
return [
13+
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
14+
new \FOS\RestBundle\FOSRestBundle(),
15+
new \JMS\SerializerBundle\JMSSerializerBundle(),
16+
new \FOS\RestBundle\Tests\Functional\Bundle\TestBundle\TestBundle(),
17+
];
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
imports:
2+
- { resource: ../config/default.yml }
3+
4+
framework:
5+
serializer: true
6+
7+
fos_rest:
8+
exception:
9+
codes:
10+
'FOS\RestBundle\Tests\Functional\Bundle\TestBundle\Controller\CustomArgumentException': 409
11+
enabled: true
12+
map_exception_codes: true
13+
exception_listener: false
14+
serialize_exceptions: false
15+
flatten_exception_format: 'legacy'
16+
serializer_error_renderer: false
17+
serializer:
18+
serialize_null: true
19+
body_listener:
20+
enabled: true
21+
routing_loader: false
22+
view:
23+
formats:
24+
json: true
25+
csv: true

0 commit comments

Comments
 (0)