From 78ad4d17b8dc8b32a5618d6aad0e3f9b8197a2b1 Mon Sep 17 00:00:00 2001 From: Igor Mukhin Date: Wed, 16 Sep 2020 16:15:44 +0300 Subject: [PATCH] WIP --- composer.json | 44 +++++++--------- phpstan-baseline.neon | 22 ++++++++ phpstan.neon | 17 +++---- phpunit.xml.dist | 6 +++ .../LoevgaardSyliusBarcodeExtension.php | 4 +- tests/Application/.env | 8 +++ tests/Application/config/bundles.php | 6 ++- .../Application/config/packages/_sylius.yaml | 1 + .../config/packages/doctrine_migrations.yaml | 11 ++-- .../packages/lexik_jwt_authentication.yaml | 4 ++ .../Application/config/packages/security.yaml | 50 ++++++++++++++++++- .../config/routes/sylius_api.yaml | 3 ++ tests/Application/config/services.yaml | 1 + 13 files changed, 133 insertions(+), 44 deletions(-) create mode 100644 phpstan-baseline.neon create mode 100644 tests/Application/config/packages/lexik_jwt_authentication.yaml create mode 100644 tests/Application/config/routes/sylius_api.yaml diff --git a/composer.json b/composer.json index 7d166e7..08fc067 100644 --- a/composer.json +++ b/composer.json @@ -6,40 +6,34 @@ "require": { "php": "^7.3", "setono/doctrine-orm-batcher-bundle": "^0.3.1", - "sylius/sylius": "^1.3", + "sylius/core-bundle": "^1.0", + "symfony/config": "^4.4 || ^5.0", + "symfony/dependency-injection": "^4.4 || ^5.0", "symfony/event-dispatcher": "^4.4 || ^5.0", + "symfony/http-kernel": "^4.4 || ^5.1.5", "symfony/messenger": "^4.4 || ^5.0", "thecodingmachine/safe": "^1.0", "violuke/php-barcodes": "^1.0" }, "require-dev": { - "behat/behat": "^3.4", - "behat/mink": "^1.7@dev", - "behat/mink-browserkit-driver": "^1.3", - "behat/mink-extension": "^2.2", - "behat/mink-selenium2-driver": "^1.3", - "ergebnis/composer-normalize": "^2.0", - "friends-of-behat/page-object-extension": "^0.3", - "friends-of-behat/suite-settings-extension": "^1.0", - "friends-of-behat/symfony-extension": "^2.0", - "friends-of-behat/variadic-extension": "^1.1", - "lakion/mink-debug-extension": "^1.2.3", - "phpspec/phpspec": "^6.1", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-doctrine": "^0.12", - "phpstan/phpstan-strict-rules": "^0.12", - "phpstan/phpstan-webmozart-assert": "^0.12", - "phpunit/phpunit": "^8.3", + "api-platform/core": "^2.5", + "doctrine/persistence": "^1.3.8", + "lexik/jwt-authentication-bundle": "^2.8", + "phpspec/phpspec": "^6.2", + "phpunit/phpunit": "^9.2", "roave/security-advisories": "dev-master", "sensiolabs/security-checker": "^5.0", - "sylius-labs/coding-standard": "^3.1", + "setono/code-quality-pack": "^1.4", + "setono/sylius-behat-pack": "^0.1.0", + "sylius/sylius": "^1.8", "symfony/browser-kit": "^4.4 || ^5.0", "symfony/debug-bundle": "^4.4 || ^5.0", "symfony/dotenv": "^4.4 || ^5.0", "symfony/intl": "^4.4 || ^5.0", - "symfony/web-profiler-bundle": "^4.4 || ^5.0", - "symfony/web-server-bundle": "^4.4 || ^5.0", - "thecodingmachine/phpstan-safe-rule": "^1.0" + "symfony/maker-bundle": "^1.15", + "symfony/property-info": "^5.0", + "symfony/serializer": "^5.0", + "symfony/web-profiler-bundle": "^4.4 || ^5.0" }, "config": { "sort-packages": true @@ -102,9 +96,9 @@ ], "phpspec": "vendor/bin/phpspec run", "phpunit": "vendor/bin/phpunit", - "run": [ + "server-run": [ "@ensure-env-copied", - "(cd tests/Application && bin/console server:run -d public -e ${SYMFONY_ENV:-'dev'})" + "(cd tests/Application && symfony server:start --daemon)" ], "tests": [ "@phpspec", @@ -115,7 +109,7 @@ "@ensure-vendors-installed", "@assets", "@fixtures", - "@run" + "@server-run" ] } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..bcda930 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,22 @@ +parameters: + ignoreErrors: + - + message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) invoked with 2 parameters, 1 required\\.$#" + count: 2 + path: src/BarcodeChecker/BarcodeChecker.php + + - + message: "#^Call to function method_exists\\(\\) with 'Symfony\\\\\\\\Component\\\\\\\\Config\\\\\\\\Definition\\\\\\\\Builder\\\\\\\\TreeBuilder' and 'getRootNode' will always evaluate to true\\.$#" + count: 1 + path: src/DependencyInjection/Configuration.php + + - + message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#" + count: 1 + path: src/DependencyInjection/Configuration.php + + - + message: "#^Parameter \\#1 \\$configuration of method Symfony\\\\Component\\\\DependencyInjection\\\\Extension\\\\Extension\\:\\:processConfiguration\\(\\) expects Symfony\\\\Component\\\\Config\\\\Definition\\\\ConfigurationInterface, Symfony\\\\Component\\\\Config\\\\Definition\\\\ConfigurationInterface\\|null given\\.$#" + count: 1 + path: src/DependencyInjection/LoevgaardSyliusBarcodeExtension.php + diff --git a/phpstan.neon b/phpstan.neon index 96385bd..c861614 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,17 +1,12 @@ includes: - - vendor/phpstan/phpstan-doctrine/extension.neon - - vendor/phpstan/phpstan-webmozart-assert/extension.neon - - vendor/phpstan/phpstan-strict-rules/rules.neon - - vendor/thecodingmachine/phpstan-safe-rule/phpstan-safe-rule.neon + - phpstan-baseline.neon parameters: - reportUnmatchedIgnoredErrors: true checkMissingIterableValueType: false - excludes_analyse: - # Makes PHPStan crash - - 'src/DependencyInjection/Configuration.php' + level: max + + paths: + - src/ - ignoreErrors: - - '/Parameter #1 \$configuration of method .+processConfiguration\(\) expects .+ConfigurationInterface, .+ConfigurationInterface\|null given\./' - - '/Method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface\:\:dispatch\(\) invoked with 2 parameters, 1 required\./' + reportUnmatchedIgnoredErrors: true diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c8aa3d6..0216ef1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,6 +10,12 @@ + + + src/ + + + diff --git a/src/DependencyInjection/LoevgaardSyliusBarcodeExtension.php b/src/DependencyInjection/LoevgaardSyliusBarcodeExtension.php index af4bb6a..1d5dfad 100644 --- a/src/DependencyInjection/LoevgaardSyliusBarcodeExtension.php +++ b/src/DependencyInjection/LoevgaardSyliusBarcodeExtension.php @@ -11,9 +11,9 @@ final class LoevgaardSyliusBarcodeExtension extends Extension { - public function load(array $config, ContainerBuilder $container): void + public function load(array $configs, ContainerBuilder $container): void { - $config = $this->processConfiguration($this->getConfiguration([], $container), $config); + $config = $this->processConfiguration($this->getConfiguration([], $container), $configs); $container->setParameter('loevgaard_sylius_barcode.form.require', $config['form']['require']); $container->setParameter('loevgaard_sylius_barcode.form.require_valid', $config['form']['require_valid']); $container->setParameter('loevgaard_sylius_barcode.form.require_unique', $config['form']['require_unique']); diff --git a/tests/Application/.env b/tests/Application/.env index 8c7de51..6346c57 100644 --- a/tests/Application/.env +++ b/tests/Application/.env @@ -21,3 +21,11 @@ DATABASE_URL=mysql://root@127.0.0.1/sylius_barcode_%kernel.environment%?serverVe # Delivery is disabled by default via "null://localhost" MAILER_URL=smtp://localhost ###< symfony/swiftmailer-bundle ### + +###> lexik/jwt-authentication-bundle ### +JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem +JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem +JWT_PASSPHRASE=acme_plugin_development +###< lexik/jwt-authentication-bundle ### + +SYLIUS_ADMIN_ROUTING_PATH_NAME=admin diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index eecdcc0..fa5261c 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -45,7 +45,6 @@ Sylius\Bundle\FixturesBundle\SyliusFixturesBundle::class => ['all' => true], Sylius\Bundle\PayumBundle\SyliusPayumBundle::class => ['all' => true], Sylius\Bundle\ThemeBundle\SyliusThemeBundle::class => ['all' => true], - Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['all' => true], Sylius\Bundle\AdminBundle\SyliusAdminBundle::class => ['all' => true], Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true], FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true], @@ -57,4 +56,9 @@ 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], + + ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], + Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true], + Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true], + SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], ]; diff --git a/tests/Application/config/packages/_sylius.yaml b/tests/Application/config/packages/_sylius.yaml index 74b0487..37c17f8 100644 --- a/tests/Application/config/packages/_sylius.yaml +++ b/tests/Application/config/packages/_sylius.yaml @@ -5,6 +5,7 @@ imports: - { resource: "@SyliusAdminApiBundle/Resources/config/app/config.yml" } - { resource: "@SyliusShopBundle/Resources/config/app/config.yml" } + - { resource: "@SyliusApiBundle/Resources/config/app/config.yaml" } parameters: sylius_core.public_dir: '%kernel.project_dir%/public' diff --git a/tests/Application/config/packages/doctrine_migrations.yaml b/tests/Application/config/packages/doctrine_migrations.yaml index c0a1202..272f87a 100644 --- a/tests/Application/config/packages/doctrine_migrations.yaml +++ b/tests/Application/config/packages/doctrine_migrations.yaml @@ -1,5 +1,8 @@ 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 + migrations_paths: + # namespace is arbitrary but should be different from App\Migrations + # as migrations classes should NOT be autoloaded + 'DoctrineMigrations': '%kernel.project_dir%/src/Migrations' + storage: + table_storage: + table_name: 'migration_versions' 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..edfb69d --- /dev/null +++ b/tests/Application/config/packages/lexik_jwt_authentication.yaml @@ -0,0 +1,4 @@ +lexik_jwt_authentication: + secret_key: '%env(resolve:JWT_SECRET_KEY)%' + public_key: '%env(resolve:JWT_PUBLIC_KEY)%' + pass_phrase: '%env(JWT_PASSPHRASE)%' diff --git a/tests/Application/config/packages/security.yaml b/tests/Application/config/packages/security.yaml index 830b03d..9c23ac7 100644 --- a/tests/Application/config/packages/security.yaml +++ b/tests/Application/config/packages/security.yaml @@ -1,7 +1,9 @@ parameters: sylius.security.admin_regex: "^/admin" sylius.security.api_regex: "^/api" - sylius.security.shop_regex: "^/(?!admin|api/.*|api$|media/.*)[^/]++" + sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|new-api|api/.*|api$|media/.*)[^/]++" + sylius.security.new_api_route: "/new-api" + sylius.security.new_api_regex: "^%sylius.security.new_api_route%" security: providers: @@ -9,6 +11,13 @@ security: id: sylius.admin_user_provider.email_or_name_based sylius_shop_user_provider: id: sylius.shop_user_provider.email_or_name_based + sylius_api_admin_user_provider: + id: sylius.admin_user_provider.email_or_name_based + sylius_api_shop_user_provider: + id: sylius.shop_user_provider.email_or_name_based + sylius_api_chain_provider: + chain: + providers: [ sylius_api_shop_user_provider, sylius_api_admin_user_provider ] encoders: Sylius\Component\User\Model\UserInterface: sha512 firewalls: @@ -80,6 +89,45 @@ security: success_handler: sylius.handler.shop_user_logout anonymous: true + new_api_admin_user: + pattern: "%sylius.security.new_api_route%/admin-user-authentication-token" + provider: sylius_admin_user_provider + stateless: true + anonymous: true + json_login: + check_path: "%sylius.security.new_api_route%/admin-user-authentication-token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + new_api_shop_user: + pattern: "%sylius.security.new_api_route%/shop-user-authentication-token" + provider: sylius_shop_user_provider + stateless: true + anonymous: true + json_login: + check_path: "%sylius.security.new_api_route%/shop-user-authentication-token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + new_api: + pattern: "%sylius.security.new_api_regex%/*" + provider: sylius_api_chain_provider + stateless: true + anonymous: lazy + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false 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/Application/config/services.yaml b/tests/Application/config/services.yaml index 615506e..1d23e8a 100644 --- a/tests/Application/config/services.yaml +++ b/tests/Application/config/services.yaml @@ -2,3 +2,4 @@ # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration parameters: locale: en_US + sylius_admin.path_prefix: '%env(resolve:SYLIUS_ADMIN_ROUTING_PATH_NAME)%'