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
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 7d654bb..38229c7 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",
@@ -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",
@@ -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",
@@ -54,7 +54,7 @@
},
"extra": {
"branch-alias": {
- "dev-master": "1.0-dev"
+ "dev-master": "2.0-dev"
}
},
"autoload": {
@@ -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/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/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
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/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..2f8d825 100644
--- a/src/EventListener/TagSubscriber.php
+++ b/src/EventListener/TagSubscriber.php
@@ -14,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
{
@@ -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();
+ }
}
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..0fa7f6f 100644
--- a/tests/Application/config/packages/framework.yaml
+++ b/tests/Application/config/packages/framework.yaml
@@ -2,6 +2,6 @@ framework:
secret: '%env(APP_SECRET)%'
form: true
csrf_protection: true
- templating: { engines: ["twig"] }
session:
handler_id: ~
+ assets: true
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%"
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
{