From 09f71304d073e775c83e11403771c4e736486bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Wed, 15 May 2024 12:28:14 +0200 Subject: [PATCH 01/22] Move fos rest, jms serializer and hateoas on dev requirements --- .github/workflows/build.yml | 3 +- UPGRADE.md | 10 ++++++ composer.json | 13 +++++--- .../ResourcesCollectionProvider.php | 16 ++++----- src/Bundle/Controller/ViewHandler.php | 8 ++--- .../Compiler/FosRestPass.php | 33 +++++++++++++++++++ .../Compiler/HateoasPass.php | 33 +++++++++++++++++++ .../Resources/config/services/controller.xml | 4 +-- src/Bundle/SyliusResourceBundle.php | 4 +++ 9 files changed, 104 insertions(+), 20 deletions(-) create mode 100644 src/Bundle/DependencyInjection/Compiler/FosRestPass.php create mode 100644 src/Bundle/DependencyInjection/Compiler/HateoasPass.php diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e2c94a67e..74a9e1780 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -157,8 +157,9 @@ jobs: - name: Run smoke tests without friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle packages run: | - composer remove friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts + composer remove --dev friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts (cd tests/Application && bin/console cache:clear --env=test_without_fosrest) + (cd tests/Application && bin/console lint:container --env=test_without_fosrest) composer require friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts - diff --git a/UPGRADE.md b/UPGRADE.md index 36106ecd4..74bced9fd 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,13 @@ +## UPGRADE FOR `1.12.x` + +### FROM `1.11.x` to `1.12.x` + +We move these following dependencies on optional requirements, so explicit them in your app requirements if you need them. + +* friendsofsymfony/rest-bundle +* jms/serializer-bundle +* willdurand/hateoas-bundle + ## UPGRADE FOR `1.11.x` ### FROM `1.10.x` to `1.11.x` diff --git a/composer.json b/composer.json index e2a28132e..636891186 100644 --- a/composer.json +++ b/composer.json @@ -33,9 +33,7 @@ "doctrine/event-manager": "^1.1", "doctrine/inflector": "^1.4 || ^2.0", "doctrine/persistence": "^2.0 || ^3.0", - "friendsofsymfony/rest-bundle": "^3.0", "gedmo/doctrine-extensions": "^2.4.12 || ^3.0", - "jms/serializer-bundle": "^3.5 || ^4.0 || ^5.0", "sylius/registry": "^1.2", "symfony/config": "^5.4 || ^6.4", "symfony/deprecation-contracts": "^2.1 || ^3.0", @@ -52,7 +50,6 @@ "symfony/validator": "^5.4 || ^6.4", "symfony/yaml": "^5.4 || ^6.4", "webmozart/assert": "^1.8", - "willdurand/hateoas-bundle": "^2.0", "winzou/state-machine-bundle": "^0.6", "willdurand/negotiation": "^3.1" }, @@ -61,6 +58,8 @@ }, "require-dev": { "doctrine/orm": "^2.5", + "friendsofsymfony/rest-bundle": "^3.0", + "jms/serializer-bundle": "^3.5 || ^4.0 || ^5.0", "lchrusciel/api-test-case": "^5.0", "matthiasnoback/symfony-dependency-injection-test": "^4.2.1", "pagerfanta/pagerfanta": "^3.7 || ^4.0", @@ -84,7 +83,13 @@ "rector/rector": "^0.18.2", "symfony/messenger": "^5.4 || ^6.4", "symfony/serializer": "^5.4 || ^6.4", - "symfony/security-bundle": "^5.4 || ^6.4" + "symfony/security-bundle": "^5.4 || ^6.4", + "willdurand/hateoas-bundle": "^2.0" + }, + "conflict": { + "friendsofsymfony/rest-bundle": "<3.0", + "jms/serializer-bundle": "<3.5", + "willdurand/hateoas-bundle": "<2.0" }, "suggest": { "doctrine/orm": "^2.5", diff --git a/src/Bundle/Controller/ResourcesCollectionProvider.php b/src/Bundle/Controller/ResourcesCollectionProvider.php index eafc139de..34c159eee 100644 --- a/src/Bundle/Controller/ResourcesCollectionProvider.php +++ b/src/Bundle/Controller/ResourcesCollectionProvider.php @@ -21,14 +21,10 @@ final class ResourcesCollectionProvider implements ResourcesCollectionProviderInterface { - private ResourcesResolverInterface $resourcesResolver; - - private PagerfantaFactory $pagerfantaRepresentationFactory; - - public function __construct(ResourcesResolverInterface $resourcesResolver, PagerfantaFactory $pagerfantaRepresentationFactory) - { - $this->resourcesResolver = $resourcesResolver; - $this->pagerfantaRepresentationFactory = $pagerfantaRepresentationFactory; + public function __construct( + private ResourcesResolverInterface $resourcesResolver, + private ?PagerfantaFactory $pagerfantaRepresentationFactory = null, + ) { } /** @@ -61,6 +57,10 @@ public function get(RequestConfiguration $requestConfiguration, RepositoryInterf $paginator->getCurrentPageResults(); if (!$requestConfiguration->isHtmlRequest()) { + if (null === $this->pagerfantaRepresentationFactory) { + throw new \LogicException('The "willdurand/hateoas-bundle" must be installed and configured to render a resource collection on non-HTML request. Try running "composer require willdurand/hateoas-bundle"'); + } + $route = new Route($request->attributes->get('_route'), array_merge($request->attributes->get('_route_params'), $request->query->all())); return $this->pagerfantaRepresentationFactory->createRepresentation($paginator, $route); diff --git a/src/Bundle/Controller/ViewHandler.php b/src/Bundle/Controller/ViewHandler.php index f0d16b757..e23fcb1d3 100644 --- a/src/Bundle/Controller/ViewHandler.php +++ b/src/Bundle/Controller/ViewHandler.php @@ -19,11 +19,8 @@ final class ViewHandler implements ViewHandlerInterface { - private ConfigurableViewHandlerInterface $restViewHandler; - - public function __construct(ConfigurableViewHandlerInterface $restViewHandler) + public function __construct(private ConfigurableViewHandlerInterface $restViewHandler) { - $this->restViewHandler = $restViewHandler; } public function handle(RequestConfiguration $requestConfiguration, View $view): Response @@ -31,7 +28,8 @@ public function handle(RequestConfiguration $requestConfiguration, View $view): if (!$requestConfiguration->isHtmlRequest()) { $this->restViewHandler->setExclusionStrategyGroups($requestConfiguration->getSerializationGroups() ?? []); - if ($version = $requestConfiguration->getSerializationVersion()) { + $version = $requestConfiguration->getSerializationVersion(); + if (null !== $version) { $this->restViewHandler->setExclusionStrategyVersion($version); } diff --git a/src/Bundle/DependencyInjection/Compiler/FosRestPass.php b/src/Bundle/DependencyInjection/Compiler/FosRestPass.php new file mode 100644 index 000000000..f56737f6d --- /dev/null +++ b/src/Bundle/DependencyInjection/Compiler/FosRestPass.php @@ -0,0 +1,33 @@ +getParameter('kernel.bundles'); + + if (in_array(FOSRestBundle::class, $bundles, true)) { + return; + } + + $container->removeDefinition('sylius.resource_controller.view_handler'); + } +} diff --git a/src/Bundle/DependencyInjection/Compiler/HateoasPass.php b/src/Bundle/DependencyInjection/Compiler/HateoasPass.php new file mode 100644 index 000000000..5a5744389 --- /dev/null +++ b/src/Bundle/DependencyInjection/Compiler/HateoasPass.php @@ -0,0 +1,33 @@ +getParameter('kernel.bundles'); + + if (in_array(BazingaHateoasBundle::class, $bundles, true)) { + return; + } + + $container->removeDefinition('sylius.resource_controller.pagerfanta_representation_factory'); + } +} diff --git a/src/Bundle/Resources/config/services/controller.xml b/src/Bundle/Resources/config/services/controller.xml index 6bf356350..ab8c86919 100644 --- a/src/Bundle/Resources/config/services/controller.xml +++ b/src/Bundle/Resources/config/services/controller.xml @@ -50,7 +50,7 @@ - + @@ -80,7 +80,7 @@ - + diff --git a/src/Bundle/SyliusResourceBundle.php b/src/Bundle/SyliusResourceBundle.php index 6d992d4ae..d352b3beb 100644 --- a/src/Bundle/SyliusResourceBundle.php +++ b/src/Bundle/SyliusResourceBundle.php @@ -16,6 +16,8 @@ use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\CsrfTokenManagerPass; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\DoctrineContainerRepositoryFactoryPass; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\DoctrineTargetEntitiesResolverPass; +use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\FosRestPass; +use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\HateoasPass; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\Helper\TargetEntitiesResolver; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\PagerfantaBridgePass; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterFormBuilderPass; @@ -50,6 +52,8 @@ public function build(ContainerBuilder $container): void $container->addCompilerPass(new DisableMetadataCachePass()); $container->addCompilerPass(new DoctrineContainerRepositoryFactoryPass()); $container->addCompilerPass(new DoctrineTargetEntitiesResolverPass(new TargetEntitiesResolver()), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1); + $container->addCompilerPass(new FosRestPass()); + $container->addCompilerPass(new HateoasPass()); $container->addCompilerPass(new RegisterFormBuilderPass()); $container->addCompilerPass(new RegisterFqcnControllersPass()); $container->addCompilerPass(new RegisterResourceRepositoryPass()); From f3b4b749d84934e0463a71195d49457dac9c5885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Wed, 15 May 2024 15:42:56 +0200 Subject: [PATCH 02/22] Add tests for compiler passes --- .../Compiler/FosRestPassTest.php | 51 +++++++++++++++++++ .../Compiler/HateoasPassTest.php | 51 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 tests/Bundle/DependencyInjection/Compiler/FosRestPassTest.php create mode 100644 tests/Bundle/DependencyInjection/Compiler/HateoasPassTest.php diff --git a/tests/Bundle/DependencyInjection/Compiler/FosRestPassTest.php b/tests/Bundle/DependencyInjection/Compiler/FosRestPassTest.php new file mode 100644 index 000000000..ebecaed4e --- /dev/null +++ b/tests/Bundle/DependencyInjection/Compiler/FosRestPassTest.php @@ -0,0 +1,51 @@ +setParameter('kernel.bundles', []); + + $this->compile(); + + $this->assertContainerBuilderNotHasService('sylius.resource_controller.view_handler'); + } + + /** @test */ + public function it_keeps_the_view_handler_if_fos_rest_is_available(): void + { + $this->setParameter('kernel.bundles', [FOSRestBundle::class]); + + $this->compile(); + + $this->assertContainerBuilderHasService('sylius.resource_controller.view_handler'); + } + + protected function registerCompilerPass(ContainerBuilder $container): void + { + $this->registerService('sylius.resource_controller.view_handler', ViewHandler::class); + $this->setParameter('kernel.bundles', []); + + $container->addCompilerPass(new FosRestPass()); + } +} diff --git a/tests/Bundle/DependencyInjection/Compiler/HateoasPassTest.php b/tests/Bundle/DependencyInjection/Compiler/HateoasPassTest.php new file mode 100644 index 000000000..73397541c --- /dev/null +++ b/tests/Bundle/DependencyInjection/Compiler/HateoasPassTest.php @@ -0,0 +1,51 @@ +setParameter('kernel.bundles', []); + + $this->compile(); + + $this->assertContainerBuilderNotHasService('sylius.resource_controller.pagerfanta_representation_factory'); + } + + /** @test */ + public function it_keeps_the_view_handler_if_fos_rest_is_available(): void + { + $this->setParameter('kernel.bundles', [BazingaHateoasBundle::class]); + + $this->compile(); + + $this->assertContainerBuilderHasService('sylius.resource_controller.pagerfanta_representation_factory'); + } + + protected function registerCompilerPass(ContainerBuilder $container): void + { + $this->registerService('sylius.resource_controller.pagerfanta_representation_factory', PagerfantaFactory::class); + $this->setParameter('kernel.bundles', []); + + $container->addCompilerPass(new HateoasPass()); + } +} From 2bf5833053734393082ce74ca59d0bb2909836a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Wed, 15 May 2024 16:02:50 +0200 Subject: [PATCH 03/22] Fix step name --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 74a9e1780..fabab144d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -155,7 +155,7 @@ jobs: sed -i -e 's/state_machine_component: symfony/state_machine_component: winzou/g' tests/Application/config/packages/test/sylius_resource.yaml - - name: Run smoke tests without friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle packages + name: Run lint container without friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle packages run: | composer remove --dev friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts (cd tests/Application && bin/console cache:clear --env=test_without_fosrest) From bbe3741c01611ab050bd207a462e2ea686f55d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 16 May 2024 09:36:18 +0200 Subject: [PATCH 04/22] Apply suggestions from code review Co-authored-by: Dmitri Perunov --- UPGRADE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UPGRADE.md b/UPGRADE.md index 74bced9fd..51df9729f 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2,7 +2,7 @@ ### FROM `1.11.x` to `1.12.x` -We move these following dependencies on optional requirements, so explicit them in your app requirements if you need them. +In preparation of removal, following dependencies were moved to optional requirements. If still in use by your app, require them explicitly in your `composer.json`. * friendsofsymfony/rest-bundle * jms/serializer-bundle From bb3aeae8e2910a42119d1a679538577f743709e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 16 May 2024 09:41:21 +0200 Subject: [PATCH 05/22] Rename compiler passes --- ...sRestPass.php => UnregisterFosRestDefinitionsPass.php} | 2 +- ...teoasPass.php => UnregisterHateoasDefinitionsPass.php} | 2 +- src/Bundle/SyliusResourceBundle.php | 8 ++++---- ...sTest.php => UnregisterFosRestDefinitionsPassTest.php} | 6 +++--- ...sTest.php => UnregisterHateoasDefinitionsPassTest.php} | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) rename src/Bundle/DependencyInjection/Compiler/{FosRestPass.php => UnregisterFosRestDefinitionsPass.php} (91%) rename src/Bundle/DependencyInjection/Compiler/{HateoasPass.php => UnregisterHateoasDefinitionsPass.php} (91%) rename tests/Bundle/DependencyInjection/Compiler/{FosRestPassTest.php => UnregisterFosRestDefinitionsPassTest.php} (83%) rename tests/Bundle/DependencyInjection/Compiler/{HateoasPassTest.php => UnregisterHateoasDefinitionsPassTest.php} (84%) diff --git a/src/Bundle/DependencyInjection/Compiler/FosRestPass.php b/src/Bundle/DependencyInjection/Compiler/UnregisterFosRestDefinitionsPass.php similarity index 91% rename from src/Bundle/DependencyInjection/Compiler/FosRestPass.php rename to src/Bundle/DependencyInjection/Compiler/UnregisterFosRestDefinitionsPass.php index f56737f6d..3d687d5e9 100644 --- a/src/Bundle/DependencyInjection/Compiler/FosRestPass.php +++ b/src/Bundle/DependencyInjection/Compiler/UnregisterFosRestDefinitionsPass.php @@ -17,7 +17,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; -final class FosRestPass implements CompilerPassInterface +final class UnregisterFosRestDefinitionsPass implements CompilerPassInterface { public function process(ContainerBuilder $container): void { diff --git a/src/Bundle/DependencyInjection/Compiler/HateoasPass.php b/src/Bundle/DependencyInjection/Compiler/UnregisterHateoasDefinitionsPass.php similarity index 91% rename from src/Bundle/DependencyInjection/Compiler/HateoasPass.php rename to src/Bundle/DependencyInjection/Compiler/UnregisterHateoasDefinitionsPass.php index 5a5744389..62288351c 100644 --- a/src/Bundle/DependencyInjection/Compiler/HateoasPass.php +++ b/src/Bundle/DependencyInjection/Compiler/UnregisterHateoasDefinitionsPass.php @@ -17,7 +17,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; -final class HateoasPass implements CompilerPassInterface +final class UnregisterHateoasDefinitionsPass implements CompilerPassInterface { public function process(ContainerBuilder $container): void { diff --git a/src/Bundle/SyliusResourceBundle.php b/src/Bundle/SyliusResourceBundle.php index d352b3beb..29eca8e69 100644 --- a/src/Bundle/SyliusResourceBundle.php +++ b/src/Bundle/SyliusResourceBundle.php @@ -16,8 +16,6 @@ use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\CsrfTokenManagerPass; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\DoctrineContainerRepositoryFactoryPass; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\DoctrineTargetEntitiesResolverPass; -use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\FosRestPass; -use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\HateoasPass; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\Helper\TargetEntitiesResolver; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\PagerfantaBridgePass; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterFormBuilderPass; @@ -27,6 +25,8 @@ use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterResourceStateMachinePass; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterStateMachinePass; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\TwigPass; +use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\UnregisterFosRestDefinitionsPass; +use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\UnregisterHateoasDefinitionsPass; use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\WinzouStateMachinePass; use Sylius\Bundle\ResourceBundle\DependencyInjection\PagerfantaExtension; use Sylius\Resource\Symfony\DependencyIjection\Compiler\DisableMetadataCachePass; @@ -52,14 +52,14 @@ public function build(ContainerBuilder $container): void $container->addCompilerPass(new DisableMetadataCachePass()); $container->addCompilerPass(new DoctrineContainerRepositoryFactoryPass()); $container->addCompilerPass(new DoctrineTargetEntitiesResolverPass(new TargetEntitiesResolver()), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1); - $container->addCompilerPass(new FosRestPass()); - $container->addCompilerPass(new HateoasPass()); $container->addCompilerPass(new RegisterFormBuilderPass()); $container->addCompilerPass(new RegisterFqcnControllersPass()); $container->addCompilerPass(new RegisterResourceRepositoryPass()); $container->addCompilerPass(new RegisterResourcesPass()); $container->addCompilerPass(new RegisterStateMachinePass()); $container->addCompilerPass(new RegisterResourceStateMachinePass()); + $container->addCompilerPass(new UnregisterFosRestDefinitionsPass()); + $container->addCompilerPass(new UnregisterHateoasDefinitionsPass()); $container->addCompilerPass(new TwigPass()); $container->addCompilerPass(new WinzouStateMachinePass()); diff --git a/tests/Bundle/DependencyInjection/Compiler/FosRestPassTest.php b/tests/Bundle/DependencyInjection/Compiler/UnregisterFosRestDefinitionsPassTest.php similarity index 83% rename from tests/Bundle/DependencyInjection/Compiler/FosRestPassTest.php rename to tests/Bundle/DependencyInjection/Compiler/UnregisterFosRestDefinitionsPassTest.php index ebecaed4e..b8eb95224 100644 --- a/tests/Bundle/DependencyInjection/Compiler/FosRestPassTest.php +++ b/tests/Bundle/DependencyInjection/Compiler/UnregisterFosRestDefinitionsPassTest.php @@ -16,10 +16,10 @@ use FOS\RestBundle\FOSRestBundle; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; use Sylius\Bundle\ResourceBundle\Controller\ViewHandler; -use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\FosRestPass; +use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\UnregisterFosRestDefinitionsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; -final class FosRestPassTest extends AbstractCompilerPassTestCase +final class UnregisterFosRestDefinitionsPassTest extends AbstractCompilerPassTestCase { /** @test */ public function it_remove_view_handler_if_fos_rest_is_not_available(): void @@ -46,6 +46,6 @@ protected function registerCompilerPass(ContainerBuilder $container): void $this->registerService('sylius.resource_controller.view_handler', ViewHandler::class); $this->setParameter('kernel.bundles', []); - $container->addCompilerPass(new FosRestPass()); + $container->addCompilerPass(new UnregisterFosRestDefinitionsPass()); } } diff --git a/tests/Bundle/DependencyInjection/Compiler/HateoasPassTest.php b/tests/Bundle/DependencyInjection/Compiler/UnregisterHateoasDefinitionsPassTest.php similarity index 84% rename from tests/Bundle/DependencyInjection/Compiler/HateoasPassTest.php rename to tests/Bundle/DependencyInjection/Compiler/UnregisterHateoasDefinitionsPassTest.php index 73397541c..57fa21100 100644 --- a/tests/Bundle/DependencyInjection/Compiler/HateoasPassTest.php +++ b/tests/Bundle/DependencyInjection/Compiler/UnregisterHateoasDefinitionsPassTest.php @@ -16,10 +16,10 @@ use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle; use Hateoas\Representation\Factory\PagerfantaFactory; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; -use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\HateoasPass; +use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\UnregisterHateoasDefinitionsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; -final class HateoasPassTest extends AbstractCompilerPassTestCase +final class UnregisterHateoasDefinitionsPassTest extends AbstractCompilerPassTestCase { /** @test */ public function it_remove_pagerfanta_representation_factory_if_hateoas_is_not_available(): void @@ -46,6 +46,6 @@ protected function registerCompilerPass(ContainerBuilder $container): void $this->registerService('sylius.resource_controller.pagerfanta_representation_factory', PagerfantaFactory::class); $this->setParameter('kernel.bundles', []); - $container->addCompilerPass(new HateoasPass()); + $container->addCompilerPass(new UnregisterHateoasDefinitionsPass()); } } From 290f142afa4d09a61d1c06dc112933b21d37309a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 23 May 2024 09:19:49 +0200 Subject: [PATCH 06/22] Allow SF7 on dependencies --- .github/workflows/build.yml | 2 ++ composer.json | 44 ++++++++++++++++++------------------- src/Component/composer.json | 26 +++++++++++----------- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fabab144d..b7056436d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,6 +26,8 @@ jobs: - php: "8.1" pagerfanta: "^3.7" symfony: "^5.4" + - php: 8.3 + symfony: "^7.0" exclude: - php: "8.1" collections: "^2.0" diff --git a/composer.json b/composer.json index 636891186..c135af222 100644 --- a/composer.json +++ b/composer.json @@ -35,20 +35,20 @@ "doctrine/persistence": "^2.0 || ^3.0", "gedmo/doctrine-extensions": "^2.4.12 || ^3.0", "sylius/registry": "^1.2", - "symfony/config": "^5.4 || ^6.4", + "symfony/config": "^5.4 || ^6.4 || ^7.0", "symfony/deprecation-contracts": "^2.1 || ^3.0", - "symfony/expression-language": "^5.4 || ^6.4", - "symfony/form": "^5.4 || ^6.4", - "symfony/framework-bundle": "^5.4 || ^6.4", - "symfony/http-foundation": "^5.4 || ^6.4", - "symfony/intl": "^5.4 || ^6.4", - "symfony/security-core": "^5.4 || ^6.4", - "symfony/security-csrf": "^5.4 || ^6.4", - "symfony/routing": "^5.4 || ^6.4", - "symfony/translation": "^5.4 || ^6.4", - "symfony/twig-bundle": "^5.4 || ^6.4", - "symfony/validator": "^5.4 || ^6.4", - "symfony/yaml": "^5.4 || ^6.4", + "symfony/expression-language": "^5.4 || ^6.4 || ^7.0", + "symfony/form": "^5.4 || ^6.4 || ^7.0", + "symfony/framework-bundle": "^5.4 || ^6.4 || ^7.0", + "symfony/http-foundation": "^5.4 || ^6.4 || ^7.0", + "symfony/intl": "^5.4 || ^6.4 || ^7.0", + "symfony/security-core": "^5.4 || ^6.4 || ^7.0", + "symfony/security-csrf": "^5.4 || ^6.4 || ^7.0", + "symfony/routing": "^5.4 || ^6.4 || ^7.0", + "symfony/translation": "^5.4 || ^6.4 || ^7.0", + "symfony/twig-bundle": "^5.4 || ^6.4 || ^7.0", + "symfony/validator": "^5.4 || ^6.4 || ^7.0", + "symfony/yaml": "^5.4 || ^6.4 || ^7.0", "webmozart/assert": "^1.8", "winzou/state-machine-bundle": "^0.6", "willdurand/negotiation": "^3.1" @@ -72,18 +72,18 @@ "phpunit/phpunit": "^9.5", "sylius-labs/coding-standard": "^4.0", "sylius/grid-bundle": "^1.7 || v1.12.0-ALPHA.1", - "symfony/console": "^5.4 || ^6.4", - "symfony/dependency-injection": "^5.4 || ^6.4", - "symfony/dotenv": "^5.4 || ^6.4", - "symfony/stopwatch": "^5.4 || ^6.4", - "symfony/uid": "^5.4 || ^6.4", - "symfony/workflow": "^5.4 || ^6.4", + "symfony/console": "^5.4 || ^6.4 || ^7.0", + "symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0", + "symfony/dotenv": "^5.4 || ^6.4 || ^7.0", + "symfony/stopwatch": "^5.4 || ^6.4 || ^7.0", + "symfony/uid": "^5.4 || ^6.4 || ^7.0", + "symfony/workflow": "^5.4 || ^6.4 || ^7.0", "twig/twig": "^2.12 || ^3.0", "vimeo/psalm": "^5.20", "rector/rector": "^0.18.2", - "symfony/messenger": "^5.4 || ^6.4", - "symfony/serializer": "^5.4 || ^6.4", - "symfony/security-bundle": "^5.4 || ^6.4", + "symfony/messenger": "^5.4 || ^6.4 || ^7.0", + "symfony/serializer": "^5.4 || ^6.4 || ^7.0", + "symfony/security-bundle": "^5.4 || ^6.4 || ^7.0", "willdurand/hateoas-bundle": "^2.0" }, "conflict": { diff --git a/src/Component/composer.json b/src/Component/composer.json index fa1ff149b..04c69ee61 100644 --- a/src/Component/composer.json +++ b/src/Component/composer.json @@ -32,17 +32,17 @@ "doctrine/inflector": "^1.4 || ^2.0", "gedmo/doctrine-extensions": "^2.4.12 || ^3.0", "pagerfanta/core": "^3.7 || ^4.0", - "symfony/event-dispatcher": "^5.4 || ^6.4", - "symfony/form": "^5.4 || ^6.4", - "symfony/http-foundation": "^5.4 || ^6.4", - "symfony/http-kernel": "^5.4 || ^6.4", - "symfony/property-access": "^5.4 || ^6.4", - "symfony/routing": "^5.4 || ^6.4", - "symfony/security-core": "^5.4 || ^6.4", - "symfony/security-csrf": "^5.4 || ^6.4", - "symfony/string": "^5.4 || ^6.4", - "symfony/translation": "^5.4 || ^6.4", - "symfony/validator": "^5.4 || ^6.4", + "symfony/event-dispatcher": "^5.4 || ^6.4 || ^7.0", + "symfony/form": "^5.4 || ^6.4 || ^7.0", + "symfony/http-foundation": "^5.4 || ^6.4 || ^7.0", + "symfony/http-kernel": "^5.4 || ^6.4 || ^7.0", + "symfony/property-access": "^5.4 || ^6.4 || ^7.0", + "symfony/routing": "^5.4 || ^6.4 || ^7.0", + "symfony/security-core": "^5.4 || ^6.4 || ^7.0", + "symfony/security-csrf": "^5.4 || ^6.4 || ^7.0", + "symfony/string": "^5.4 || ^6.4 || ^7.0", + "symfony/translation": "^5.4 || ^6.4 || ^7.0", + "symfony/validator": "^5.4 || ^6.4 || ^7.0", "willdurand/negotiation": "^3.1", "winzou/state-machine": "^0.4" }, @@ -54,8 +54,8 @@ "phpspec/prophecy-phpunit": "^2.0", "phpunit/phpunit": "^9.5", "sylius/grid": "^1.7 || ^1.12", - "symfony/serializer": "^5.4 || ^6.4", - "symfony/workflow": "^5.4 || ^6.4", + "symfony/serializer": "^5.4 || ^6.4 || ^7.0", + "symfony/workflow": "^5.4 || ^6.4 || ^7.0", "twig/twig": "^2.12 || ^3.0" }, "extra": { From 281ac9d84f52bfbf957055b8712b066278d28fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 23 May 2024 15:27:35 +0200 Subject: [PATCH 07/22] SF7 Fix the sf7 build --- .github/workflows/build.yml | 4 ++++ Dockerfile | 2 ++ composer.json | 3 +++ 3 files changed, 9 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b7056436d..4cced2d40 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,6 +13,7 @@ on: jobs: tests: runs-on: ubuntu-latest + continue-on-error: ${{ matrix.experimental }} name: "PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, Twig ${{ matrix.twig }}, Persistence: ${{ matrix.persistence }}, Collections: ${{ matrix.collections }}" strategy: fail-fast: false @@ -22,12 +23,15 @@ jobs: symfony: ["^5.4", "^6.4"] persistence: ["^2.0", "^3.0"] collections: ["^1.8", "^2.0"] + experimental: [false] include: - php: "8.1" pagerfanta: "^3.7" symfony: "^5.4" + experimental: false - php: 8.3 symfony: "^7.0" + experimental: true exclude: - php: "8.1" collections: "^2.0" diff --git a/Dockerfile b/Dockerfile index f984fdcc7..f95848270 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,8 @@ COPY . /app WORKDIR /app +RUN composer global config --no-plugins allow-plugins.symfony/flex true +RUN composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10" RUN composer update --with-all-dependencies --no-interaction --no-progress WORKDIR /app/tests/Application diff --git a/composer.json b/composer.json index c135af222..a70e02ea4 100644 --- a/composer.json +++ b/composer.json @@ -104,6 +104,9 @@ "extra": { "branch-alias": { "dev-master": "1.10-dev" + }, + "symfony": { + "require": "^6.4" } }, "autoload": { From 7e0d2eb97683ca143b3df1cfe646b5914c0c9b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 23 May 2024 09:23:48 +0200 Subject: [PATCH 08/22] Bump symfony-dependency-injection-test --- composer.json | 2 +- src/Component/composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a70e02ea4..07dc4b072 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,7 @@ "friendsofsymfony/rest-bundle": "^3.0", "jms/serializer-bundle": "^3.5 || ^4.0 || ^5.0", "lchrusciel/api-test-case": "^5.0", - "matthiasnoback/symfony-dependency-injection-test": "^4.2.1", + "matthiasnoback/symfony-dependency-injection-test": "^4.2.1 || ^5.1", "pagerfanta/pagerfanta": "^3.7 || ^4.0", "pamil/phpspec-skip-example-extension": "^4.2", "phpspec/phpspec": "^7.3", diff --git a/src/Component/composer.json b/src/Component/composer.json index 04c69ee61..947f4be89 100644 --- a/src/Component/composer.json +++ b/src/Component/composer.json @@ -49,7 +49,7 @@ "require-dev": { "behat/transliterator": "^1.3", "doctrine/orm": "^2.5", - "matthiasnoback/symfony-dependency-injection-test": "^4.2.1", + "matthiasnoback/symfony-dependency-injection-test": "^4.2.1 || ^5.1", "phpspec/phpspec": "^7.3", "phpspec/prophecy-phpunit": "^2.0", "phpunit/phpunit": "^9.5", From 8d1fd4c103a1cd76961cb4b0e4ba931d0189dc64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 23 May 2024 10:27:30 +0200 Subject: [PATCH 09/22] [SF7] Bump grid version --- composer.json | 2 +- src/Component/composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 07dc4b072..016b1b24a 100644 --- a/composer.json +++ b/composer.json @@ -71,7 +71,7 @@ "phpstan/phpstan-webmozart-assert": "^1.2", "phpunit/phpunit": "^9.5", "sylius-labs/coding-standard": "^4.0", - "sylius/grid-bundle": "^1.7 || v1.12.0-ALPHA.1", + "sylius/grid-bundle": "^1.7 || dev-symfony-7", "symfony/console": "^5.4 || ^6.4 || ^7.0", "symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0", "symfony/dotenv": "^5.4 || ^6.4 || ^7.0", diff --git a/src/Component/composer.json b/src/Component/composer.json index 947f4be89..a1feeb74a 100644 --- a/src/Component/composer.json +++ b/src/Component/composer.json @@ -53,7 +53,7 @@ "phpspec/phpspec": "^7.3", "phpspec/prophecy-phpunit": "^2.0", "phpunit/phpunit": "^9.5", - "sylius/grid": "^1.7 || ^1.12", + "sylius/grid": "^1.7 || dev-symfony-7", "symfony/serializer": "^5.4 || ^6.4 || ^7.0", "symfony/workflow": "^5.4 || ^6.4 || ^7.0", "twig/twig": "^2.12 || ^3.0" From 3a28e67f7f8286064566d2fcd84d684cbd46770b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 23 May 2024 10:35:17 +0200 Subject: [PATCH 10/22] [SF7] Bump Doctrine event manager version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 016b1b24a..e23223c6f 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "doctrine/annotations": "^2.0", "doctrine/collections": "^1.8 || ^2.0", "doctrine/doctrine-bundle": "^2.0", - "doctrine/event-manager": "^1.1", + "doctrine/event-manager": "^1.1 || ^2.0", "doctrine/inflector": "^1.4 || ^2.0", "doctrine/persistence": "^2.0 || ^3.0", "gedmo/doctrine-extensions": "^2.4.12 || ^3.0", From 7f8504c3fec19e76bd875d071753643571e1ea0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 23 May 2024 11:19:26 +0200 Subject: [PATCH 11/22] [SF7] Add removed symfony container aware trait --- psalm.xml | 6 ++++ src/Bundle/Controller/ContainerAwareTrait.php | 34 +++++++++++++++++++ src/Bundle/Controller/ResourceController.php | 1 - 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/Controller/ContainerAwareTrait.php diff --git a/psalm.xml b/psalm.xml index 08b527b10..244df6359 100644 --- a/psalm.xml +++ b/psalm.xml @@ -168,6 +168,12 @@ + + + + + + diff --git a/src/Bundle/Controller/ContainerAwareTrait.php b/src/Bundle/Controller/ContainerAwareTrait.php new file mode 100644 index 000000000..0b50463b2 --- /dev/null +++ b/src/Bundle/Controller/ContainerAwareTrait.php @@ -0,0 +1,34 @@ +container = $container; + } +} diff --git a/src/Bundle/Controller/ResourceController.php b/src/Bundle/Controller/ResourceController.php index e672f1eb2..defd989de 100644 --- a/src/Bundle/Controller/ResourceController.php +++ b/src/Bundle/Controller/ResourceController.php @@ -23,7 +23,6 @@ use Sylius\Resource\Metadata\MetadataInterface; use Sylius\Resource\Model\ResourceInterface; use Sylius\Resource\ResourceActions; -use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; From f27f93b1289f45bb47ada46629cb2f2c661b56fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 23 May 2024 10:05:46 +0200 Subject: [PATCH 12/22] [SF7] Remove enable authenticator manager option on test application --- composer.json | 7 ++++--- tests/Application/config/packages/security.yaml | 1 - tests/Application/src/Kernel.php | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index e23223c6f..4a7ea4f01 100644 --- a/composer.json +++ b/composer.json @@ -70,20 +70,21 @@ "phpstan/phpstan-phpunit": "^1.1", "phpstan/phpstan-webmozart-assert": "^1.2", "phpunit/phpunit": "^9.5", + "rector/rector": "^0.18.2", "sylius-labs/coding-standard": "^4.0", "sylius/grid-bundle": "^1.7 || dev-symfony-7", "symfony/console": "^5.4 || ^6.4 || ^7.0", "symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0", "symfony/dotenv": "^5.4 || ^6.4 || ^7.0", + "symfony/http-kernel": "^5.4 || ^6.4 || ^7.0", "symfony/stopwatch": "^5.4 || ^6.4 || ^7.0", "symfony/uid": "^5.4 || ^6.4 || ^7.0", "symfony/workflow": "^5.4 || ^6.4 || ^7.0", - "twig/twig": "^2.12 || ^3.0", - "vimeo/psalm": "^5.20", - "rector/rector": "^0.18.2", "symfony/messenger": "^5.4 || ^6.4 || ^7.0", "symfony/serializer": "^5.4 || ^6.4 || ^7.0", "symfony/security-bundle": "^5.4 || ^6.4 || ^7.0", + "twig/twig": "^2.12 || ^3.0", + "vimeo/psalm": "^5.20", "willdurand/hateoas-bundle": "^2.0" }, "conflict": { diff --git a/tests/Application/config/packages/security.yaml b/tests/Application/config/packages/security.yaml index 789a9ac14..367af25a5 100644 --- a/tests/Application/config/packages/security.yaml +++ b/tests/Application/config/packages/security.yaml @@ -1,5 +1,4 @@ security: - enable_authenticator_manager: true # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords password_hashers: Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' diff --git a/tests/Application/src/Kernel.php b/tests/Application/src/Kernel.php index 2ebc63e0b..376631222 100644 --- a/tests/Application/src/Kernel.php +++ b/tests/Application/src/Kernel.php @@ -32,5 +32,11 @@ protected function build(ContainerBuilder $container): void $container->registerForAutoconfiguration(CommandHandlerInterface::class) ->addTag('messenger.message_handler', ['bus' => 'command.bus']) ; + + if (self::MAJOR_VERSION < 7) { + $container->prependExtensionConfig('security', [ + 'enable_authenticator_manager' => true, + ]); + } } } From ebac2c9fb54b1e1cc12f92ee05ab6cec37ca620a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 23 May 2024 14:44:45 +0200 Subject: [PATCH 13/22] Upgrade winzou on dev branch --- .github/workflows/build.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4cced2d40..40fc0280e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -88,6 +88,10 @@ jobs: if: matrix.collections != '' run: composer require "doctrine/collections:${{ matrix.collections }}" --no-update --no-scripts + - + name: Upgrade winzou-state-machine to dev branch + run: composer require "winzou/state-machine-bundle" "dev-master" --no-update --no-scripts + - name: Install dependencies run: | From 5609c1fdd00a16090f7e883c6cc338c3df9a42a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 23 May 2024 15:14:23 +0200 Subject: [PATCH 14/22] [SF7] Remove hateoas on Symfony 7 --- .github/workflows/build.yml | 20 +++++++++++++++----- composer.json | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 40fc0280e..f9cf6d151 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,6 +15,8 @@ jobs: runs-on: ubuntu-latest continue-on-error: ${{ matrix.experimental }} name: "PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, Twig ${{ matrix.twig }}, Persistence: ${{ matrix.persistence }}, Collections: ${{ matrix.collections }}" + env: + APP_ENV: ${{ matrix.app_env }} strategy: fail-fast: false matrix: @@ -24,13 +26,16 @@ jobs: persistence: ["^2.0", "^3.0"] collections: ["^1.8", "^2.0"] experimental: [false] + app_env: ["test"] include: - php: "8.1" pagerfanta: "^3.7" symfony: "^5.4" + app_env: "test" experimental: false - php: 8.3 symfony: "^7.0" + app_env: "test_without_fosrest" experimental: true exclude: - php: "8.1" @@ -92,6 +97,11 @@ jobs: name: Upgrade winzou-state-machine to dev branch run: composer require "winzou/state-machine-bundle" "dev-master" --no-update --no-scripts + - + name: Remove hateoas on Symfony 7 + if: matrix.symfony == '^7.0' + run: composer remove --dev willdurand/hateoas-bundle --no-update --no-scripts + - name: Install dependencies run: | @@ -134,7 +144,7 @@ jobs: if: ${{ true != contains( matrix.php, '8.2' ) }} run: | sed -i -e 's/state_machine_component: symfony/state_machine_component: winzou/g' tests/Application/config/packages/test/sylius_resource.yaml - (cd tests/Application && bin/console cache:clear --env=test) + (cd tests/Application && bin/console cache:clear) vendor/bin/phpspec run --ansi --no-interaction sed -i -e 's/state_machine_component: winzou/state_machine_component: symfony/g' tests/Application/config/packages/test/sylius_resource.yaml @@ -143,7 +153,7 @@ jobs: name: Run state machine PHPUnit tests with winzou/state-machine package run: | sed -i -e 's/state_machine_component: symfony/state_machine_component: winzou/g' tests/Application/config/packages/test/sylius_resource.yaml - (cd tests/Application && bin/console cache:clear --env=test) + (cd tests/Application && bin/console cache:clear) vendor/bin/phpunit --colors=always sed -i -e 's/state_machine_component: winzou/state_machine_component: symfony/g' tests/Application/config/packages/test/sylius_resource.yaml @@ -152,7 +162,7 @@ jobs: if: ${{ true != contains( matrix.php, '8.2' ) }} run: | sed -i -e 's/state_machine_component: winzou/state_machine_component: symfony/g' tests/Application/config/packages/test/sylius_resource.yaml - (cd tests/Application && bin/console cache:clear --env=test) + (cd tests/Application && bin/console cache:clear) vendor/bin/phpspec run --ansi --no-interaction sed -i -e 's/state_machine_component: symfony/state_machine_component: winzou/g' tests/Application/config/packages/test/sylius_resource.yaml @@ -160,7 +170,7 @@ jobs: name: Run state machine PHPUnit tests with symfony/workflow package run: | sed -i -e 's/state_machine_component: winzou/state_machine_component: symfony/g' tests/Application/config/packages/test/sylius_resource.yaml - (cd tests/Application && bin/console cache:clear --env=test) + (cd tests/Application && bin/console cache:clear) vendor/bin/phpunit --colors=always sed -i -e 's/state_machine_component: symfony/state_machine_component: winzou/g' tests/Application/config/packages/test/sylius_resource.yaml @@ -170,7 +180,7 @@ jobs: composer remove --dev friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts (cd tests/Application && bin/console cache:clear --env=test_without_fosrest) (cd tests/Application && bin/console lint:container --env=test_without_fosrest) - composer require friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts + composer require --dev friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts - name: Run lint container without winzou/state-machine-bundle package diff --git a/composer.json b/composer.json index 4a7ea4f01..39b22c043 100644 --- a/composer.json +++ b/composer.json @@ -90,7 +90,7 @@ "conflict": { "friendsofsymfony/rest-bundle": "<3.0", "jms/serializer-bundle": "<3.5", - "willdurand/hateoas-bundle": "<2.0" + "willdurand/hateoas-bundle": "<2.0 || ^2.6" }, "suggest": { "doctrine/orm": "^2.5", From 8d2e5284a9a44235d84cf6185018c2deda480559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 23 May 2024 16:29:08 +0200 Subject: [PATCH 15/22] [SF7] Fix resource loader --- psalm.xml | 1 + src/Bundle/Routing/ResourceLoader.php | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/psalm.xml b/psalm.xml index 244df6359..3d2b89bbf 100644 --- a/psalm.xml +++ b/psalm.xml @@ -204,6 +204,7 @@ + diff --git a/src/Bundle/Routing/ResourceLoader.php b/src/Bundle/Routing/ResourceLoader.php index c271a8a62..e54793a8e 100644 --- a/src/Bundle/Routing/ResourceLoader.php +++ b/src/Bundle/Routing/ResourceLoader.php @@ -29,6 +29,8 @@ final class ResourceLoader implements LoaderInterface private RouteFactoryInterface $routeFactory; + private LoaderResolverInterface $resolver; + public function __construct(RegistryInterface $resourceRegistry, RouteFactoryInterface $routeFactory) { $this->resourceRegistry = $resourceRegistry; @@ -105,17 +107,15 @@ public function supports($resource, $type = null): bool /** * @psalm-suppress InvalidReturnType Symfony docblocks are messing with us - * - * @return LoaderResolverInterface */ - public function getResolver() + public function getResolver(): LoaderResolverInterface { - // Intentionally left blank. + return $this->resolver; } public function setResolver(LoaderResolverInterface $resolver): void { - // Intentionally left blank. + $this->resolver = $resolver; } private function createRoute( From da5f7404a0b75355d1462cd7ddf960b3c96d2b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Wed, 29 May 2024 15:31:33 +0200 Subject: [PATCH 16/22] Use abstract loader from Symfony --- .../Resources/config/services/routing.xml | 1 + src/Bundle/Routing/ResourceLoader.php | 27 ++++++------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/Bundle/Resources/config/services/routing.xml b/src/Bundle/Resources/config/services/routing.xml index a84844b94..58adb37f4 100644 --- a/src/Bundle/Resources/config/services/routing.xml +++ b/src/Bundle/Resources/config/services/routing.xml @@ -20,6 +20,7 @@ + %kernel.environment% diff --git a/src/Bundle/Routing/ResourceLoader.php b/src/Bundle/Routing/ResourceLoader.php index e54793a8e..639182163 100644 --- a/src/Bundle/Routing/ResourceLoader.php +++ b/src/Bundle/Routing/ResourceLoader.php @@ -17,22 +17,24 @@ use Sylius\Resource\Metadata\MetadataInterface; use Sylius\Resource\Metadata\RegistryInterface; use Symfony\Component\Config\Definition\Processor; -use Symfony\Component\Config\Loader\LoaderInterface; -use Symfony\Component\Config\Loader\LoaderResolverInterface; +use Symfony\Component\Config\Loader\Loader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Yaml\Yaml; -final class ResourceLoader implements LoaderInterface +final class ResourceLoader extends Loader { private RegistryInterface $resourceRegistry; private RouteFactoryInterface $routeFactory; - private LoaderResolverInterface $resolver; + public function __construct( + RegistryInterface $resourceRegistry, + RouteFactoryInterface $routeFactory, + ?string $env = null, + ) { + parent::__construct($env); - public function __construct(RegistryInterface $resourceRegistry, RouteFactoryInterface $routeFactory) - { $this->resourceRegistry = $resourceRegistry; $this->routeFactory = $routeFactory; } @@ -105,19 +107,6 @@ public function supports($resource, $type = null): bool return 'sylius.resource' === $type || 'sylius.resource_api' === $type; } - /** - * @psalm-suppress InvalidReturnType Symfony docblocks are messing with us - */ - public function getResolver(): LoaderResolverInterface - { - return $this->resolver; - } - - public function setResolver(LoaderResolverInterface $resolver): void - { - $this->resolver = $resolver; - } - private function createRoute( MetadataInterface $metadata, array $configuration, From ce59b1d78325b3d8e8d444d0b8d4122d4e70112d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 23 May 2024 16:43:37 +0200 Subject: [PATCH 17/22] Fix analysis errors --- psalm.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/psalm.xml b/psalm.xml index 3d2b89bbf..f486f43a7 100644 --- a/psalm.xml +++ b/psalm.xml @@ -257,10 +257,13 @@ + + + From 5ff7ee8af1eb4a9e1f4234d593654472be613983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 23 May 2024 16:55:35 +0200 Subject: [PATCH 18/22] Fix PHPStan errors --- phpstan.neon | 1 + .../DataTransformer/ResourceToIdentifierTransformer.php | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 895903226..3acae94e9 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -46,6 +46,7 @@ parameters: - '/Call to method isChangeTrackingDeferredExplicit\(\) on an unknown class Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata./' - '/Call to an undefined method ReflectionClass::getAttributes\(\)./' - '/Call to an undefined method object::getRealClassName\(\)./' + - '/Class Bazinga\\Bundle\\HateoasBundle\\BazingaHateoasBundle not found\./' - '/Class Doctrine\\Bundle\\MongoDBBundle/' - '/Class Doctrine\\Bundle\\PHPCRBundle/' - '/Class Doctrine\\Common\\Persistence\\ObjectManager not found\./' diff --git a/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php b/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php index ac6ae0492..33f17154c 100644 --- a/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php +++ b/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php @@ -33,13 +33,9 @@ public function __construct(RepositoryInterface $repository, ?string $identifier } /** - * @psalm-suppress MissingParamType - * - * @param object|null $value - * - * @return mixed + * @inheritDoc */ - public function transform($value) + public function transform($value): mixed { if (null === $value) { return null; From 49bbf3f9765e72900d4981c6acfa95fd8ce0f2de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Wed, 29 May 2024 17:51:58 +0200 Subject: [PATCH 19/22] Add suggestion from code review --- .../DataTransformer/ResourceToIdentifierTransformer.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php b/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php index 33f17154c..8b52bdbf9 100644 --- a/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php +++ b/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php @@ -35,7 +35,7 @@ public function __construct(RepositoryInterface $repository, ?string $identifier /** * @inheritDoc */ - public function transform($value): mixed + public function transform(mixed $value): mixed { if (null === $value) { return null; @@ -47,8 +47,10 @@ public function transform($value): mixed return PropertyAccess::createPropertyAccessor()->getValue($value, $this->identifier); } - /** @param int|string|null $value */ - public function reverseTransform($value): ?ResourceInterface + /** + * @inheritDoc + */ + public function reverseTransform(mixed $value): ?ResourceInterface { if (null === $value) { return null; From e1c2ff4ad909baade199f8e5a2b24d1995a1d05e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Fri, 24 May 2024 10:03:53 +0200 Subject: [PATCH 20/22] [SF7] Fix phpspec tests --- src/Bundle/Controller/Parameters.php | 2 +- .../spec/Controller/RedirectHandlerSpec.php | 4 +- .../RequestConfigurationFactorySpec.php | 6 +- .../Controller/RequestConfigurationSpec.php | 82 ++++++++++--------- .../Controller/ResourceControllerSpec.php | 20 ++--- .../ResourcesCollectionProviderSpec.php | 78 ++++++++---------- .../Grid/Controller/ResourcesResolverSpec.php | 10 +-- .../RepositoryArgumentResolverSpec.php | 10 +-- .../Symfony/Request/State/ProviderSpec.php | 10 +-- 9 files changed, 108 insertions(+), 114 deletions(-) diff --git a/src/Bundle/Controller/Parameters.php b/src/Bundle/Controller/Parameters.php index 510b86232..a9b39700e 100644 --- a/src/Bundle/Controller/Parameters.php +++ b/src/Bundle/Controller/Parameters.php @@ -16,7 +16,7 @@ use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpKernel\Kernel; -if (Kernel::MAJOR_VERSION === 6) { +if (Kernel::MAJOR_VERSION >= 6) { class Parameters extends ParameterBag { /** diff --git a/src/Bundle/spec/Controller/RedirectHandlerSpec.php b/src/Bundle/spec/Controller/RedirectHandlerSpec.php index 2d752ebf2..3630d2673 100644 --- a/src/Bundle/spec/Controller/RedirectHandlerSpec.php +++ b/src/Bundle/spec/Controller/RedirectHandlerSpec.php @@ -17,7 +17,7 @@ use Sylius\Bundle\ResourceBundle\Controller\RedirectHandlerInterface; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; use Sylius\Resource\Model\ResourceInterface; -use Symfony\Component\HttpFoundation\ParameterBag; +use Symfony\Component\HttpFoundation\HeaderBag; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -104,7 +104,7 @@ function it_redirects(RequestConfiguration $configuration): void $this->redirect($configuration, 'http://myurl.com')->shouldHaveType(RedirectResponse::class); } - function it_redirect_to_referer(RequestConfiguration $configuration, Request $request, ParameterBag $bag): void + function it_redirect_to_referer(RequestConfiguration $configuration, Request $request, HeaderBag $bag): void { $request->headers = $bag; diff --git a/src/Bundle/spec/Controller/RequestConfigurationFactorySpec.php b/src/Bundle/spec/Controller/RequestConfigurationFactorySpec.php index 739ea73dc..9909f4a60 100644 --- a/src/Bundle/spec/Controller/RequestConfigurationFactorySpec.php +++ b/src/Bundle/spec/Controller/RequestConfigurationFactorySpec.php @@ -138,7 +138,7 @@ function it_creates_configuration_using_only_those_serialization_groups_that_are ParametersParserInterface $parametersParser, MetadataInterface $metadata, Request $request, - ParameterBag $headersBag, + HeaderBag $headersBag, ParameterBag $attributesBag, ): void { $request->headers = $headersBag; @@ -167,7 +167,7 @@ function it_creates_configuration_using_only_those_serialization_groups_that_are ParametersParserInterface $parametersParser, MetadataInterface $metadata, Request $request, - ParameterBag $headersBag, + HeaderBag $headersBag, ParameterBag $attributesBag, ): void { $request->headers = $headersBag; @@ -197,7 +197,7 @@ function it_creates_configuration_using_only_those_serialization_groups_that_are ParametersParserInterface $parametersParser, MetadataInterface $metadata, Request $request, - ParameterBag $headersBag, + HeaderBag $headersBag, ParameterBag $attributesBag, ): void { $request->headers = $headersBag; diff --git a/src/Bundle/spec/Controller/RequestConfigurationSpec.php b/src/Bundle/spec/Controller/RequestConfigurationSpec.php index e29bc2b40..c9e45464b 100644 --- a/src/Bundle/spec/Controller/RequestConfigurationSpec.php +++ b/src/Bundle/spec/Controller/RequestConfigurationSpec.php @@ -17,6 +17,8 @@ use Prophecy\Argument; use Sylius\Bundle\ResourceBundle\Controller\Parameters; use Sylius\Resource\Metadata\MetadataInterface; +use Symfony\Component\HttpFoundation\HeaderBag; +use Symfony\Component\HttpFoundation\InputBag; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; @@ -132,7 +134,7 @@ function it_generates_route_names(MetadataInterface $metadata, Parameters $param $this->getRouteName('custom')->shouldReturn('sylius_admin_product_custom'); } - function it_generates_redirect_referer(Parameters $parameters, Request $request, ParameterBag $bag): void + function it_generates_redirect_referer(Parameters $parameters, Request $request, HeaderBag $bag): void { $request->headers = $bag; $bag->get('referer')->willReturn('http://myurl.com'); @@ -275,9 +277,10 @@ function it_has_criteria_parameter( Parameters $parameters, Request $request, ParameterBag $attributesBag, - ParameterBag $queryBag, - ParameterBag $requestBag, ): void { + $queryBag = new InputBag(); + $requestBag = new InputBag(); + $criteria = ['property' => 'myNewValue']; $request->attributes = $attributesBag; $request->query = $queryBag; @@ -287,9 +290,10 @@ function it_has_criteria_parameter( $parameters->get('criteria', Argument::any())->willReturn([]); $attributesBag->get('criteria', $request)->willReturn($request); - $queryBag->has('criteria')->willReturn(true); - $queryBag->all()->willReturn(['criteria' => $criteria]); - $requestBag->all()->willReturn(['criteria' => []]); + + $queryBag->set('criteria', $criteria); + + $requestBag->set('criteria', []); $this->getCriteria()->shouldReturn($criteria); } @@ -298,9 +302,10 @@ function it_has_criteria_parameter_in_request( Parameters $parameters, Request $request, ParameterBag $attributesBag, - ParameterBag $queryBag, - ParameterBag $requestBag, ): void { + $queryBag = new InputBag(); + $requestBag = new InputBag(); + $criteria = ['property' => 'myNewValue']; $request->attributes = $attributesBag; $request->query = $queryBag; @@ -310,9 +315,8 @@ function it_has_criteria_parameter_in_request( $parameters->get('criteria', Argument::any())->willReturn([]); $attributesBag->get('criteria', $request)->willReturn($request); - $queryBag->has('criteria')->willReturn(false); - $requestBag->has('criteria')->willReturn(true); - $requestBag->all()->willReturn(['criteria' => $criteria]); + + $requestBag->set('criteria', $criteria); $this->getCriteria()->shouldReturn($criteria); } @@ -321,9 +325,10 @@ function it_allows_to_override_criteria_parameter_in_route( Parameters $parameters, Request $request, ParameterBag $attributesBag, - ParameterBag $queryBag, - ParameterBag $requestBag, ): void { + $queryBag = new InputBag(); + $requestBag = new InputBag(); + $criteria = ['property' => 'myValue']; $overriddenCriteria = ['other_property' => 'myNewValue']; $combinedCriteria = ['property' => 'myValue', 'other_property' => 'myNewValue']; @@ -333,10 +338,12 @@ function it_allows_to_override_criteria_parameter_in_route( $parameters->get('filterable', false)->willReturn(true); $parameters->get('criteria', [])->willReturn($criteria); + $attributesBag->get('criteria', $request)->willReturn($request); - $queryBag->has('criteria')->willReturn(true); - $queryBag->all()->willReturn(['criteria' => $overriddenCriteria]); - $requestBag->all()->willReturn(['criteria' => []]); + + $queryBag->set('criteria', $overriddenCriteria); + + $requestBag->set('criteria', []); $this->getCriteria()->shouldReturn($combinedCriteria); @@ -346,18 +353,16 @@ function it_allows_to_override_criteria_parameter_in_route( $parameters->get('filterable', false)->willReturn(true); $parameters->get('criteria', Argument::any())->willReturn($criteria); $attributesBag->get('criteria', $request)->willReturn($request); - $queryBag->has('criteria')->willReturn(true); - $queryBag->all()->willReturn(['criteria' => $overriddenCriteria]); - $requestBag->all()->willReturn(['criteria' => []]); + $queryBag->set('criteria', $overriddenCriteria); + $requestBag->set('criteria', []); $this->getCriteria($defaultCriteria)->shouldReturn($combinedDefaultCriteria); $parameters->get('filterable', false)->willReturn(true); $parameters->get('criteria', [])->willReturn(['filter' => 'route']); $attributesBag->get('criteria', $request)->willReturn($request); - $queryBag->has('criteria')->willReturn(true); - $queryBag->all()->willReturn(['criteria' => ['filter' => 'request']]); - $requestBag->all()->willReturn(['criteria' => []]); + $queryBag->set('criteria', ['filter' => 'request']); + $requestBag->set('criteria', []); $this->getCriteria(['filter' => 'default'])->shouldReturn(['filter' => 'request']); } @@ -375,9 +380,10 @@ function it_has_sorting_parameter( Parameters $parameters, Request $request, ParameterBag $attributesBag, - ParameterBag $queryBag, - ParameterBag $requestBag, ): void { + $queryBag = new InputBag(); + $requestBag = new InputBag(); + $sorting = ['property' => 'asc']; $request->attributes = $attributesBag; $request->query = $queryBag; @@ -385,10 +391,12 @@ function it_has_sorting_parameter( $parameters->get('sortable', false)->willReturn(true); $parameters->get('sorting', Argument::any())->willReturn($sorting); + $attributesBag->get('sorting', $request)->willReturn($request); - $queryBag->has('sorting')->willReturn(true); - $queryBag->all()->willReturn(['sorting' => $sorting]); - $requestBag->get('sorting', [])->willReturn([]); + + $queryBag->set('sorting', $sorting); + + $requestBag->set('sorting', []); $this->getSorting()->shouldReturn($sorting); } @@ -408,9 +416,10 @@ function it_allows_to_override_sorting_parameter_in_route( Parameters $parameters, Request $request, ParameterBag $attributesBag, - ParameterBag $queryBag, - ParameterBag $requestBag, ): void { + $queryBag = new InputBag(); + $requestBag = new InputBag(); + $sorting = ['property' => 'desc']; $overriddenSorting = ['other_property' => 'asc']; $combinedSorting = ['other_property' => 'asc', 'property' => 'desc']; @@ -421,9 +430,8 @@ function it_allows_to_override_sorting_parameter_in_route( $parameters->get('sortable', false)->willReturn(true); $parameters->get('sorting', [])->willReturn($sorting); $attributesBag->get('sorting', $request)->willReturn($request); - $queryBag->has('sorting')->willReturn(true); - $queryBag->all()->willReturn(['sorting' => $overriddenSorting]); - $requestBag->get('sorting', [])->willReturn([]); + $queryBag->set('sorting', $overriddenSorting); + $requestBag->set('sorting', []); $this->getSorting()->shouldReturn($combinedSorting); @@ -433,18 +441,16 @@ function it_allows_to_override_sorting_parameter_in_route( $parameters->get('sortable', false)->willReturn(true); $parameters->get('sorting', Argument::any())->willReturn($sorting); $attributesBag->get('sorting', $request)->willReturn($request); - $queryBag->has('sorting')->willReturn(true); - $queryBag->all()->willReturn(['sorting' => $overriddenSorting]); - $requestBag->get('sorting', [])->willReturn([]); + $queryBag->set('sorting', $overriddenSorting); + $requestBag->set('sorting', []); $this->getSorting($defaultSorting)->shouldReturn($combinedDefaultSorting); $parameters->get('sortable', false)->willReturn(true); $parameters->get('sorting', [])->willReturn(['sort' => 'route']); $attributesBag->get('sorting', $request)->willReturn($request); - $queryBag->has('sorting')->willReturn(true); - $queryBag->all()->willReturn(['sorting' => ['sort' => 'request']]); - $requestBag->get('sorting', [])->willReturn([]); + $queryBag->set('sorting', ['sort' => 'request']); + $requestBag->set('sorting', []); $this->getSorting(['sort' => 'default'])->shouldReturn(['sort' => 'request']); } diff --git a/src/Bundle/spec/Controller/ResourceControllerSpec.php b/src/Bundle/spec/Controller/ResourceControllerSpec.php index 4daf97dcc..270c25110 100644 --- a/src/Bundle/spec/Controller/ResourceControllerSpec.php +++ b/src/Bundle/spec/Controller/ResourceControllerSpec.php @@ -43,7 +43,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\Form; use Symfony\Component\Form\FormView; -use Symfony\Component\HttpFoundation\ParameterBag; +use Symfony\Component\HttpFoundation\InputBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; @@ -1784,7 +1784,7 @@ function it_deletes_multiple_resources_and_redirects_to_index_for_html_request( $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration); $configuration->hasPermission()->willReturn(true); $configuration->getPermission(ResourceActions::BULK_DELETE)->willReturn('sylius.product.bulk_delete'); - $request->request = new ParameterBag(['_csrf_token' => 'xyz']); + $request->request = new InputBag(['_csrf_token' => 'xyz']); $container->has('security.csrf.token_manager')->willReturn(true); $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager); @@ -1903,7 +1903,7 @@ function it_deletes_a_resource_and_redirects_to_index_by_for_html_request( $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration); $configuration->hasPermission()->willReturn(true); $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete'); - $request->request = new ParameterBag(['_csrf_token' => 'xyz']); + $request->request = new InputBag(['_csrf_token' => 'xyz']); $container->has('security.csrf.token_manager')->willReturn(true); $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager); @@ -1954,7 +1954,7 @@ function it_uses_response_from_post_delete_event_if_defined( $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration); $configuration->hasPermission()->willReturn(true); $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete'); - $request->request = new ParameterBag(['_csrf_token' => 'xyz']); + $request->request = new InputBag(['_csrf_token' => 'xyz']); $container->has('security.csrf.token_manager')->willReturn(true); $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager); @@ -2005,7 +2005,7 @@ function it_does_not_delete_a_resource_and_redirects_to_index_for_html_requests_ $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration); $configuration->hasPermission()->willReturn(true); $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete'); - $request->request = new ParameterBag(['_csrf_token' => 'xyz']); + $request->request = new InputBag(['_csrf_token' => 'xyz']); $container->has('security.csrf.token_manager')->willReturn(true); $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager); @@ -2056,7 +2056,7 @@ function it_does_not_delete_a_resource_and_uses_response_from_event_if_defined( $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration); $configuration->hasPermission()->willReturn(true); $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete'); - $request->request = new ParameterBag(['_csrf_token' => 'xyz']); + $request->request = new InputBag(['_csrf_token' => 'xyz']); $container->has('security.csrf.token_manager')->willReturn(true); $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager); @@ -2109,7 +2109,7 @@ function it_does_not_correctly_delete_a_resource_and_returns_500_for_not_html_re $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration); $configuration->hasPermission()->willReturn(true); $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete'); - $request->request = new ParameterBag(['_csrf_token' => 'xyz']); + $request->request = new InputBag(['_csrf_token' => 'xyz']); $container->has('security.csrf.token_manager')->willReturn(true); $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager); @@ -2159,7 +2159,7 @@ function it_deletes_a_resource_and_returns_204_for_non_html_requests( $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration); $configuration->hasPermission()->willReturn(true); $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete'); - $request->request = new ParameterBag(['_csrf_token' => 'xyz']); + $request->request = new InputBag(['_csrf_token' => 'xyz']); $container->has('security.csrf.token_manager')->willReturn(true); $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager); @@ -2207,7 +2207,7 @@ function it_does_not_delete_a_resource_and_throws_http_exception_for_non_html_re $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration); $configuration->hasPermission()->willReturn(true); $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete'); - $request->request = new ParameterBag(['_csrf_token' => 'xyz']); + $request->request = new InputBag(['_csrf_token' => 'xyz']); $container->has('security.csrf.token_manager')->willReturn(true); $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager); @@ -2259,7 +2259,7 @@ function it_throws_a_403_exception_if_csrf_token_is_invalid_during_delete_action $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration); $configuration->hasPermission()->willReturn(true); $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete'); - $request->request = new ParameterBag(['_csrf_token' => 'xyz']); + $request->request = new InputBag(['_csrf_token' => 'xyz']); $container->has('security.csrf.token_manager')->willReturn(true); $container->get('security.csrf.token_manager')->willReturn($csrfTokenManager); diff --git a/src/Bundle/spec/Controller/ResourcesCollectionProviderSpec.php b/src/Bundle/spec/Controller/ResourcesCollectionProviderSpec.php index c385bbee1..1b92ead68 100644 --- a/src/Bundle/spec/Controller/ResourcesCollectionProviderSpec.php +++ b/src/Bundle/spec/Controller/ResourcesCollectionProviderSpec.php @@ -13,27 +13,34 @@ namespace spec\Sylius\Bundle\ResourceBundle\Controller; -use Hateoas\Configuration\Route; use Hateoas\Representation\Factory\PagerfantaFactory; use Hateoas\Representation\PaginatedRepresentation; +use Pagerfanta\Adapter\ArrayAdapter; use Pagerfanta\Pagerfanta; +use PhpSpec\Exception\Example\SkippingException; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; +use Sylius\Bundle\ResourceBundle\Controller\Parameters; use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; use Sylius\Bundle\ResourceBundle\Controller\ResourcesCollectionProviderInterface; +use Sylius\Bundle\ResourceBundle\Controller\ResourcesResolver; use Sylius\Bundle\ResourceBundle\Controller\ResourcesResolverInterface; use Sylius\Bundle\ResourceBundle\Grid\View\ResourceGridView; use Sylius\Component\Grid\Definition\Grid; use Sylius\Resource\Doctrine\Persistence\RepositoryInterface; +use Sylius\Resource\Metadata\MetadataInterface; use Sylius\Resource\Model\ResourceInterface; +use Symfony\Component\HttpFoundation\InputBag; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; final class ResourcesCollectionProviderSpec extends ObjectBehavior { - function let(ResourcesResolverInterface $resourcesResolver, PagerfantaFactory $pagerfantaRepresentationFactory): void + use ProphecyTrait; + + function let(ResourcesResolverInterface $resourcesResolver): void { - $this->beConstructedWith($resourcesResolver, $pagerfantaRepresentationFactory); + $this->beConstructedWith($resourcesResolver, null); } function it_implements_resources_collection_provider_interface(): void @@ -61,8 +68,9 @@ function it_handles_Pagerfanta( RepositoryInterface $repository, Pagerfanta $paginator, Request $request, - ParameterBag $queryParameters, ): void { + $queryParameters = new InputBag(); + $requestConfiguration->isHtmlRequest()->willReturn(true); $requestConfiguration->getPaginationMaxPerPage()->willReturn(5); @@ -70,9 +78,8 @@ function it_handles_Pagerfanta( $requestConfiguration->getRequest()->willReturn($request); $request->query = $queryParameters; - $queryParameters->has('limit')->willReturn(true); - $queryParameters->getInt('limit')->willReturn(5); - $queryParameters->get('page', 1)->willReturn(6); + $queryParameters->set('limit', 5); + $queryParameters->set('page', 6); $paginator->setMaxPerPage(5)->shouldBeCalled(); $paginator->setCurrentPage(6)->shouldBeCalled(); @@ -89,8 +96,9 @@ function it_restricts_max_pagination_limit_based_on_grid_configuration( Grid $grid, Pagerfanta $paginator, Request $request, - ParameterBag $queryParameters, ): void { + $queryParameters = new InputBag(); + $requestConfiguration->isHtmlRequest()->willReturn(true); $requestConfiguration->getPaginationMaxPerPage()->willReturn(1000); @@ -103,9 +111,8 @@ function it_restricts_max_pagination_limit_based_on_grid_configuration( $requestConfiguration->getRequest()->willReturn($request); $request->query = $queryParameters; - $queryParameters->has('limit')->willReturn(true); - $queryParameters->getInt('limit')->willReturn(1000); - $queryParameters->get('page', 1)->willReturn(1); + $queryParameters->set('limit', 1000); + $queryParameters->set('page', 1); $paginator->setMaxPerPage(99)->shouldBeCalled(); $paginator->setCurrentPage(1)->shouldBeCalled(); @@ -115,39 +122,24 @@ function it_restricts_max_pagination_limit_based_on_grid_configuration( } function it_creates_a_paginated_representation_for_pagerfanta_for_non_html_requests( - ResourcesResolverInterface $resourcesResolver, - RequestConfiguration $requestConfiguration, RepositoryInterface $repository, - Pagerfanta $paginator, - Request $request, - ParameterBag $queryParameters, - ParameterBag $requestAttributes, - PagerfantaFactory $pagerfantaRepresentationFactory, - PaginatedRepresentation $paginatedRepresentation, + MetadataInterface $metadata, ): void { - $requestConfiguration->isHtmlRequest()->willReturn(false); - $requestConfiguration->getPaginationMaxPerPage()->willReturn(8); + if (!class_exists(PagerfantaFactory::class)) { + throw new SkippingException('PagerfantaFactory is not installed.'); + } - $resourcesResolver->getResources($requestConfiguration, $repository)->willReturn($paginator); + $this->beConstructedWith(new ResourcesResolver(), new PagerfantaFactory()); - $requestConfiguration->getRequest()->willReturn($request); - $request->query = $queryParameters; - $queryParameters->has('limit')->willReturn(true); - $queryParameters->getInt('limit')->willReturn(8); - $queryParameters->get('page', 1)->willReturn(6); - $queryParameters->all()->willReturn(['foo' => 2, 'bar' => 15]); + $paginator = new Pagerfanta(new ArrayAdapter([])); + $repository->createPaginator([], [])->willReturn($paginator); - $request->attributes = $requestAttributes; - $requestAttributes->get('_route')->willReturn('sylius_product_index'); - $requestAttributes->get('_route_params')->willReturn(['slug' => 'foo-bar']); + $request = new Request(); + $request->query = new InputBag(['limit' => 8, 'page' => 1]); + $request->attributes = new ParameterBag(['_format' => 'json', '_route' => 'sylius_product_index', '_route_params' => ['slug' => 'foo-bar']]); + $requestConfiguration = new RequestConfiguration($metadata->getWrappedObject(), $request, new Parameters(['paginate' => true])); - $paginator->setMaxPerPage(8)->shouldBeCalled(); - $paginator->setCurrentPage(6)->shouldBeCalled(); - $paginator->getCurrentPageResults()->willReturn([]); - - $pagerfantaRepresentationFactory->createRepresentation($paginator, Argument::type(Route::class))->willReturn($paginatedRepresentation); - - $this->get($requestConfiguration, $repository)->shouldReturn($paginatedRepresentation); + $this->get($requestConfiguration, $repository)->shouldHaveType(PaginatedRepresentation::class); } function it_handles_resource_grid_view( @@ -158,8 +150,9 @@ function it_handles_resource_grid_view( Grid $grid, Pagerfanta $paginator, Request $request, - ParameterBag $queryParameters, ): void { + $queryParameters = new InputBag(); + $requestConfiguration->isHtmlRequest()->willReturn(true); $requestConfiguration->getPaginationMaxPerPage()->willReturn(5); @@ -171,9 +164,8 @@ function it_handles_resource_grid_view( $requestConfiguration->getRequest()->willReturn($request); $request->query = $queryParameters; - $queryParameters->has('limit')->willReturn(true); - $queryParameters->getInt('limit')->willReturn(5); - $queryParameters->get('page', 1)->willReturn(6); + $queryParameters->set('limit', 5); + $queryParameters->set('page', 6); $paginator->setMaxPerPage(5)->shouldBeCalled(); $paginator->setCurrentPage(6)->shouldBeCalled(); diff --git a/src/Bundle/spec/Grid/Controller/ResourcesResolverSpec.php b/src/Bundle/spec/Grid/Controller/ResourcesResolverSpec.php index cea6e0b6b..563c22cb4 100644 --- a/src/Bundle/spec/Grid/Controller/ResourcesResolverSpec.php +++ b/src/Bundle/spec/Grid/Controller/ResourcesResolverSpec.php @@ -26,7 +26,7 @@ use Sylius\Resource\Doctrine\Persistence\RepositoryInterface; use Sylius\Resource\Metadata\MetadataInterface; use Sylius\Resource\Model\ResourceInterface; -use Symfony\Component\HttpFoundation\ParameterBag; +use Symfony\Component\HttpFoundation\InputBag; use Symfony\Component\HttpFoundation\Request; final class ResourcesResolverSpec extends ObjectBehavior @@ -66,7 +66,6 @@ function it_returns_grid_view( ResourceGridView $gridView, MetadataInterface $metadata, Request $request, - ParameterBag $queryParameters, ): void { $requestConfiguration->hasGrid()->willReturn(true); $requestConfiguration->getGrid()->willReturn('sylius_admin_tax_category'); @@ -74,8 +73,7 @@ function it_returns_grid_view( $requestConfiguration->isHtmlRequest()->willReturn(true); $requestConfiguration->getRequest()->willReturn($request); - $request->query = $queryParameters; - $queryParameters->all()->willReturn(['foo' => 'bar']); + $request->query = new InputBag(['foo' => 'bar']); $gridProvider->get('sylius_admin_tax_category')->willReturn($gridDefinition); $gridViewFactory->create($gridDefinition, Argument::type(Parameters::class), $metadata, $requestConfiguration)->willReturn($gridView); @@ -93,7 +91,6 @@ function it_returns_grid_data_for_non_html_requests( Pagerfanta $paginator, MetadataInterface $metadata, Request $request, - ParameterBag $queryParameters, ): void { $requestConfiguration->hasGrid()->willReturn(true); $requestConfiguration->getGrid()->willReturn('sylius_admin_tax_category'); @@ -101,8 +98,7 @@ function it_returns_grid_data_for_non_html_requests( $requestConfiguration->isHtmlRequest()->willReturn(false); $requestConfiguration->getRequest()->willReturn($request); - $request->query = $queryParameters; - $queryParameters->all()->willReturn(['foo' => 'bar']); + $request->query = new InputBag(['foo' => 'bar']); $gridProvider->get('sylius_admin_tax_category')->willReturn($gridDefinition); $gridViewFactory->create($gridDefinition, Argument::type(Parameters::class), $metadata, $requestConfiguration)->willReturn($gridView); diff --git a/src/Component/spec/Symfony/Request/RepositoryArgumentResolverSpec.php b/src/Component/spec/Symfony/Request/RepositoryArgumentResolverSpec.php index c6417fae6..1cc796e1b 100644 --- a/src/Component/spec/Symfony/Request/RepositoryArgumentResolverSpec.php +++ b/src/Component/spec/Symfony/Request/RepositoryArgumentResolverSpec.php @@ -34,7 +34,7 @@ function it_gets_arguments_to_sent_to_the_repository( ): void { $request->attributes = $attributes; $request->query = new InputBag([]); - $request->request = new ParameterBag(); + $request->request = new InputBag(); $attributes->all('_route_params')->willReturn(['id' => 'my_id']); @@ -52,7 +52,7 @@ function it_uses_query_params_when_route_params_are_not_matching( ): void { $request->attributes = $attributes; $request->query = new InputBag(['id' => 'my_id']); - $request->request = new ParameterBag(); + $request->request = new InputBag(); $attributes->all('_route_params')->willReturn(['_sylius' => ['resource' => 'app.dummy']]); @@ -70,7 +70,7 @@ function it_uses_request_params_when_route_params_are_not_matching( ): void { $request->attributes = $attributes; $request->query = new InputBag(); - $request->request = new ParameterBag(['id' => 'my_id']); + $request->request = new InputBag(['id' => 'my_id']); $attributes->all('_route_params')->willReturn(['_sylius' => ['resource' => 'app.dummy']]); @@ -88,7 +88,7 @@ function it_encapsulates_arguments_when_the_method_has_only_one_required_array_a ): void { $request->attributes = $attributes; $request->query = new InputBag([]); - $request->request = new ParameterBag(); + $request->request = new InputBag(); $attributes->all('_route_params')->willReturn(['enabled' => 'true', 'author' => 'author@example.com']); @@ -109,7 +109,7 @@ function it_return_array_values_when_method_is_magic( ): void { $request->attributes = $attributes; $request->query = new InputBag(); - $request->request = new ParameterBag(['ids' => ['first_id', 'second_id']]); + $request->request = new InputBag(['ids' => ['first_id', 'second_id']]); $attributes->all('_route_params')->willReturn(['_sylius' => ['resource' => 'app.dummy']]); diff --git a/src/Component/spec/Symfony/Request/State/ProviderSpec.php b/src/Component/spec/Symfony/Request/State/ProviderSpec.php index 22d5fca3c..05d3fbb89 100644 --- a/src/Component/spec/Symfony/Request/State/ProviderSpec.php +++ b/src/Component/spec/Symfony/Request/State/ProviderSpec.php @@ -50,7 +50,7 @@ function it_calls_repository_as_callable( $request->attributes = new ParameterBag(['_route_params' => ['id' => 'my_id']]); $request->query = new InputBag([]); - $request->request = new ParameterBag(); + $request->request = new InputBag(); $response = $this->provide($operation, new Context(new RequestOption($request->getWrappedObject()))); $response->shouldHaveType(\stdClass::class); @@ -70,7 +70,7 @@ function it_calls_repository_as_string( $request->attributes = new ParameterBag(['_route_params' => ['id' => 'my_id', '_sylius' => ['resource' => 'app.dummy']]]); $request->query = new InputBag([]); - $request->request = new ParameterBag(); + $request->request = new InputBag(); $locator->has('App\Repository')->willReturn(true); $locator->get('App\Repository')->willReturn($repository); @@ -91,7 +91,7 @@ function it_calls_create_paginator_by_default_on_collection_operations( $request->attributes = new ParameterBag(['_route_params' => ['id' => 'my_id', '_sylius' => ['resource' => 'app.dummy']]]); $request->query = new InputBag([]); - $request->request = new ParameterBag(); + $request->request = new InputBag(); $locator->has('App\Repository')->willReturn(true); $locator->get('App\Repository')->willReturn($repository); @@ -113,7 +113,7 @@ function it_sets_current_page_from_request_when_data_is_a_paginator( $request->attributes = new ParameterBag(['_route_params' => ['id' => 'my_id', '_sylius' => ['resource' => 'app.dummy']]]); $request->query = new InputBag(['page' => 42]); - $request->request = new ParameterBag(); + $request->request = new InputBag(); $locator->has('App\Repository')->willReturn(true); $locator->get('App\Repository')->willReturn($repository); @@ -139,7 +139,7 @@ function it_calls_repository_as_string_with_specific_repository_method( $request->attributes = new ParameterBag(['_route_params' => ['id' => 'my_id', '_sylius' => ['resource' => 'app.dummy']]]); $request->query = new InputBag([]); - $request->request = new ParameterBag(); + $request->request = new InputBag(); $locator->has('App\Repository')->willReturn(true); $locator->get('App\Repository')->willReturn($repository); From 3172eab3c8268b18c0cd3d43b1532e2629c5c65a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Mon, 27 May 2024 10:46:36 +0200 Subject: [PATCH 21/22] [SF7] Fix PHPUnit tests --- .github/workflows/build.yml | 5 ++- .../EventListener/AddFormatListenerTest.php | 7 +++-- tests/Application/config/bundles.php | 2 +- .../test_without_fosrest/framework.yaml | 2 ++ .../packages/test_without_fosrest/grids.yaml | 2 ++ .../test_without_fosrest/sylius_grid.yaml | 2 ++ .../winzou_state_machine.yaml | 2 ++ .../test_without_hateoas/fos_rest.yaml | 2 ++ .../test_without_hateoas/framework.yaml | 2 ++ .../packages/test_without_hateoas/grids.yaml | 2 ++ .../test_without_hateoas/jms_serializer.yaml | 2 ++ .../test_without_hateoas/sylius_grid.yaml | 2 ++ .../packages/test_without_hateoas/twig.yaml | 2 ++ .../winzou_state_machine.yaml | 2 ++ tests/Application/config/services.yaml | 22 ++++++++----- .../src/Subscription/Entity/Subscription.php | 5 +-- .../src/Tests/Controller/BookApiTest.php | 31 +++++++++++++++++++ .../src/Tests/Controller/ComicBookApiTest.php | 15 +++++++++ 18 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 tests/Application/config/packages/test_without_fosrest/framework.yaml create mode 100644 tests/Application/config/packages/test_without_fosrest/grids.yaml create mode 100644 tests/Application/config/packages/test_without_fosrest/sylius_grid.yaml create mode 100644 tests/Application/config/packages/test_without_fosrest/winzou_state_machine.yaml create mode 100644 tests/Application/config/packages/test_without_hateoas/fos_rest.yaml create mode 100644 tests/Application/config/packages/test_without_hateoas/framework.yaml create mode 100644 tests/Application/config/packages/test_without_hateoas/grids.yaml create mode 100644 tests/Application/config/packages/test_without_hateoas/jms_serializer.yaml create mode 100644 tests/Application/config/packages/test_without_hateoas/sylius_grid.yaml create mode 100644 tests/Application/config/packages/test_without_hateoas/twig.yaml create mode 100644 tests/Application/config/packages/test_without_hateoas/winzou_state_machine.yaml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f9cf6d151..713344ced 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,7 @@ jobs: experimental: false - php: 8.3 symfony: "^7.0" - app_env: "test_without_fosrest" + app_env: "test_without_hateoas" experimental: true exclude: - php: "8.1" @@ -176,6 +176,7 @@ jobs: - name: Run lint container without friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle packages + if: matrix.app_env == 'test' run: | composer remove --dev friendsofsymfony/rest-bundle willdurand/hateoas-bundle jms/serializer-bundle --no-scripts (cd tests/Application && bin/console cache:clear --env=test_without_fosrest) @@ -184,6 +185,7 @@ jobs: - name: Run lint container without winzou/state-machine-bundle package + if: matrix.app_env == 'test' run: | composer remove winzou/state-machine-bundle --no-scripts (cd tests/Application && bin/console cache:clear --env=test_without_state_machine) @@ -192,6 +194,7 @@ jobs: - name: Run lint container without twig/twig package + if: matrix.app_env == 'test' run: | composer remove symfony/twig-bundle --no-scripts composer remove sylius/grid-bundle --no-scripts --dev diff --git a/src/Component/legacy/tests/Symfony/EventListener/AddFormatListenerTest.php b/src/Component/legacy/tests/Symfony/EventListener/AddFormatListenerTest.php index ce3285167..2692ea2b1 100644 --- a/src/Component/legacy/tests/Symfony/EventListener/AddFormatListenerTest.php +++ b/src/Component/legacy/tests/Symfony/EventListener/AddFormatListenerTest.php @@ -20,6 +20,7 @@ use Sylius\Resource\Metadata\HttpOperation; use Sylius\Resource\Metadata\Operation\HttpOperationInitiatorInterface; use Sylius\Resource\Symfony\EventListener\AddFormatListener; +use Symfony\Component\HttpFoundation\HeaderBag; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; @@ -55,7 +56,7 @@ public function it_sets_format_from_accept_header(): void $this->operationInitiator->initializeOperation($request)->willReturn($operation); $request->attributes = new ParameterBag(); - $request->headers = new ParameterBag(['Accept' => 'application/json']); + $request->headers = new HeaderBag(['Accept' => 'application/json']); $request->getFormat('application/json')->willReturn('json')->shouldBeCalled(); @@ -76,7 +77,7 @@ public function it_sets_format_from_request(): void $this->operationInitiator->initializeOperation($request)->willReturn($operation); $request->attributes = new ParameterBag(['_format' => 'json']); - $request->headers = new ParameterBag(); + $request->headers = new HeaderBag(); $request->getRequestFormat(null)->willReturn('json')->shouldBeCalled(); @@ -97,7 +98,7 @@ public function it_throws_an_exception_when_format_is_not_accepted(): void $this->operationInitiator->initializeOperation($request)->willReturn($operation); $request->attributes = new ParameterBag(['_format' => 'json-ld']); - $request->headers = new ParameterBag(); + $request->headers = new HeaderBag(); $request->getRequestFormat(null)->willReturn('json-ld')->shouldBeCalled(); diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index 194769143..1eb88eee0 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -34,7 +34,7 @@ TwigBundle::class => ['all' => true, 'test_without_twig' => false], FOSRestBundle::class => ['all' => true, 'test_without_fosrest' => false], JMSSerializerBundle::class => ['all' => true, 'test_without_fosrest' => false], - BazingaHateoasBundle::class => ['all' => true, 'test_without_fosrest' => false], + BazingaHateoasBundle::class => ['all' => true, 'test_without_hateoas' => false, 'test_without_fosrest' => false, 'test_with_attributes' => false], FidryAliceDataFixturesBundle::class => ['all' => true], NelmioAliceBundle::class => ['all' => true], winzouStateMachineBundle::class => ['all' => true, 'test_without_state_machine' => false], diff --git a/tests/Application/config/packages/test_without_fosrest/framework.yaml b/tests/Application/config/packages/test_without_fosrest/framework.yaml new file mode 100644 index 000000000..cf8f08807 --- /dev/null +++ b/tests/Application/config/packages/test_without_fosrest/framework.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: '../test/framework.yaml' } diff --git a/tests/Application/config/packages/test_without_fosrest/grids.yaml b/tests/Application/config/packages/test_without_fosrest/grids.yaml new file mode 100644 index 000000000..c9750ae87 --- /dev/null +++ b/tests/Application/config/packages/test_without_fosrest/grids.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: '../test/grids.yaml' } diff --git a/tests/Application/config/packages/test_without_fosrest/sylius_grid.yaml b/tests/Application/config/packages/test_without_fosrest/sylius_grid.yaml new file mode 100644 index 000000000..b702c5814 --- /dev/null +++ b/tests/Application/config/packages/test_without_fosrest/sylius_grid.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: '../test/sylius_grid.yaml' } diff --git a/tests/Application/config/packages/test_without_fosrest/winzou_state_machine.yaml b/tests/Application/config/packages/test_without_fosrest/winzou_state_machine.yaml new file mode 100644 index 000000000..5854ae021 --- /dev/null +++ b/tests/Application/config/packages/test_without_fosrest/winzou_state_machine.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: '../test/winzou_state_machine.yaml' } diff --git a/tests/Application/config/packages/test_without_hateoas/fos_rest.yaml b/tests/Application/config/packages/test_without_hateoas/fos_rest.yaml new file mode 100644 index 000000000..dbd0f9f27 --- /dev/null +++ b/tests/Application/config/packages/test_without_hateoas/fos_rest.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: '../test/fos_rest.yaml' } diff --git a/tests/Application/config/packages/test_without_hateoas/framework.yaml b/tests/Application/config/packages/test_without_hateoas/framework.yaml new file mode 100644 index 000000000..cf8f08807 --- /dev/null +++ b/tests/Application/config/packages/test_without_hateoas/framework.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: '../test/framework.yaml' } diff --git a/tests/Application/config/packages/test_without_hateoas/grids.yaml b/tests/Application/config/packages/test_without_hateoas/grids.yaml new file mode 100644 index 000000000..c9750ae87 --- /dev/null +++ b/tests/Application/config/packages/test_without_hateoas/grids.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: '../test/grids.yaml' } diff --git a/tests/Application/config/packages/test_without_hateoas/jms_serializer.yaml b/tests/Application/config/packages/test_without_hateoas/jms_serializer.yaml new file mode 100644 index 000000000..e236b51c9 --- /dev/null +++ b/tests/Application/config/packages/test_without_hateoas/jms_serializer.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: '../test/jms_serializer.yaml' } diff --git a/tests/Application/config/packages/test_without_hateoas/sylius_grid.yaml b/tests/Application/config/packages/test_without_hateoas/sylius_grid.yaml new file mode 100644 index 000000000..b702c5814 --- /dev/null +++ b/tests/Application/config/packages/test_without_hateoas/sylius_grid.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: '../test/sylius_grid.yaml' } diff --git a/tests/Application/config/packages/test_without_hateoas/twig.yaml b/tests/Application/config/packages/test_without_hateoas/twig.yaml new file mode 100644 index 000000000..7a00b552f --- /dev/null +++ b/tests/Application/config/packages/test_without_hateoas/twig.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: '../test/twig.yaml' } diff --git a/tests/Application/config/packages/test_without_hateoas/winzou_state_machine.yaml b/tests/Application/config/packages/test_without_hateoas/winzou_state_machine.yaml new file mode 100644 index 000000000..5854ae021 --- /dev/null +++ b/tests/Application/config/packages/test_without_hateoas/winzou_state_machine.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: '../test/winzou_state_machine.yaml' } diff --git a/tests/Application/config/services.yaml b/tests/Application/config/services.yaml index bc87b38e3..e688256a7 100644 --- a/tests/Application/config/services.yaml +++ b/tests/Application/config/services.yaml @@ -70,14 +70,22 @@ services: - '%app.model.book_translation.class%' tags: ['form.type'] - Gedmo\Sortable\SortableListener: - calls: - - - setAnnotationReader: ['@annotation_reader'] + gedmo_doctrine_extensions.mapping.driver.attribute: + class: Gedmo\Mapping\Driver\AttributeReader + public: false + + gedmo.listener.sortable: + class: Gedmo\Sortable\SortableListener tags: - - - name: doctrine.event_subscriber - connection: default + - { name: doctrine.event_listener, event: 'onFlush' } + - { name: doctrine.event_listener, event: 'loadClassMetadata' } + - { name: doctrine.event_listener, event: 'prePersist' } + - { name: doctrine.event_listener, event: 'postPersist' } + - { name: doctrine.event_listener, event: 'preUpdate' } + - { name: doctrine.event_listener, event: 'postRemove' } + - { name: doctrine.event_listener, event: 'postFlush' } + calls: + - [ setAnnotationReader, [ "@gedmo_doctrine_extensions.mapping.driver.attribute" ] ] App\Repository\ComicBookRepository: null App\Repository\LegacyBookRepository: null diff --git a/tests/Application/src/Subscription/Entity/Subscription.php b/tests/Application/src/Subscription/Entity/Subscription.php index 29b1af116..1e2aa6e50 100644 --- a/tests/Application/src/Subscription/Entity/Subscription.php +++ b/tests/Application/src/Subscription/Entity/Subscription.php @@ -41,11 +41,12 @@ #[Update] #[Delete] #[BulkDelete] -#[ApplyStateMachineTransition(stateMachineTransition: 'accept')] -#[ApplyStateMachineTransition(stateMachineTransition: 'reject')] +#[ApplyStateMachineTransition(stateMachineTransition: 'accept', stateMachineGraph: 'subscription')] +#[ApplyStateMachineTransition(stateMachineTransition: 'reject', stateMachineGraph: 'subscription')] #[BulkUpdate( shortName: 'bulk_accept', stateMachineTransition: 'accept', + stateMachineGraph: 'subscription', )] #[Show( template: 'subscription/show.html.twig', diff --git a/tests/Application/src/Tests/Controller/BookApiTest.php b/tests/Application/src/Tests/Controller/BookApiTest.php index ef9c23950..cfec84916 100644 --- a/tests/Application/src/Tests/Controller/BookApiTest.php +++ b/tests/Application/src/Tests/Controller/BookApiTest.php @@ -23,6 +23,8 @@ class BookApiTest extends JsonApiTestCase */ public function it_allows_creating_a_book() { + $this->markAsSkippedIfNecessary(); + $data = <<markAsSkippedIfNecessary(); + $objects = $this->loadFixturesFromFile('books.yml'); $this->client->request('GET', '/books/' . $objects['book1']->getId()); @@ -115,6 +119,8 @@ public function it_allows_showing_a_book() */ public function it_allows_indexing_books() { + $this->markAsSkippedIfNecessary(); + $this->loadFixturesFromFile('books.yml'); $this->client->request('GET', '/books/'); @@ -127,6 +133,8 @@ public function it_allows_indexing_books() */ public function it_allows_paginating_the_index_of_books() { + $this->markAsSkippedIfNecessary(); + $this->loadFixturesFromFile('more_books.yml'); $this->client->request('GET', '/books/', ['page' => 2]); @@ -139,6 +147,8 @@ public function it_allows_paginating_the_index_of_books() */ public function it_does_not_allow_showing_resource_if_it_not_exists() { + $this->markAsSkippedIfNecessary(); + $this->loadFixturesFromFile('books.yml'); $this->client->request('GET', '/books/3'); @@ -151,6 +161,8 @@ public function it_does_not_allow_showing_resource_if_it_not_exists() */ public function it_does_not_apply_sorting_for_un_existing_field() { + $this->markAsSkippedIfNecessary(); + $this->loadFixturesFromFile('more_books.yml'); $this->client->request('GET', '/sortable-books/', ['sorting' => ['name' => 'DESC']]); @@ -164,6 +176,8 @@ public function it_does_not_apply_sorting_for_un_existing_field() */ public function it_does_not_apply_filtering_for_un_existing_field() { + $this->markAsSkippedIfNecessary(); + $this->loadFixturesFromFile('more_books.yml'); $this->client->request('GET', '/filterable-books/', ['criteria' => ['name' => 'John']]); @@ -177,6 +191,8 @@ public function it_does_not_apply_filtering_for_un_existing_field() */ public function it_applies_sorting_for_existing_field() { + $this->markAsSkippedIfNecessary(); + $this->loadFixturesFromFile('more_books.yml'); $this->client->request('GET', '/sortable-books/', ['sorting' => ['id' => 'DESC']]); @@ -190,6 +206,8 @@ public function it_applies_sorting_for_existing_field() */ public function it_applies_filtering_for_existing_field() { + $this->markAsSkippedIfNecessary(); + $this->loadFixturesFromFile('more_books.yml'); $this->client->request('GET', '/filterable-books/', ['criteria' => ['author' => 'J.R.R. Tolkien']]); @@ -203,6 +221,8 @@ public function it_applies_filtering_for_existing_field() */ public function it_allows_creating_a_book_via_custom_factory() { + $this->markAsSkippedIfNecessary(); + $data = <<markAsSkippedIfNecessary(); + $this->loadFixturesFromFile('books.yml'); $this->client->request('GET', '/find-custom-books'); @@ -237,10 +259,19 @@ public function it_allows_indexing_books_via_custom_repository(): void */ public function it_allows_showing_a_book_via_custom_repository() { + $this->markAsSkippedIfNecessary(); + $this->loadFixturesFromFile('books.yml'); $this->client->request('GET', '/find-custom-book'); $response = $this->client->getResponse(); $this->assertResponse($response, 'books/show_response'); } + + private function markAsSkippedIfNecessary(): void + { + if ('test_without_hateoas' === self::$sharedKernel->getEnvironment()) { + $this->markTestSkipped(); + } + } } diff --git a/tests/Application/src/Tests/Controller/ComicBookApiTest.php b/tests/Application/src/Tests/Controller/ComicBookApiTest.php index d4ece7e29..7a5286a79 100644 --- a/tests/Application/src/Tests/Controller/ComicBookApiTest.php +++ b/tests/Application/src/Tests/Controller/ComicBookApiTest.php @@ -44,6 +44,8 @@ public function it_allows_creating_a_comic_book() */ public function it_allows_versioned_creating_a_comic_book() { + $this->markAsSkippedIfNecessary(); + $data = <<markAsSkippedIfNecessary(); + $objects = $this->loadFixturesFromFile('comic_books.yml'); $this->client->request('GET', '/v1.2/comic-books/' . $objects['comic-book1']->getId()); @@ -146,6 +150,8 @@ public function it_allows_versioning_of_a_showing_comic_book_serialization() */ public function it_allows_indexing_of_comic_books() { + $this->markAsSkippedIfNecessary(); + $this->loadFixturesFromFile('comic_books.yml'); $this->client->request('GET', '/v1/comic-books/'); @@ -158,6 +164,8 @@ public function it_allows_indexing_of_comic_books() */ public function it_allows_versioned_indexing_of_comic_books() { + $this->markAsSkippedIfNecessary(); + $this->loadFixturesFromFile('comic_books.yml'); $this->client->request('GET', '/v1.2/comic-books/'); @@ -176,4 +184,11 @@ public function it_does_not_allow_showing_resource_if_it_does_not_exist() $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_NOT_FOUND); } + + private function markAsSkippedIfNecessary(): void + { + if ('test_without_hateoas' === self::$sharedKernel->getEnvironment()) { + $this->markTestSkipped(); + } + } } From 27890ef4d9610ed75aff17efad6dda40ecb0b9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Fri, 31 May 2024 08:39:13 +0200 Subject: [PATCH 22/22] [SF7] Bump Winzou state machine version --- .github/workflows/build.yml | 4 ---- composer.json | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 713344ced..050e9ce2d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -93,10 +93,6 @@ jobs: if: matrix.collections != '' run: composer require "doctrine/collections:${{ matrix.collections }}" --no-update --no-scripts - - - name: Upgrade winzou-state-machine to dev branch - run: composer require "winzou/state-machine-bundle" "dev-master" --no-update --no-scripts - - name: Remove hateoas on Symfony 7 if: matrix.symfony == '^7.0' diff --git a/composer.json b/composer.json index 39b22c043..f26f8076a 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "symfony/validator": "^5.4 || ^6.4 || ^7.0", "symfony/yaml": "^5.4 || ^6.4 || ^7.0", "webmozart/assert": "^1.8", - "winzou/state-machine-bundle": "^0.6", + "winzou/state-machine-bundle": "^0.6.2", "willdurand/negotiation": "^3.1" }, "replace": {