From a127aa2a926c0ccfb829ec5c57ff6e12533f681a Mon Sep 17 00:00:00 2001 From: Youri Westerman Date: Thu, 9 Sep 2021 11:22:19 +0200 Subject: [PATCH 01/11] Support PHP 8 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7d654bb..9b23698 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "license": "MIT", "require": { - "php": "^7.4", + "php": ">=7.4", "ext-json": "*", "doctrine/collections": "^1.6", "knplabs/knp-menu": "^3.1", From 6a429557f3fbe7cfe1a9f475aa0e84ba7b3918fe Mon Sep 17 00:00:00 2001 From: Youri Westerman Date: Thu, 9 Sep 2021 11:27:22 +0200 Subject: [PATCH 02/11] Run tests and checks on PHP 8 as well --- .github/workflows/build.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 250c4ce..a6746de 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -22,6 +22,7 @@ jobs: matrix: php-version: - "7.4" + - "8.0" dependencies: - "highest" @@ -66,6 +67,7 @@ jobs: matrix: php-version: - "7.4" + - "8.0" dependencies: - "highest" @@ -102,6 +104,7 @@ jobs: matrix: php-version: - "7.4" + - "8.0" dependencies: - "highest" @@ -137,6 +140,7 @@ jobs: matrix: php-version: - "7.4" + - "8.0" dependencies: - "lowest" @@ -170,6 +174,7 @@ jobs: matrix: php-version: - "7.4" + - "8.0" dependencies: - "highest" @@ -217,6 +222,7 @@ jobs: matrix: php-version: - "7.4" + - "8.0" dependencies: - "highest" From dee6db250b2786ae403b38bf2c257b44a1eeea2e Mon Sep 17 00:00:00 2001 From: Youri Westerman Date: Wed, 20 Oct 2021 14:55:06 +0200 Subject: [PATCH 03/11] Support newer event dispatcher contracts version as it is required for event dispatcher 5.3 (as part of Symfony 5.3) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9b23698..bcb1276 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "symfony/config": "^4.4 || ^5.0", "symfony/dependency-injection": "^4.4 || ^5.0", "symfony/event-dispatcher": "^4.4 || ^5.0", - "symfony/event-dispatcher-contracts": "^1.1", + "symfony/event-dispatcher-contracts": "^1.1 || ^2.3", "symfony/form": "^4.4 || ^5.0", "symfony/http-foundation": "^4.4 || ^5.0.7", "symfony/http-kernel": "^4.4 || ^5.0", From 5a77ae04afddc8adf6696b74e2ab99d63abc1e02 Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Tue, 26 Oct 2021 15:50:48 +0200 Subject: [PATCH 04/11] feat: add changelog --- CHANGELOG.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..34df0e5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,23 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +## [2.0.x] - 2021-04-15 + +### Added +- Support for Symfony 5.x (<5.3) +- Danish translations +- French translations + +### Changed +- Removed usage of Safe library for json encode/decode, now using native PHP constant `JSON_THROW_ON_ERROR` +- Performance: `PropertyContext` now caches the properties +- Now using TagBag library instead of TagBagBundle (from Setono as well) +- Add a tag for each property in the library subscriber (previously only one tag were added containing all properties) +- Added psalm to the CI, the codebase has been updated and is now more type-safe + +### Removed +- Support for Symfony 4.1 and older +- Option `resources.property.classes.interface` does not exists anymore From bd0986c1577e4ef9582845aa96626b222159c01f Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Tue, 26 Oct 2021 18:47:21 +0200 Subject: [PATCH 05/11] fix: branch alias in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bcb1276..1777d8d 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.0-dev" } }, "autoload": { From f53db3bd6a23104b3d8f1f333d8d95744883ee44 Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Tue, 26 Oct 2021 18:47:40 +0200 Subject: [PATCH 06/11] update: test suite to Sylius 1.10 This is the only way to test with PHP 8.x and Symfony 5. --- composer.json | 4 ++-- tests/Application/Kernel.php | 19 ------------------- tests/Application/config/bundles.php | 10 ++++++---- .../Application/config/packages/_sylius.yaml | 3 +-- .../config/packages/dev/jms_serializer.yaml | 7 ++++++- .../config/packages/doctrine_migrations.yaml | 7 +++---- .../config/packages/framework.yaml | 1 - .../config/packages/jms_serializer.yaml | 2 +- .../packages/lexik_jwt_authentication.yaml | 3 +++ .../config/packages/prod/jms_serializer.yaml | 7 ++++++- .../Application/config/packages/security.yaml | 15 +-------------- tests/Application/config/routes/dev/twig.yaml | 3 --- .../config/routes/sylius_admin_api.yaml | 3 --- .../Application/config/routes/sylius_api.yaml | 3 +++ 14 files changed, 32 insertions(+), 55 deletions(-) create mode 100644 tests/Application/config/packages/lexik_jwt_authentication.yaml delete mode 100644 tests/Application/config/routes/dev/twig.yaml delete mode 100644 tests/Application/config/routes/sylius_admin_api.yaml create mode 100644 tests/Application/config/routes/sylius_api.yaml diff --git a/composer.json b/composer.json index 1777d8d..4fc32aa 100644 --- a/composer.json +++ b/composer.json @@ -40,10 +40,10 @@ "phpunit/phpunit": "^9.5", "psalm/plugin-symfony": "^2.2", "roave/security-advisories": "dev-master", - "setono/code-quality-pack": "^1.5.2", + "setono/code-quality-pack": "^2.1.2", "setono/sylius-behat-pack": "^0.1", "setono/sylius-tag-bag-plugin": "^1.1", - "sylius/sylius": "~1.7.0", + "sylius/sylius": "~1.10.0", "symfony/debug-bundle": "^4.4 || ^5.0", "symfony/dotenv": "^4.4 || ^5.0", "symfony/intl": "^4.4 || ^5.0", diff --git a/tests/Application/Kernel.php b/tests/Application/Kernel.php index c136c8a..1a973a8 100644 --- a/tests/Application/Kernel.php +++ b/tests/Application/Kernel.php @@ -80,25 +80,6 @@ protected function getContainerBaseClass(): string return parent::getContainerBaseClass(); } - protected function getContainerLoader(ContainerInterface $container): LoaderInterface - { - /** @var ContainerBuilder $container */ - Assert::isInstanceOf($container, ContainerBuilder::class); - - $locator = new FileLocator($this, $this->getRootDir() . '/Resources'); - $resolver = new LoaderResolver(array( - new XmlFileLoader($container, $locator), - new YamlFileLoader($container, $locator), - new IniFileLoader($container, $locator), - new PhpFileLoader($container, $locator), - new GlobFileLoader($container, $locator), - new DirectoryLoader($container, $locator), - new ClosureLoader($container), - )); - - return new DelegatingLoader($resolver); - } - private function isTestEnvironment(): bool { return 0 === strpos($this->getEnvironment(), 'test'); diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index 9896e51..2706968 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -7,7 +7,6 @@ Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], - Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true], Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true], Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true], Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true], @@ -48,16 +47,19 @@ Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true], Payum\Bundle\PayumBundle\PayumBundle::class => ['all' => true], Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true], - WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle::class => ['all' => true], + BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], + SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], Sylius\Bundle\FixturesBundle\SyliusFixturesBundle::class => ['all' => true], Sylius\Bundle\PayumBundle\SyliusPayumBundle::class => ['all' => true], Sylius\Bundle\ThemeBundle\SyliusThemeBundle::class => ['all' => true], Sylius\Bundle\AdminBundle\SyliusAdminBundle::class => ['all' => true], Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true], - FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true], - Sylius\Bundle\AdminApiBundle\SyliusAdminApiBundle::class => ['all' => true], + ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], + Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true], + Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true], Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true], Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true], FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true], + SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], ]; diff --git a/tests/Application/config/packages/_sylius.yaml b/tests/Application/config/packages/_sylius.yaml index e45fc71..51b3306 100644 --- a/tests/Application/config/packages/_sylius.yaml +++ b/tests/Application/config/packages/_sylius.yaml @@ -1,9 +1,8 @@ imports: - { resource: "@SyliusCoreBundle/Resources/config/app/config.yml" } - { resource: "@SyliusAdminBundle/Resources/config/app/config.yml" } - - { resource: "@SyliusAdminApiBundle/Resources/config/app/config.yml" } - { resource: "@SyliusShopBundle/Resources/config/app/config.yml" } - + - { resource: "@SyliusApiBundle/Resources/config/app/config.yaml" } - { resource: "@SetonoSyliusAnalyticsPlugin/Resources/config/app/config.yaml" } parameters: diff --git a/tests/Application/config/packages/dev/jms_serializer.yaml b/tests/Application/config/packages/dev/jms_serializer.yaml index 353e460..2f32a9b 100644 --- a/tests/Application/config/packages/dev/jms_serializer.yaml +++ b/tests/Application/config/packages/dev/jms_serializer.yaml @@ -1,6 +1,11 @@ jms_serializer: visitors: - json: + json_serialization: + options: + - JSON_PRETTY_PRINT + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION + json_deserialization: options: - JSON_PRETTY_PRINT - JSON_UNESCAPED_SLASHES diff --git a/tests/Application/config/packages/doctrine_migrations.yaml b/tests/Application/config/packages/doctrine_migrations.yaml index c0a1202..cdbc01a 100644 --- a/tests/Application/config/packages/doctrine_migrations.yaml +++ b/tests/Application/config/packages/doctrine_migrations.yaml @@ -1,5 +1,4 @@ doctrine_migrations: - dir_name: "%kernel.project_dir%/src/Migrations" - - # Namespace is arbitrary but should be different from App\Migrations as migrations classes should NOT be autoloaded - namespace: DoctrineMigrations + storage: + table_storage: + table_name: sylius_migrations diff --git a/tests/Application/config/packages/framework.yaml b/tests/Application/config/packages/framework.yaml index e74ed81..9b44501 100644 --- a/tests/Application/config/packages/framework.yaml +++ b/tests/Application/config/packages/framework.yaml @@ -2,6 +2,5 @@ framework: secret: '%env(APP_SECRET)%' form: true csrf_protection: true - templating: { engines: ["twig"] } session: handler_id: ~ diff --git a/tests/Application/config/packages/jms_serializer.yaml b/tests/Application/config/packages/jms_serializer.yaml index 64dd8d1..ed7bc61 100644 --- a/tests/Application/config/packages/jms_serializer.yaml +++ b/tests/Application/config/packages/jms_serializer.yaml @@ -1,4 +1,4 @@ jms_serializer: visitors: - xml: + xml_serialization: format_output: '%kernel.debug%' diff --git a/tests/Application/config/packages/lexik_jwt_authentication.yaml b/tests/Application/config/packages/lexik_jwt_authentication.yaml new file mode 100644 index 0000000..a6d2a48 --- /dev/null +++ b/tests/Application/config/packages/lexik_jwt_authentication.yaml @@ -0,0 +1,3 @@ +lexik_jwt_authentication: + secret_key: '%env(resolve:JWT_SECRET_KEY)%' + public_key: '%env(resolve:JWT_PUBLIC_KEY)%' diff --git a/tests/Application/config/packages/prod/jms_serializer.yaml b/tests/Application/config/packages/prod/jms_serializer.yaml index bc97faf..a8684a2 100644 --- a/tests/Application/config/packages/prod/jms_serializer.yaml +++ b/tests/Application/config/packages/prod/jms_serializer.yaml @@ -1,6 +1,11 @@ jms_serializer: visitors: - json: + + json_serialization: + options: + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION + json_deserialization: options: - JSON_UNESCAPED_SLASHES - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/packages/security.yaml b/tests/Application/config/packages/security.yaml index 830b03d..3d850dc 100644 --- a/tests/Application/config/packages/security.yaml +++ b/tests/Application/config/packages/security.yaml @@ -1,6 +1,6 @@ parameters: sylius.security.admin_regex: "^/admin" - sylius.security.api_regex: "^/api" + sylius.security.shop_regex: "^/(?!admin|api/.*|api$|media/.*)[^/]++" security: @@ -39,17 +39,6 @@ security: target: sylius_admin_login anonymous: true - oauth_token: - pattern: "%sylius.security.api_regex%/oauth/v2/token" - security: false - - api: - pattern: "%sylius.security.api_regex%/.*" - provider: sylius_admin_user_provider - fos_oauth: true - stateless: true - anonymous: true - shop: switch_user: { role: ROLE_ALLOWED_TO_SWITCH } context: shop @@ -91,12 +80,10 @@ security: - { path: "%sylius.security.shop_regex%/_partial", role: ROLE_NO_ACCESS } - { path: "%sylius.security.admin_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } - - { path: "%sylius.security.api_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: "%sylius.security.shop_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: "%sylius.security.shop_regex%/register", role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: "%sylius.security.shop_regex%/verify", role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: "%sylius.security.admin_regex%", role: ROLE_ADMINISTRATION_ACCESS } - - { path: "%sylius.security.api_regex%/.*", role: ROLE_API_ACCESS } - { path: "%sylius.security.shop_regex%/account", role: ROLE_USER } diff --git a/tests/Application/config/routes/dev/twig.yaml b/tests/Application/config/routes/dev/twig.yaml deleted file mode 100644 index f4ee839..0000000 --- a/tests/Application/config/routes/dev/twig.yaml +++ /dev/null @@ -1,3 +0,0 @@ -_errors: - resource: '@TwigBundle/Resources/config/routing/errors.xml' - prefix: /_error diff --git a/tests/Application/config/routes/sylius_admin_api.yaml b/tests/Application/config/routes/sylius_admin_api.yaml deleted file mode 100644 index 80aed45..0000000 --- a/tests/Application/config/routes/sylius_admin_api.yaml +++ /dev/null @@ -1,3 +0,0 @@ -sylius_admin_api: - resource: "@SyliusAdminApiBundle/Resources/config/routing.yml" - prefix: /api diff --git a/tests/Application/config/routes/sylius_api.yaml b/tests/Application/config/routes/sylius_api.yaml new file mode 100644 index 0000000..ae01ffc --- /dev/null +++ b/tests/Application/config/routes/sylius_api.yaml @@ -0,0 +1,3 @@ +sylius_api: + resource: "@SyliusApiBundle/Resources/config/routing.yml" + prefix: "%sylius.security.new_api_route%" From 230439eb7a31bc69638930671fa128430ec6aa81 Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Tue, 26 Oct 2021 18:49:44 +0200 Subject: [PATCH 07/11] fix: test suite is not compatible with PHP 8.0 --- .github/workflows/build.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a6746de..250c4ce 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -22,7 +22,6 @@ jobs: matrix: php-version: - "7.4" - - "8.0" dependencies: - "highest" @@ -67,7 +66,6 @@ jobs: matrix: php-version: - "7.4" - - "8.0" dependencies: - "highest" @@ -104,7 +102,6 @@ jobs: matrix: php-version: - "7.4" - - "8.0" dependencies: - "highest" @@ -140,7 +137,6 @@ jobs: matrix: php-version: - "7.4" - - "8.0" dependencies: - "lowest" @@ -174,7 +170,6 @@ jobs: matrix: php-version: - "7.4" - - "8.0" dependencies: - "highest" @@ -222,7 +217,6 @@ jobs: matrix: php-version: - "7.4" - - "8.0" dependencies: - "highest" From 7fc9d94363d857ad40cf4c43e4a774c7146049c5 Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Wed, 27 Oct 2021 15:13:08 +0200 Subject: [PATCH 08/11] feat: update changes required by psalm & cs --- bin/remove-dev-info-of-deps.php | 0 src/DependencyInjection/Configuration.php | 13 ++----------- src/EventListener/AddLibrarySubscriber.php | 2 +- src/EventListener/BeginCheckoutSubscriber.php | 2 +- src/EventListener/PurchaseSubscriber.php | 2 +- src/EventListener/TagSubscriber.php | 12 ++++++++++++ 6 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 bin/remove-dev-info-of-deps.php diff --git a/bin/remove-dev-info-of-deps.php b/bin/remove-dev-info-of-deps.php new file mode 100644 index 0000000..e69de29 diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 4ed646a..e01e407 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -20,15 +20,13 @@ public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('setono_sylius_analytics'); - /** @var ArrayNodeDefinition $rootNode */ $rootNode = $treeBuilder->getRootNode(); /** @psalm-suppress PossiblyUndefinedMethod,PossiblyNullReference */ $rootNode ->addDefaultsIfNotSet() ->children() - ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->cannotBeEmpty()->end() - ->end() + ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->cannotBeEmpty() ; $this->addResourcesSection($rootNode); @@ -55,14 +53,7 @@ private function addResourcesSection(ArrayNodeDefinition $node): void ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() ->scalarNode('repository')->defaultValue(PropertyRepository::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(Factory::class)->end() - ->scalarNode('form')->defaultValue(PropertyType::class)->cannotBeEmpty()->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ->end() + ->scalarNode('form')->defaultValue(PropertyType::class)->cannotBeEmpty() ; } } diff --git a/src/EventListener/AddLibrarySubscriber.php b/src/EventListener/AddLibrarySubscriber.php index 5166524..e022e04 100644 --- a/src/EventListener/AddLibrarySubscriber.php +++ b/src/EventListener/AddLibrarySubscriber.php @@ -23,7 +23,7 @@ public function add(RequestEvent $event): void { $request = $event->getRequest(); - if (!$event->isMasterRequest() || !$this->isShopContext($request)) { + if (!$this->isMainRequest($event) || !$this->isShopContext($request)) { return; } diff --git a/src/EventListener/BeginCheckoutSubscriber.php b/src/EventListener/BeginCheckoutSubscriber.php index 8c01b75..47c9a92 100644 --- a/src/EventListener/BeginCheckoutSubscriber.php +++ b/src/EventListener/BeginCheckoutSubscriber.php @@ -23,7 +23,7 @@ public function track(RequestEvent $event): void { $request = $event->getRequest(); - if (!$event->isMasterRequest() || !$this->isShopContext($request)) { + if (!$this->isMainRequest($event) || !$this->isShopContext($request)) { return; } diff --git a/src/EventListener/PurchaseSubscriber.php b/src/EventListener/PurchaseSubscriber.php index bf08cd0..0db49e1 100644 --- a/src/EventListener/PurchaseSubscriber.php +++ b/src/EventListener/PurchaseSubscriber.php @@ -48,7 +48,7 @@ public function track(RequestEvent $event): void { $request = $event->getRequest(); - if (!$event->isMasterRequest() || !$this->isShopContext($request)) { + if (!$this->isMainRequest($event) || !$this->isShopContext($request)) { return; } diff --git a/src/EventListener/TagSubscriber.php b/src/EventListener/TagSubscriber.php index 780dd25..d2a053a 100644 --- a/src/EventListener/TagSubscriber.php +++ b/src/EventListener/TagSubscriber.php @@ -4,6 +4,7 @@ namespace Setono\SyliusAnalyticsPlugin\EventListener; +use Symfony\Component\HttpKernel\Event\RequestEvent; use function count; use Psr\EventDispatcher\EventDispatcherInterface; use Setono\SyliusAnalyticsPlugin\Context\PropertyContextInterface; @@ -73,4 +74,15 @@ protected function isShopContext(Request $request = null): bool return $firewallConfig->getName() === 'shop'; } + + protected function isMainRequest(RequestEvent $event): bool + { + if (method_exists($event, 'isMainRequest')) { + return $event->isMainRequest(); + } + + // BC Layer for Symfony < 5.3 + /** @psalm-suppress DeprecatedMethod */ + return $event->isMasterRequest(); + } } From de765f14fd2a4b0e85d6c8c4887a4750eabc92b2 Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Wed, 27 Oct 2021 15:13:38 +0200 Subject: [PATCH 09/11] fix: behat tests in Symfony 5.3 https://github.com/symfony/symfony/issues/41672 is blocking to update the behat test suite. This is why I decided to add this patch. It should not have any specific impact but for the dev environment. After the issue has been closed on Symfony side, this commit has been edited and is now a simple line :tada: --- bin/remove-dev-info-of-deps.php | 0 tests/Application/config/packages/framework.yaml | 1 + 2 files changed, 1 insertion(+) delete mode 100644 bin/remove-dev-info-of-deps.php diff --git a/bin/remove-dev-info-of-deps.php b/bin/remove-dev-info-of-deps.php deleted file mode 100644 index e69de29..0000000 diff --git a/tests/Application/config/packages/framework.yaml b/tests/Application/config/packages/framework.yaml index 9b44501..0fa7f6f 100644 --- a/tests/Application/config/packages/framework.yaml +++ b/tests/Application/config/packages/framework.yaml @@ -4,3 +4,4 @@ framework: csrf_protection: true session: handler_id: ~ + assets: true From 133c1a56239ffe059d5a1663852441ac815e3809 Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Tue, 2 Nov 2021 16:32:43 +0100 Subject: [PATCH 10/11] feat: make ecs config work This commit also fixes some CS issues. Please notice that this configuration is coming from the setono feed bundle. --- ecs.php | 16 ++++++++++++++++ src/Builder/Builder.php | 9 ++++++--- src/EventListener/TagSubscriber.php | 2 +- .../Page/Admin/Property/UpdatePropertyPage.php | 2 +- 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 ecs.php diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..fb1d739 --- /dev/null +++ b/ecs.php @@ -0,0 +1,16 @@ +import('vendor/sylius-labs/coding-standard/ecs.php'); + $containerConfigurator->parameters()->set(Option::PATHS, [ + 'src', 'tests', 'spec' + ]); + $containerConfigurator->parameters()->set(Option::SKIP, [ + 'tests/Application/**', + ]); +}; diff --git a/src/Builder/Builder.php b/src/Builder/Builder.php index ba46594..d6be10e 100644 --- a/src/Builder/Builder.php +++ b/src/Builder/Builder.php @@ -39,8 +39,10 @@ public function getData(): array public function getJson(): string { - return json_encode($this->data, - JSON_UNESCAPED_SLASHES | JSON_PRESERVE_ZERO_FRACTION | JSON_INVALID_UTF8_IGNORE | JSON_INVALID_UTF8_SUBSTITUTE | JSON_THROW_ON_ERROR); + return json_encode( + $this->data, + JSON_UNESCAPED_SLASHES | JSON_PRESERVE_ZERO_FRACTION | JSON_INVALID_UTF8_IGNORE | JSON_INVALID_UTF8_SUBSTITUTE | JSON_THROW_ON_ERROR + ); } /** @@ -79,7 +81,8 @@ public function __call($name, array $arguments) if (!is_scalar($val) && !is_array($val)) { throw new InvalidArgumentException(sprintf( 'Unexpected type %s. Expected types are: callable, %s or scalar', - is_object($val) ? get_class($val) : gettype($val), BuilderInterface::class + is_object($val) ? get_class($val) : gettype($val), + BuilderInterface::class )); } diff --git a/src/EventListener/TagSubscriber.php b/src/EventListener/TagSubscriber.php index d2a053a..2f8d825 100644 --- a/src/EventListener/TagSubscriber.php +++ b/src/EventListener/TagSubscriber.php @@ -4,7 +4,6 @@ namespace Setono\SyliusAnalyticsPlugin\EventListener; -use Symfony\Component\HttpKernel\Event\RequestEvent; use function count; use Psr\EventDispatcher\EventDispatcherInterface; use Setono\SyliusAnalyticsPlugin\Context\PropertyContextInterface; @@ -15,6 +14,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpKernel\Event\RequestEvent; abstract class TagSubscriber implements EventSubscriberInterface { diff --git a/tests/Behat/Page/Admin/Property/UpdatePropertyPage.php b/tests/Behat/Page/Admin/Property/UpdatePropertyPage.php index 40e1dc7..992daf6 100644 --- a/tests/Behat/Page/Admin/Property/UpdatePropertyPage.php +++ b/tests/Behat/Page/Admin/Property/UpdatePropertyPage.php @@ -19,7 +19,7 @@ public function getTrackingId(): string } /** - * {@inheritdoc} + * @inheritdoc */ protected function getDefinedElements(): array { From 03064e1d3cd5eb06d224032aabbfbee3f7e29f3a Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Tue, 2 Nov 2021 17:18:08 +0100 Subject: [PATCH 11/11] fix: psalm test suite on CI This commit fixes the following problems: 1. The script inside composer.json was failing because on Github Action it runs with SH and not BASH (fixed by making it external) 2. Since we run Symfony 5.x, we need to adapt the psalm configuration of the Symfony plugin. --- bin/container-exists.sh | 2 ++ composer.json | 2 +- psalm.xml | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 bin/container-exists.sh diff --git a/bin/container-exists.sh b/bin/container-exists.sh new file mode 100644 index 0000000..baa391b --- /dev/null +++ b/bin/container-exists.sh @@ -0,0 +1,2 @@ +#!/bin/bash +[[ -f tests/Application/var/cache/test/ApplicationTests_Setono_SyliusAnalyticsPlugin_Application_KernelTestDebugContainer.xml ]] || tests/Application/bin/console cache:warmup --env=test diff --git a/composer.json b/composer.json index 4fc32aa..38229c7 100644 --- a/composer.json +++ b/composer.json @@ -77,7 +77,7 @@ "psalm" ], "check-style": "ecs check --ansi spec/ src/ tests/", - "ensure-test-container-exists": "[[ -f tests/Application/var/cache/test/ApplicationTests_Setono_SyliusAnalyticsPlugin_Application_KernelTestDebugContainer.xml ]] || tests/Application/bin/console cache:warmup --env=test", + "ensure-test-container-exists": "bash bin/container-exists.sh", "fix-style": "ecs check --ansi spec/ src/ tests/ --fix", "phpspec": "phpspec run", "phpunit": "phpunit", diff --git a/psalm.xml b/psalm.xml index 56552be..49a5c17 100644 --- a/psalm.xml +++ b/psalm.xml @@ -13,7 +13,10 @@ + tests/Application/var/cache/test/ApplicationTests_Setono_SyliusAnalyticsPlugin_Application_KernelTestDebugContainer.xml + + tests/Application/var/cache/test/Tests_Setono_SyliusAnalyticsPlugin_Application_KernelTestDebugContainer.xml