|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <[email protected]> |
| 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 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace ApiPlatform\Tests\Functional; |
| 15 | + |
| 16 | +use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; |
| 17 | +use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue7287\OperationWithDefaultFormat; |
| 18 | +use ApiPlatform\Tests\SetupClassResourcesTrait; |
| 19 | +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
| 20 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 21 | + |
| 22 | +class ErrorFormatAppKernel extends \AppKernel |
| 23 | +{ |
| 24 | + protected function build(ContainerBuilder $container): void |
| 25 | + { |
| 26 | + parent::build($container); |
| 27 | + $container->addCompilerPass(new class implements CompilerPassInterface { |
| 28 | + public function process(ContainerBuilder $container): void |
| 29 | + { |
| 30 | + $def = $container->getDefinition('api_platform.error_listener'); |
| 31 | + $def->setArgument(5, ['jsonld' => ['application/ld+json']]); |
| 32 | + } |
| 33 | + }); |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +final class ErrorFormatTest extends ApiTestCase |
| 38 | +{ |
| 39 | + use SetupClassResourcesTrait; |
| 40 | + |
| 41 | + protected static function getKernelClass(): string |
| 42 | + { |
| 43 | + return ErrorFormatAppKernel::class; |
| 44 | + } |
| 45 | + |
| 46 | + protected static ?bool $alwaysBootKernel = true; |
| 47 | + |
| 48 | + /** |
| 49 | + * @return class-string[] |
| 50 | + */ |
| 51 | + public static function getResources(): array |
| 52 | + { |
| 53 | + return [OperationWithDefaultFormat::class]; |
| 54 | + } |
| 55 | + |
| 56 | + public function testNotAcceptableXml(): void |
| 57 | + { |
| 58 | + self::createClient()->request('GET', '/operation_with_default_formats', [ |
| 59 | + 'headers' => ['accept' => 'text/xml'], |
| 60 | + ]); |
| 61 | + |
| 62 | + $this->assertJsonContains(['detail' => 'Requested format "text/xml" is not supported. Supported MIME types are "application/ld+json".']); |
| 63 | + $this->assertResponseStatusCodeSame(406); |
| 64 | + } |
| 65 | +} |
0 commit comments