From e15f3d272a80a68a16b4135cd39975b7baf6f8c4 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Tue, 21 Dec 2021 11:08:16 +0100 Subject: [PATCH 1/6] Use an early version of Api-platform with symfony 6 support in one test case --- .github/workflows/continuous-integration.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index fb2871fb3..3679baa67 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -34,6 +34,9 @@ jobs: symfony-require: "5.4.*" - php-version: 8.1 symfony-require: "5.4.*" + - php-version: 8.1 + symfony-require: "5.4.*" + api-platform: "early" steps: - name: "Checkout" @@ -58,6 +61,14 @@ jobs: path: ${{ steps.composercache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} restore-keys: ${{ runner.os }}-composer- + + - name: "Use an early version of Api-platform with symfony 6 support" + if: ${{ matrix.api-platform == 'early' }} + env: + SYMFONY_REQUIRE: "${{ matrix.symfony-require }}" + run: | + composer config repositories.api-platform git https://github.com/PierreRebeilleau/core.git + composer require api-platform/core:dev-test-compatibility --no-update --dev - name: "Install dependencies with composer" env: From 2ade72d0aae64d94024745802a9fb85cf498d6c8 Mon Sep 17 00:00:00 2001 From: Fabiano Roberto Date: Tue, 30 Nov 2021 15:12:38 +0100 Subject: [PATCH 2/6] feat(dependencies): #1913 - upgrade symfony 60 dependencies --- .github/workflows/continuous-integration.yml | 2 +- composer.json | 42 ++++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 3679baa67..e99505fe4 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -35,7 +35,7 @@ jobs: - php-version: 8.1 symfony-require: "5.4.*" - php-version: 8.1 - symfony-require: "5.4.*" + symfony-require: "6.0.*" api-platform: "early" steps: diff --git a/composer.json b/composer.json index 4b035a2f9..eb798711b 100644 --- a/composer.json +++ b/composer.json @@ -21,32 +21,32 @@ "psr/cache": "^1.0|^2.0|^3.0", "psr/container": "^1.0|^2.0", "psr/log": "^1.0|^2.0|^3.0", - "symfony/config": "^4.4|^5.0", - "symfony/console": "^4.4|^5.0", - "symfony/dependency-injection": "^4.4|^5.0", - "symfony/framework-bundle": "^4.4|^5.0", - "symfony/http-foundation": "^4.4|^5.0", - "symfony/http-kernel": "^4.4|^5.0", - "symfony/options-resolver": "^4.4|^5.0", - "symfony/property-info": "^4.4|^5.0", - "symfony/routing": "^4.4|^5.0", + "symfony/config": "^4.4|^5.0|^6.0", + "symfony/console": "^4.4|^5.0|^6.0", + "symfony/dependency-injection": "^4.4|^5.0|^6.0", + "symfony/framework-bundle": "^4.4|^5.0|^6.0", + "symfony/http-foundation": "^4.4|^5.0|^6.0", + "symfony/http-kernel": "^4.4|^5.0|^6.0", + "symfony/options-resolver": "^4.4|^5.0|^6.0", + "symfony/property-info": "^4.4|^5.0|^6.0", + "symfony/routing": "^4.4|^5.0|^6.0", "zircote/swagger-php": "^3.2|^4.0", "phpdocumentor/reflection-docblock": "^3.1|^4.4|^5.0" }, "require-dev": { - "sensio/framework-extra-bundle": "^4.4|^5.0|^6.0", - "symfony/asset": "^4.4|^5.0", - "symfony/dom-crawler": "^4.4|^5.0", - "symfony/browser-kit": "^4.4|^5.0", - "symfony/cache": "^4.4|^5.0", - "symfony/form": "^4.4|^5.0", + "sensio/framework-extra-bundle": "^4.4|^5.2|^6.0", + "symfony/asset": "^4.4|^5.2|^6.0", + "symfony/dom-crawler": "^4.4|^5.2|^6.0", + "symfony/browser-kit": "^4.4|^5.2|^6.0", + "symfony/cache": "^4.4|^5.2|^6.0", + "symfony/form": "^4.4|^5.2|^6.0", "symfony/phpunit-bridge": "^5.2", - "symfony/property-access": "^4.4|^5.0", - "symfony/serializer": "^4.4|^5.0", - "symfony/stopwatch": "^4.4|^5.0", - "symfony/templating": "^4.4|^5.0", - "symfony/twig-bundle": "^4.4|^5.0", - "symfony/validator": "^4.4|^5.0", + "symfony/property-access": "^4.4|^5.2|^6.0", + "symfony/serializer": "^4.4|^5.2|^6.0", + "symfony/stopwatch": "^4.4|^5.2|^6.0", + "symfony/templating": "^4.4|^5.2|^6.0", + "symfony/twig-bundle": "^4.4|^5.2|^6.0", + "symfony/validator": "^4.4|^5.2|^6.0", "api-platform/core": "^2.4", "friendsofsymfony/rest-bundle": "^2.8|^3.0", From e04521ebea87fd8d8a545e6847772678cc28cda4 Mon Sep 17 00:00:00 2001 From: Fabiano Roberto Date: Tue, 30 Nov 2021 15:12:38 +0100 Subject: [PATCH 3/6] Fix usage of configureRoutes in tests --- Tests/Functional/Resources/routes.yaml | 40 ++++++++++++++++++++++++++ Tests/Functional/TestKernel.php | 37 +++++++++++++----------- 2 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 Tests/Functional/Resources/routes.yaml diff --git a/Tests/Functional/Resources/routes.yaml b/Tests/Functional/Resources/routes.yaml new file mode 100644 index 000000000..0e118e90c --- /dev/null +++ b/Tests/Functional/Resources/routes.yaml @@ -0,0 +1,40 @@ +# Resources +test: + resource: ../Controller/TestController.php + type: annotation + +api: + resource: ../Controller/ApiController.php + type: annotation + +class_api: + resource: ../Controller/ClassApiController.php + type: annotation + +undocumented: + resource: ../Controller/UndocumentedController.php + type: annotation + +invokable: + resource: ../Controller/InvokableController.php + type: annotation + +fos_rest: + resource: ../Controller/FOSRestController.php + type: annotation + + +# Controllers +doc_area: + path: /docs/{area} + controller: nelmio_api_doc.controller.swagger_ui + defaults: + area: default + +doc_json: + path: /docs.json + controller: nelmio_api_doc.controller.swagger_json + +doc_yaml: + path: /docs.yaml + controller: nelmio_api_doc.controller.swagger_yaml \ No newline at end of file diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index 3f3f6680a..74de9ecb7 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -30,6 +30,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\HttpKernel\Kernel; +use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; use Symfony\Component\Routing\RouteCollectionBuilder; use Symfony\Component\Serializer\Annotation\SerializedName; @@ -79,39 +80,43 @@ public function registerBundles(): iterable /** * {@inheritdoc} */ - protected function configureRoutes(RouteCollectionBuilder $routes) + protected function configureRoutes($routes) { - $routes->import(__DIR__.'/Controller/TestController.php', '/', 'annotation'); - $routes->import(__DIR__.'/Controller/ApiController.php', '/', 'annotation'); - $routes->import(__DIR__.'/Controller/ClassApiController.php', '/', 'annotation'); - $routes->import(__DIR__.'/Controller/UndocumentedController.php', '/', 'annotation'); - $routes->import(__DIR__.'/Controller/InvokableController.php', '/', 'annotation'); - $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_json'); - $routes->add('/docs.yaml', 'nelmio_api_doc.controller.swagger_yaml'); - $routes->import(__DIR__.'/Controller/FOSRestController.php', '/', 'annotation'); + $this->import($routes, '', '/api', 'api_platform'); + + $this->import($routes, __DIR__.'/Resources/routes.yaml', '/', 'yaml'); if (class_exists(SerializedName::class)) { - $routes->import(__DIR__.'/Controller/SerializedNameController.php', '/', 'annotation'); + $this->import($routes, __DIR__.'/Controller/SerializedNameController.php', '/', 'annotation'); } if ($this->flags & self::USE_JMS) { - $routes->import(__DIR__.'/Controller/JMSController.php', '/', 'annotation'); + $this->import($routes, __DIR__.'/Controller/JMSController.php', '/', 'annotation'); } if ($this->flags & self::USE_BAZINGA) { - $routes->import(__DIR__.'/Controller/BazingaController.php', '/', 'annotation'); + $this->import($routes, __DIR__.'/Controller/BazingaController.php', '/', 'annotation'); try { new \ReflectionMethod(Embedded::class, 'getType'); - $routes->import(__DIR__.'/Controller/BazingaTypedController.php', '/', 'annotation'); + $this->import($routes, __DIR__.'/Controller/BazingaTypedController.php', '/', 'annotation'); } catch (\ReflectionException $e) { } } if ($this->flags & self::ERROR_ARRAY_ITEMS) { - $routes->import(__DIR__.'/Controller/ArrayItemsErrorController.php', '/', 'annotation'); + $this->import($routes, __DIR__.'/Controller/ArrayItemsErrorController.php', '/', 'annotation'); + } + } + + /** + * BC for sf < 5.1. + */ + private function import($routes, $resource, $prefix, $type) { + if ($routes instanceof RoutingConfigurator) { + $routes->withPath($prefix)->import($resource, $type); + } else { + $routes->import($resource, $prefix, $type); } } From b4c74ee9384f1526f51e6dd481439f4f7e24accf Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Tue, 21 Dec 2021 13:41:49 +0100 Subject: [PATCH 4/6] Fix retrieval of container in tests --- Tests/Render/Html/GetNelmioAssetTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Render/Html/GetNelmioAssetTest.php b/Tests/Render/Html/GetNelmioAssetTest.php index 8aea594e3..063393e3b 100644 --- a/Tests/Render/Html/GetNelmioAssetTest.php +++ b/Tests/Render/Html/GetNelmioAssetTest.php @@ -23,7 +23,7 @@ public function test($mode, $asset, $expectedContent) { static::bootKernel(); /** @var GetNelmioAsset $getNelmioAsset */ - $getNelmioAsset = static::$container->get('nelmio_api_doc.render_docs.html.asset'); + $getNelmioAsset = static::getContainer()->get('nelmio_api_doc.render_docs.html.asset'); /** @var TwigFunction */ $twigFunction = $getNelmioAsset->getFunctions()[0]; self::assertSame($expectedContent, $twigFunction->getCallable()->__invoke($mode, $asset)); From 0fada289f5ffe60a5dab541975f2634f044f55ca Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Tue, 21 Dec 2021 13:46:02 +0100 Subject: [PATCH 5/6] Fix CS --- Tests/Functional/TestKernel.php | 4 ++-- Tests/Functional/WebTestCase.php | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index 74de9ecb7..a865e7887 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -31,7 +31,6 @@ use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; -use Symfony\Component\Routing\RouteCollectionBuilder; use Symfony\Component\Serializer\Annotation\SerializedName; class TestKernel extends Kernel @@ -112,7 +111,8 @@ protected function configureRoutes($routes) /** * BC for sf < 5.1. */ - private function import($routes, $resource, $prefix, $type) { + private function import($routes, $resource, $prefix, $type) + { if ($routes instanceof RoutingConfigurator) { $routes->withPath($prefix)->import($resource, $type); } else { diff --git a/Tests/Functional/WebTestCase.php b/Tests/Functional/WebTestCase.php index c792c0d2c..54bfdde56 100644 --- a/Tests/Functional/WebTestCase.php +++ b/Tests/Functional/WebTestCase.php @@ -14,6 +14,7 @@ use OpenApi\Annotations as OA; use OpenApi\Generator; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\KernelInterface; class WebTestCase extends BaseWebTestCase @@ -168,4 +169,16 @@ public function assertNotHasProperty($property, OA\AbstractAnnotation $annotatio sprintf('Failed asserting that property "%s" does not exist.', $property) ); } + + /** + * BC symfony < 5.3 + */ + protected static function getContainer(): ContainerInterface + { + if (method_exists(parent::class, 'getContainer')) { + return parent::getContainer(); + } + + return static::$container; + } } From ab99b4bcb90115c6e6f0131011cc7c01ab1b01e7 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Tue, 21 Dec 2021 13:52:16 +0100 Subject: [PATCH 6/6] Fix api-platform routes import --- Tests/Functional/Resources/routes.yaml | 5 +++++ Tests/Functional/TestKernel.php | 2 -- Tests/Functional/WebTestCase.php | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Tests/Functional/Resources/routes.yaml b/Tests/Functional/Resources/routes.yaml index 0e118e90c..66e8be6fd 100644 --- a/Tests/Functional/Resources/routes.yaml +++ b/Tests/Functional/Resources/routes.yaml @@ -24,6 +24,11 @@ fos_rest: type: annotation +api_platform: + resource: . + prefix: /api + type: api_platform + # Controllers doc_area: path: /docs/{area} diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index a865e7887..58e893cab 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -81,8 +81,6 @@ public function registerBundles(): iterable */ protected function configureRoutes($routes) { - $this->import($routes, '', '/api', 'api_platform'); - $this->import($routes, __DIR__.'/Resources/routes.yaml', '/', 'yaml'); if (class_exists(SerializedName::class)) { diff --git a/Tests/Functional/WebTestCase.php b/Tests/Functional/WebTestCase.php index 54bfdde56..846c59a42 100644 --- a/Tests/Functional/WebTestCase.php +++ b/Tests/Functional/WebTestCase.php @@ -171,7 +171,7 @@ public function assertNotHasProperty($property, OA\AbstractAnnotation $annotatio } /** - * BC symfony < 5.3 + * BC symfony < 5.3. */ protected static function getContainer(): ContainerInterface {