From b31522af7eabcd13839d5172d8f1488f5ec53b53 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Sun, 31 May 2020 11:35:34 +0200 Subject: [PATCH 1/2] Fix branch name --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4ece532..8fb509c 100644 --- a/composer.json +++ b/composer.json @@ -62,7 +62,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.7.x-dev" + "dev-3.x": "3.7.x-dev" } } } From 1f4dfb0b2b95af9dd84715d1dfd2cc7186b324b1 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Sun, 31 May 2020 17:47:18 +0200 Subject: [PATCH 2/2] Add FOSRestBundle 3.x support (#1637) * Add FOSRestBundle 3.x support * fix cs * Update phpunit config * Fix deprecations * Fix tests when running with fosrest < 2.8 * revert change --- .travis.yml | 1 - Tests/Functional/FOSRestTest.php | 6 ----- Tests/Functional/TestKernel.php | 38 ++++++++++++++++++-------------- composer.json | 2 +- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3672859..d8601ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,6 @@ matrix: before_install: - phpenv config-rm xdebug.ini || true - - if [ "$SYMFONY_VERSION" == "^5.0" ]; then composer remove friendsofsymfony/rest-bundle --dev; fi; - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --dev --no-update; fi; install: composer update --no-interaction $COMPOSER_FLAGS diff --git a/Tests/Functional/FOSRestTest.php b/Tests/Functional/FOSRestTest.php index 8b58634..2ddf417 100644 --- a/Tests/Functional/FOSRestTest.php +++ b/Tests/Functional/FOSRestTest.php @@ -11,8 +11,6 @@ namespace Nelmio\ApiDocBundle\Tests\Functional; -use FOS\RestBundle\FOSRestBundle; - class FOSRestTest extends WebTestCase { protected function setUp() @@ -24,10 +22,6 @@ class FOSRestTest extends WebTestCase public function testFOSRestAction() { - if (!class_exists(FOSRestBundle::class)) { - $this->markTestSkipped('FOSRestBundle is not installed.'); - } - $operation = $this->getOperation('/api/fosrest', 'post'); $parameters = $operation->getParameters(); diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index a51526c..d709ac5 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -58,12 +58,9 @@ class TestKernel extends Kernel new ApiPlatformBundle(), new NelmioApiDocBundle(), new TestBundle(), + new FOSRestBundle(), ]; - if (class_exists(FOSRestBundle::class)) { - $bundles[] = new FOSRestBundle(); - } - if ($this->useJMS) { $bundles[] = new JMSSerializerBundle(); @@ -87,15 +84,12 @@ class TestKernel extends Kernel $routes->import('', '/api', 'api_platform'); $routes->add('/docs/{area}', 'nelmio_api_doc.controller.swagger_ui')->setDefault('area', 'default'); $routes->add('/docs.json', 'nelmio_api_doc.controller.swagger'); + $routes->import(__DIR__.'/Controller/FOSRestController.php', '/', 'annotation'); if (class_exists(SerializedName::class)) { $routes->import(__DIR__.'/Controller/SerializedNameController.php', '/', 'annotation'); } - if (class_exists(FOSRestBundle::class)) { - $routes->import(__DIR__.'/Controller/FOSRestController.php', '/', 'annotation'); - } - if ($this->useJMS) { $routes->import(__DIR__.'/Controller/JMSController.php', '/', 'annotation'); } @@ -134,6 +128,7 @@ class TestKernel extends Kernel $c->loadFromExtension('twig', [ 'strict_variables' => '%kernel.debug%', + 'exception_controller' => null, ]); $c->loadFromExtension('sensio_framework_extra', [ @@ -146,16 +141,27 @@ class TestKernel extends Kernel 'mapping' => ['paths' => ['%kernel.project_dir%/Tests/Functional/Entity']], ]); - if (class_exists(FOSRestBundle::class)) { - $c->loadFromExtension('fos_rest', [ - 'format_listener' => [ - 'rules' => [ - [ - 'path' => '^/', - 'fallback_format' => 'json', - ], + $c->loadFromExtension('fos_rest', [ + 'format_listener' => [ + 'rules' => [ + [ + 'path' => '^/', + 'fallback_format' => 'json', ], ], + ], + ]); + + // If FOSRestBundle 2.8 + if (class_exists(\FOS\RestBundle\EventListener\ResponseStatusCodeListener::class)) { + $c->loadFromExtension('fos_rest', [ + 'exception' => [ + 'enabled' => false, + 'exception_listener' => false, + 'serialize_exceptions' => false, + ], + 'body_listener' => false, + 'routing_loader' => false, ]); } diff --git a/composer.json b/composer.json index 8fb509c..393d2cd 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "doctrine/common": "^2.4", "api-platform/core": "^2.1.2", - "friendsofsymfony/rest-bundle": "^2.0", + "friendsofsymfony/rest-bundle": "^2.0|^3.0@beta", "willdurand/hateoas-bundle": "^1.0|^2.0", "jms/serializer-bundle": "^2.3|^3.0", "jms/serializer": "^1.14|^3.0"