Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
igormukhingmailcom committed Sep 16, 2020
1 parent dad5ede commit 78ad4d1
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 44 deletions.
44 changes: 19 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -115,7 +109,7 @@
"@ensure-vendors-installed",
"@assets",
"@fixtures",
"@run"
"@server-run"
]
}
}
22 changes: 22 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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

17 changes: 6 additions & 11 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
</testsuite>
</testsuites>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

<php>
<env name="APP_ENV" value="test"/>
<env name="SHELL_VERBOSITY" value="-1" />
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/LoevgaardSyliusBarcodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
8 changes: 8 additions & 0 deletions tests/Application/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion tests/Application/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
];
1 change: 1 addition & 0 deletions tests/Application/config/packages/_sylius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
11 changes: 7 additions & 4 deletions tests/Application/config/packages/doctrine_migrations.yaml
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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)%'
50 changes: 49 additions & 1 deletion tests/Application/config/packages/security.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
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:
sylius_admin_user_provider:
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:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/Application/config/routes/sylius_api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sylius_api:
resource: "@SyliusApiBundle/Resources/config/routing.yml"
prefix: "%sylius.security.new_api_route%"
1 change: 1 addition & 0 deletions tests/Application/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)%'

0 comments on commit 78ad4d1

Please sign in to comment.