diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9b32ddc..b4d570f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,23 +21,23 @@ jobs: strategy: fail-fast: false matrix: - php: [ "8.0" ] + php: [ "8.0", "8.1", "8.2", "8.3" ] symfony: [ "^5.4", "^6.0" ] - sylius: [ "~1.11.0", "~1.12.0" ] - node: [ "^14.17.x" ] + sylius: [ "~1.12.0", "~1.13.0" ] + node: [ "^18.x", "20.x" ] mysql: [ "8.0" ] - + exclude: - - sylius: ~1.11.0 - symfony: "^6.0" - + - sylius: "~1.13.0" + php: "8.0" + env: APP_ENV: test DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?serverVersion=${{ matrix.mysql }}" steps: - - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP @@ -50,14 +50,14 @@ jobs: - name: Setup Node - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: "${{ matrix.node }}" - name: Shutdown default MySQL run: sudo service mysql stop - + - name: Setup MySQL uses: mirromutth/mysql-action@v1.1 @@ -180,7 +180,7 @@ jobs: path: etc/build/ if-no-files-found: ignore - - + - name: Failed build Slack notification uses: rtCamp/action-slack-notify@v2 if: ${{ failure() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') }} diff --git a/composer.json b/composer.json index a9e534e..1fced54 100644 --- a/composer.json +++ b/composer.json @@ -11,12 +11,12 @@ "require": { "php": "^8.0", "bitbag/shipping-export-plugin": "^3.0", - "sylius/sylius": "~1.11.0 || ~1.12.0" + "sylius/sylius": "~1.12.0 || ~1.13.0" }, "require-dev": { - "behat/behat": "^3.6.1", - "behat/mink-selenium2-driver": "^1.4", - "bitbag/coding-standard": "^1.0.0 || ^2.0.0 ", + "behat/behat": "^3.7", + "behat/mink-selenium2-driver": "~1.6", + "bitbag/coding-standard": "^3.0.0", "dmore/behat-chrome-extension": "^1.3", "dmore/chrome-mink-driver": "^2.7", "friends-of-behat/mink": "^1.8", @@ -29,12 +29,14 @@ "friends-of-behat/variadic-extension": "^1.3", "phpspec/phpspec": "^7.0", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "0.12.85", - "phpstan/phpstan-doctrine": "0.12.33", - "phpstan/phpstan-strict-rules": "^0.12.0", - "phpstan/phpstan-webmozart-assert": "0.12.12", + "phpstan/phpstan": "^1.8.1", + "phpstan/phpstan-doctrine": "1.3.69", + "phpstan/phpstan-strict-rules": "^1.3.0", + "phpstan/phpstan-webmozart-assert": "^1.2.0", "phpunit/phpunit": "^9.5", "polishsymfonycommunity/symfony-mocker-container": "^1.0", + "nyholm/psr7": "^1.8", + "symfony/http-client": "^5.4 || ^6.0", "symfony/browser-kit": "^5.4 || ^6.0", "symfony/debug-bundle": "^5.4 || ^6.0", "symfony/dotenv": "^5.4 || ^6.0", @@ -46,12 +48,8 @@ "twig/twig": "^2.10.0" }, "conflict": { - "symfony/symfony": "4.1.8", - "symfony/browser-kit": "4.1.8", - "symfony/dom-crawler": "4.1.8", - "symfony/routing": "4.1.8", - "symfony/doctrine-bridge": "4.4.16", - "behat/mink-selenium2-driver": ">=1.7.0" + "behat/mink-selenium2-driver": ">=1.7.0", + "doctrine/persistence": "<3.0" }, "config": { "sort-packages": true, diff --git a/doc/installation.md b/doc/installation.md index 6c78e97..3ed4773 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -37,8 +37,34 @@ bitbag_sylius_inpost_plugin: ``` This plugin was made on top -of [SyliusShippingExportPlugin](https://github.com/BitBagCommerce/SyliusShippingExportPlugin), so please remember to do -the same for it's configuration. +of [SyliusShippingExportPlugin](https://github.com/BitBagCommerce/SyliusShippingExportPlugin). +Typically, Symfony Flex, if you agree, automatically adds the configuration files: +bitbag_shipping_export_plugin.yaml to the config/packages and config/routes directories. +It also adding the appropriate entry to config/bundles.php. +If it doesn't, so please remember to do the same as above for SyliusShippingExportPlugin configuration. + +### Extend entities with parameters + +You can implement this using xml-mapping or attributes. Instructions for both settings are described below. + +#### For doctrine XML-MAPPING: +If you are using doctrine xml-mapping, you have probably already removed the entries +for the entity in config/_sylius.yaml and all entity extensions are in src/Entity. +Add the following entries to config/_sylius.yaml: +``` +sylius_order: + resources: + order: + classes: + model: App\Entity\Order + +sylius_shipping: + resources: + shipping_method: + classes: + model: App\Entity\ShippingMethod + +``` Add trait and interface to your Order and ShippingMethod entity classes: @@ -47,7 +73,7 @@ Add trait and interface to your Order and ShippingMethod entity classes: declare(strict_types=1); -namespace App\Entity\Order; +namespace App\Entity; use BitBag\SyliusInPostPlugin\Model\InPostPointsAwareInterface; use Sylius\Component\Core\Model\Order as BaseOrder; @@ -64,7 +90,7 @@ class Order extends BaseOrder implements InPostPointsAwareInterface declare(strict_types=1); -namespace App\Entity\Shipping; +namespace App\Entity; use BitBag\SyliusInPostPlugin\Model\ShippingMethodImageTrait; use Sylius\Component\Core\Model\ImageAwareInterface; @@ -75,9 +101,19 @@ class ShippingMethod extends BaseShippingMethod implements ImageAwareInterface use ShippingMethodImageTrait; } ``` - -Define new Entity mapping inside your src/Resources/config/doctrine directory. (You can do it with annotations if you -prefer) +Remember to mark it appropriately in the config/doctrine.yaml configuration file. +``` +doctrine: + ... + orm: + ... + mappings: + App: + ... + type: xml + dir: '%kernel.project_dir%/src/Resources/config/doctrine' +``` +Define new Entity mapping inside your src/Resources/config/doctrine directory. ```xml @@ -88,13 +124,13 @@ prefer) xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" > - + - - - + + + @@ -105,21 +141,108 @@ prefer) ```xml - - - - + + + + + + + + - ``` -Finish the installation by updating the database schema: +#### You can do it with attributes if you prefer. Remember to mark it appropriately in the config/doctrine.yaml configuration file. +``` +doctrine: + ... + orm: + ... + mappings: + App: + ... + type: attribute + +``` +```php +point; + } + + public function setPoint(?InPostPointInterface $point): void + { + $this->point = $point; + } +} + +``` + +```php +image; + } + + public function setImage(?ImageInterface $image): void + { + $this->image = $image; + } +} + +``` +Finish the installation by updating the database schema (check in advance: [Known Issues](known_issues.md)): ``` $ bin/console doctrine:migrations:diff @@ -127,6 +250,95 @@ $ bin/console doctrine:migrations:migrate $ bin/console assets:install --symlink $ bin/console sylius:theme:assets:install --symlink ``` +### TWIG configuration +#### Adding files to the template +Copy the files below to the appropriate directories in your template. + +``` +vendor/bitbag/inpost-plugin/tests/Application/templates/bundles/SyliusAdminBundle/Order/Show/_addresses.html.twig +vendor/bitbag/inpost-plugin/tests/Application/templates/bundles/SyliusAdminBundle/ShippingMethod/_form.html.twig +``` +``` +vendor/bitbag/inpost-plugin/tests/Application/templates/bundles/SyliusShopBundle/Checkout/SelectShipping/_choice.html.twig +vendor/bitbag/inpost-plugin/tests/Application/templates/bundles/SyliusShopBundle/Common/Order/_addresses.html.twig +vendor/bitbag/inpost-plugin/tests/Application/templates/bundles/SyliusShopBundle/Grid/Action/quickReturn.html.twig +``` + +### Webpack configuration +#### Installing Webpack package + +1. Before Webpack installation, please create the `config/packages/webpack_encore.yaml` file with a content of: + + ```yaml + webpack_encore: + output_path: '%kernel.project_dir%/public/build/default' + builds: + admin: '%kernel.project_dir%/public/build/admin' + shop: '%kernel.project_dir%/public/build/shop' + app.admin: '%kernel.project_dir%/public/build/app/admin' + app.shop: '%kernel.project_dir%/public/build/app/shop' + inpost_admin: '%kernel.project_dir%/public/build/bitbag/inpost/admin' + inpost_shop: '%kernel.project_dir%/public/build/bitbag/inpost/shop' + ``` + +2. To install Webpack in your application, please run the command below: + + ```bash + $ composer require "symfony/webpack-encore-bundle" + ``` + +3. After installation, please add the line below into `config/bundles.php` file: + + ```php + return [ + ... + Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], + ]; + ``` +#### Configuring Webpack + +By a standard, the `webpack.config.js` file should be available in your repository. If not, please use [the Sylius-Standard one](https://github.com/Sylius/Sylius-Standard/blob/1.12/webpack.config.js). + +1. Please setup your `webpack.config.js` file to require the plugin's webpack configuration. To do so, please put the line below somewhere on top of your `webpack.config.js` file: + + ```javascript + const [bitbagInPostShop, bitbagInPostAdmin] = require('./vendor/bitbag/inpost-plugin/webpack.config.js'); + ``` + +2. As next step, please add the imported consts into final module exports: + + ```javascripts + module.exports = [shopConfig, adminConfig, appShopConfig, appAdminConfig, bitbagInPostShop, bitbagInPostAdmin]; + ``` + +3. Next thing is to add the asset configuration into `config/packages/assets.yaml`: + + ```yaml + framework: + assets: + packages: + admin: + json_manifest_path: '%kernel.project_dir%/public/build/admin/manifest.json' + shop: + json_manifest_path: '%kernel.project_dir%/public/build/shop/manifest.json' + app.admin: + json_manifest_path: '%kernel.project_dir%/public/build/app/admin/manifest.json' + app.shop: + json_manifest_path: '%kernel.project_dir%/public/build/app/shop/manifest.json' + inpost_shop: + json_manifest_path: '%kernel.project_dir%/public/build/bitbag/inpost/shop/manifest.json' + inpost_admin: + json_manifest_path: '%kernel.project_dir%/public/build/bitbag/inpost/admin/manifest.json' + ``` +4. Additionally, please add the `"@symfony/webpack-encore": "^1.5.0",` dependency into your `package.json` file. + +5. Now you can run the commands: + + ```bash + $ yarn install + $ yarn encore dev # or prod, depends on your environment + ``` + ## Testing & running the plugin diff --git a/ecs.php b/ecs.php index 34cb6c5..abcfbcf 100644 --- a/ecs.php +++ b/ecs.php @@ -1,14 +1,13 @@ import('vendor/bitbag/coding-standard/ecs.php'); +use Symplify\EasyCodingStandard\Config\ECSConfig; - $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::PATHS, [ - __DIR__ . '/src', - __DIR__ . '/tests', - ]); +return static function (ECSConfig $config): void { + + putenv('ALLOW_BITBAG_OS_HEADER=1'); + + $config->import('vendor/bitbag/coding-standard/ecs.php'); + $config->paths(['src', 'tests']); }; diff --git a/features/exporting_shipping_data_to_api_inpost.feature b/features/exporting_shipping_data_to_api_inpost.feature index ab03cd7..6679f79 100644 --- a/features/exporting_shipping_data_to_api_inpost.feature +++ b/features/exporting_shipping_data_to_api_inpost.feature @@ -13,7 +13,7 @@ Feature: Managing shipping gateway And it has "Organization ID" field set to "123" And it has "Environment" field set to "sandbox" And it has "Service" field set to "inpost_courier_standard" - And the store has a product "Chicken" priced at "$2" in "Web-US" channel + And the store has a product "Chicken" priced at "$2.00" in "Web-US" channel And customer "user@bitbag.pl" has placed 5 orders on the "Web-US" channel in each buying 5 "Chicken" products And the customer set the shipping address "Mike Ross" addressed it to "350 5th Ave", "10118" "New York" in the "United States" to orders And those orders were placed with "Inpost" shipping method diff --git a/phpstan.neon b/phpstan.neon index b9cae1f..dbde899 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,11 @@ parameters: + level: 8 + + paths: + - src + reportUnmatchedIgnoredErrors: false - checkMissingIterableValueType: false + treatPhpDocTypesAsCertain: false excludePaths: # Makes PHPStan crash @@ -11,4 +16,5 @@ parameters: - 'tests/Application/src/**.php' ignoreErrors: - - '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./' + - identifier: missingType.iterableValue + - identifier: missingType.generics diff --git a/spec/Api/WebClientSpec.php b/spec/Api/WebClientSpec.php index d3cb8c5..e93737a 100644 --- a/spec/Api/WebClientSpec.php +++ b/spec/Api/WebClientSpec.php @@ -13,8 +13,10 @@ use BitBag\SyliusInPostPlugin\Api\WebClient; use BitBag\SyliusInPostPlugin\Api\WebClientInterface; use BitBag\SyliusShippingExportPlugin\Entity\ShippingGatewayInterface; -use GuzzleHttp\Client; +use Psr\Http\Client\ClientInterface; use PhpSpec\ObjectBehavior; +use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; final class WebClientSpec extends ObjectBehavior { @@ -26,9 +28,13 @@ final class WebClientSpec extends ObjectBehavior public const LABEL_TYPE = "normal"; - public function let(Client $client): void + public function let( + ClientInterface $client, + RequestFactoryInterface $requestFactory, + StreamFactoryInterface $streamFactory, + ): void { - $this->beConstructedWith($client,self::LABEL_TYPE); + $this->beConstructedWith($client, $requestFactory, $streamFactory, self::LABEL_TYPE); } public function it_is_initializable(): void diff --git a/spec/EventListener/ShippingExportEventListenerSpec.php b/spec/EventListener/ShippingExportEventListenerSpec.php index c5c8494..6476d99 100644 --- a/spec/EventListener/ShippingExportEventListenerSpec.php +++ b/spec/EventListener/ShippingExportEventListenerSpec.php @@ -14,7 +14,7 @@ use BitBag\SyliusInPostPlugin\EventListener\ShippingExportEventListener; use BitBag\SyliusInPostPlugin\EventListener\ShippingExportEventListener\InPostShippingExportActionInterface; use BitBag\SyliusInPostPlugin\EventListener\ShippingExportEventListener\InPostShippingExportActionProviderInterface; -use GuzzleHttp\Exception\ClientException; +use BitBag\SyliusInPostPlugin\Exception\InvalidInPostResponseException; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Psr\Log\LoggerInterface; @@ -128,7 +128,7 @@ public function it_should_handle_when_create_shipment_throws_exception( $event->getSubject()->willReturn($shippingExport); $webClient->setShippingGateway($shippingGateway); - $webClient->createShipment($shipment)->willThrow(ClientException::class); + $webClient->createShipment($shipment)->willThrow(InvalidInPostResponseException::class); $requestStack->getSession()->willReturn($session); $session->getBag('flashes')->willReturn($flashBag); $flashBag->add(self::ERROR, self::SHIPPING_EXPORT_ERROR_MESSAGE)->shouldBeCalled(); @@ -156,7 +156,7 @@ public function it_should_handle_when_get_shipment_by_id_throws_exception( $webClient->setShippingGateway($shippingGateway); $webClient->createShipment($shipment)->willReturn(self::EXPECTED_CREATE_SHIPMENT_RESPONSE); - $webClient->getShipmentById(self::SHIPMENT_ID)->willThrow(ClientException::class); + $webClient->getShipmentById(self::SHIPMENT_ID)->willThrow(InvalidInPostResponseException::class); $requestStack->getSession()->willReturn($session); $session->getBag('flashes')->willReturn($flashBag); $flashBag->add(self::ERROR, self::SHIPPING_EXPORT_ERROR_MESSAGE)->shouldBeCalled(); diff --git a/src/Api/WebClient.php b/src/Api/WebClient.php index 5450e43..03d236e 100644 --- a/src/Api/WebClient.php +++ b/src/Api/WebClient.php @@ -1,22 +1,24 @@ apiClient = $client; + $this->requestFactory = $requestFactory; + $this->streamFactory = $streamFactory; $this->labelType = $labelType; } @@ -188,30 +200,39 @@ public function getAuthorizedHeaderWithContentType(): array } /** - * @return mixed - * - * @throws GuzzleException + * @throws InvalidInPostResponseException + * @throws ClientExceptionInterface */ public function request( string $method, string $url, array $data = [], - bool $returnJson = true - ) { - $options = [ - 'json' => $data, - 'headers' => $this->getAuthorizedHeaderWithContentType(), - ]; + bool $returnJson = true, + ): array|string { + $header = $this->getAuthorizedHeaderWithContentType(); try { - $result = $this->apiClient->request($method, $url, $options); - } catch (ClientException $exception) { - /** @var ?ResponseInterface $result */ - $result = $exception->getResponse(); - - throw new ClientException( - null !== $result ? (string) $result->getBody() : 'Request failed for url' . $url, - $exception->getRequest() + $request = $this->requestFactory + ->createRequest($method, $url) + ->withHeader('Content-Type', $header['Content-Type']) + ->withHeader('Authorization', $header['Authorization']) + ->withBody($this->streamFactory->createStream(json_encode($data))); + + $result = $this->apiClient->sendRequest($request); + $response = json_decode((string) $result->getBody(), true); + if (200 !== $result->getStatusCode() && 201 !== $result->getStatusCode()) { + throw new InvalidInPostResponseException(); + } + } catch (InvalidInPostResponseException $e) { + $error_details = $response['details'] ?? '[]'; + + throw new InvalidInPostResponseException( + sprintf( + '%s %s; details: %s', + $e->getMessage(), + $e->getErrorMessage(), + print_r($error_details, true), + ), ); } @@ -219,7 +240,7 @@ public function request( return (string) $result->getBody(); } - return \GuzzleHttp\json_decode((string) $result->getBody(), true); + return $response; } private function getAdditionalServices(): array @@ -330,7 +351,7 @@ private function resolveHouseNumber(AddressInterface $address): string 'Street "%s" is invalid. The street format must be something like %s, where %d is the house number.', $street, '"Opolska 45"', - 45 + 45, )); return end($streetParts); diff --git a/src/Api/WebClientInterface.php b/src/Api/WebClientInterface.php index 9e9c06d..49cc2ce 100644 --- a/src/Api/WebClientInterface.php +++ b/src/Api/WebClientInterface.php @@ -1,17 +1,17 @@ orderRepository = $orderRepository; $this->inPostPointFactory = $inPostPointFactory; @@ -84,8 +85,8 @@ private function addPoint(Request $request, InPostPointsAwareInterface $order): try { $pointData = $this->client->getPointByName($name); - } catch (ClientException $exception) { - $data = \GuzzleHttp\json_decode($exception->getMessage(), true); + } catch (InPostException $exception) { + $data = json_decode($exception->getMessage(), true); return new JsonResponse($data['message'], Response::HTTP_BAD_REQUEST); } diff --git a/src/DependencyInjection/BitBagSyliusInPostPluginExtension.php b/src/DependencyInjection/BitBagSyliusInPostPluginExtension.php index 272d89a..79d75a7 100644 --- a/src/DependencyInjection/BitBagSyliusInPostPluginExtension.php +++ b/src/DependencyInjection/BitBagSyliusInPostPluginExtension.php @@ -1,5 +1,12 @@ webClient = $webClient; $this->shippingExportActionProvider = $shippingExportActionProvider; @@ -73,7 +74,7 @@ public function exportShipment(ResourceControllerEvent $exportShipmentEvent): vo if (null === $shippingExport->getExternalId()) { try { $createShipmentResponse = $this->webClient->createShipment($shipment); - } catch (ClientException $exception) { + } catch (InPostException $exception) { $this->requestStack->getSession()->getBag('flashes')->add('error', 'bitbag.ui.shipping_export_error'); $this->logError($exception, $shipment); @@ -85,7 +86,7 @@ public function exportShipment(ResourceControllerEvent $exportShipmentEvent): vo try { $shipmentData = $this->webClient->getShipmentById((int) ($shippingExport->getExternalId())); - } catch (ClientException $exception) { + } catch (InPostException $exception) { $this->requestStack->getSession()->getBag('flashes')->add('error', 'bitbag.ui.shipping_export_error'); $this->logError($exception, $shipment); @@ -118,7 +119,7 @@ private function logError(\Exception $exception, ShipmentInterface $shipment): v '%s %s: %s', '[InPostPlugin] Error while exporting shipment for order number', $order->getNumber(), - $exception->getMessage() + $exception->getMessage(), ); $this->logger->error($message); diff --git a/src/EventListener/ShippingExportEventListener/InPostShippingExportActionInterface.php b/src/EventListener/ShippingExportEventListener/InPostShippingExportActionInterface.php index 32e129e..b8ff9da 100644 --- a/src/EventListener/ShippingExportEventListener/InPostShippingExportActionInterface.php +++ b/src/EventListener/ShippingExportEventListener/InPostShippingExportActionInterface.php @@ -1,9 +1,10 @@ shippingExportRepository = $shippingExportRepository; $this->webClient = $webClient; @@ -55,7 +56,7 @@ public function __construct( } /** - * @throws ClientException + * @throws InPostException */ public function execute(ShippingExportInterface $shippingExport): void { @@ -100,7 +101,7 @@ private function getFilename(ShippingExportInterface $shippingExport): string [ $shipment->getId(), $order->getNumber(), - ] + ], ); } diff --git a/src/EventListener/ShippingExportEventListener/InPostShippingExportDefaultAction.php b/src/EventListener/ShippingExportEventListener/InPostShippingExportDefaultAction.php index 933b77a..1cc95c4 100644 --- a/src/EventListener/ShippingExportEventListener/InPostShippingExportDefaultAction.php +++ b/src/EventListener/ShippingExportEventListener/InPostShippingExportDefaultAction.php @@ -1,9 +1,10 @@ getFile(), + $this->getCode(), + $this->getLine(), + ); + } +} diff --git a/src/Form/Type/Extension/SelectPaymentTypeExtension.php b/src/Form/Type/Extension/SelectPaymentTypeExtension.php index 959221d..ea9352d 100644 --- a/src/Form/Type/Extension/SelectPaymentTypeExtension.php +++ b/src/Form/Type/Extension/SelectPaymentTypeExtension.php @@ -1,9 +1,10 @@ + + + + + %bitbag.inpost.label_type% diff --git a/src/TwigExtension/ShippingInpostCodeExtension.php b/src/TwigExtension/ShippingInpostCodeExtension.php index 3d57428..139f955 100644 --- a/src/TwigExtension/ShippingInpostCodeExtension.php +++ b/src/TwigExtension/ShippingInpostCodeExtension.php @@ -1,9 +1,10 @@ isQuickReturnResolver = $isQuickReturnResolver; $this->organizationIdResolver = $organizationIdResolver; diff --git a/src/Validator/Constraint/HasAllowedPaymentMethodInPostOrder.php b/src/Validator/Constraint/HasAllowedPaymentMethodInPostOrder.php index 54e2bcd..6819446 100644 --- a/src/Validator/Constraint/HasAllowedPaymentMethodInPostOrder.php +++ b/src/Validator/Constraint/HasAllowedPaymentMethodInPostOrder.php @@ -1,9 +1,10 @@ ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], @@ -55,5 +64,4 @@ Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true], SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], - Sylius\Bundle\MailerBundle\SyliusMailerBundle::class => ['all' => true], ]; diff --git a/tests/Application/config/packages/mailer.yaml b/tests/Application/config/packages/mailer.yaml new file mode 100644 index 0000000..0a0697c --- /dev/null +++ b/tests/Application/config/packages/mailer.yaml @@ -0,0 +1,3 @@ +framework: + mailer: + dsn: '%env(MAILER_DSN)%' diff --git a/tests/Application/config/sylius/1.11/bundles.php b/tests/Application/config/sylius/1.11/bundles.php deleted file mode 100644 index 70ca608..0000000 --- a/tests/Application/config/sylius/1.11/bundles.php +++ /dev/null @@ -1,16 +0,0 @@ - ['all' => true], - SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], - Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true], - Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], -]; diff --git a/tests/Application/config/sylius/1.11/packages/swiftmailer.yaml b/tests/Application/config/sylius/1.11/packages/swiftmailer.yaml deleted file mode 100644 index 73bba27..0000000 --- a/tests/Application/config/sylius/1.11/packages/swiftmailer.yaml +++ /dev/null @@ -1,2 +0,0 @@ -swiftmailer: - url: '%env(MAILER_URL)%' diff --git a/tests/Application/config/sylius/1.11/packages/test/swiftmailer.yaml b/tests/Application/config/sylius/1.11/packages/test/swiftmailer.yaml deleted file mode 100644 index aaac242..0000000 --- a/tests/Application/config/sylius/1.11/packages/test/swiftmailer.yaml +++ /dev/null @@ -1,6 +0,0 @@ -swiftmailer: - disable_delivery: true - logging: true - spool: - type: file - path: "%kernel.cache_dir%/spool" diff --git a/tests/Application/config/sylius/1.11/packages/test_cached/swiftmailer.yaml b/tests/Application/config/sylius/1.11/packages/test_cached/swiftmailer.yaml deleted file mode 100644 index aaac242..0000000 --- a/tests/Application/config/sylius/1.11/packages/test_cached/swiftmailer.yaml +++ /dev/null @@ -1,6 +0,0 @@ -swiftmailer: - disable_delivery: true - logging: true - spool: - type: file - path: "%kernel.cache_dir%/spool" diff --git a/tests/Application/config/sylius/1.12/bundles.php b/tests/Application/config/sylius/1.12/bundles.php index 7f164c8..e11e90b 100644 --- a/tests/Application/config/sylius/1.12/bundles.php +++ b/tests/Application/config/sylius/1.12/bundles.php @@ -1,10 +1,11 @@ ['all' => true], + SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], + Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true], + League\FlysystemBundle\FlysystemBundle::class => ['all' => true], + Sylius\Abstraction\StateMachine\SyliusStateMachineAbstractionBundle::class => ['all' => true], +]; diff --git a/tests/Application/config/sylius/1.13/packages/dev/jms_serializer.yaml b/tests/Application/config/sylius/1.13/packages/dev/jms_serializer.yaml new file mode 100644 index 0000000..9bdda24 --- /dev/null +++ b/tests/Application/config/sylius/1.13/packages/dev/jms_serializer.yaml @@ -0,0 +1,12 @@ +jms_serializer: + visitors: + json_serialization: + options: + - JSON_PRETTY_PRINT + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION + json_deserialization: + options: + - JSON_PRETTY_PRINT + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/sylius/1.11/packages/jms_serializer.yaml b/tests/Application/config/sylius/1.13/packages/jms_serializer.yaml similarity index 100% rename from tests/Application/config/sylius/1.11/packages/jms_serializer.yaml rename to tests/Application/config/sylius/1.13/packages/jms_serializer.yaml diff --git a/tests/Application/config/sylius/1.13/packages/prod/jms_serializer.yaml b/tests/Application/config/sylius/1.13/packages/prod/jms_serializer.yaml new file mode 100644 index 0000000..0cc8d8f --- /dev/null +++ b/tests/Application/config/sylius/1.13/packages/prod/jms_serializer.yaml @@ -0,0 +1,10 @@ +jms_serializer: + visitors: + 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/sylius/1.11/packages/security.yaml b/tests/Application/config/sylius/1.13/packages/security.yaml similarity index 65% rename from tests/Application/config/sylius/1.11/packages/security.yaml rename to tests/Application/config/sylius/1.13/packages/security.yaml index d0f96b1..842b093 100644 --- a/tests/Application/config/sylius/1.11/packages/security.yaml +++ b/tests/Application/config/sylius/1.13/packages/security.yaml @@ -1,16 +1,5 @@ -parameters: - sylius.security.admin_regex: "^/%sylius_admin.path_name%" - sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|api/.*|api$|media/.*)[^/]++" - sylius.security.new_api_route: "/api/v2" - sylius.security.new_api_regex: "^%sylius.security.new_api_route%" - sylius.security.new_api_admin_route: "%sylius.security.new_api_route%/admin" - sylius.security.new_api_admin_regex: "^%sylius.security.new_api_admin_route%" - sylius.security.new_api_shop_route: "%sylius.security.new_api_route%/shop" - sylius.security.new_api_shop_regex: "^%sylius.security.new_api_shop_route%" - sylius.security.new_api_user_account_route: "%sylius.security.new_api_shop_route%/account" - sylius.security.new_api_user_account_regex: "^%sylius.security.new_api_user_account_route%" security: - always_authenticate_before_granting: true + enable_authenticator_manager: true providers: sylius_admin_user_provider: id: sylius.admin_user_provider.email_or_name_based @@ -20,7 +9,8 @@ security: id: sylius.shop_user_provider.email_or_name_based sylius_api_shop_user_provider: id: sylius.shop_user_provider.email_or_name_based - encoders: + + password_hashers: Sylius\Component\User\Model\UserInterface: argon2i firewalls: admin: @@ -36,7 +26,7 @@ security: default_target_path: sylius_admin_dashboard use_forward: false use_referer: true - csrf_token_generator: security.csrf.token_manager + enable_csrf: true csrf_parameter: _csrf_admin_security_token csrf_token_id: admin_authenticate remember_me: @@ -48,35 +38,33 @@ security: logout: path: sylius_admin_logout target: sylius_admin_login - anonymous: true + new_api_admin_user: pattern: "%sylius.security.new_api_admin_regex%/.*" provider: sylius_api_admin_user_provider stateless: true - anonymous: true + entry_point: jwt json_login: check_path: "%sylius.security.new_api_admin_route%/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 + jwt: true + new_api_shop_user: pattern: "%sylius.security.new_api_shop_regex%/.*" provider: sylius_api_shop_user_provider stateless: true - anonymous: true + entry_point: jwt json_login: check_path: "%sylius.security.new_api_shop_route%/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 + jwt: true + shop: switch_user: { role: ROLE_ALLOWED_TO_SWITCH } context: shop @@ -92,7 +80,7 @@ security: default_target_path: sylius_shop_homepage use_forward: false use_referer: true - csrf_token_generator: security.csrf.token_manager + enable_csrf: true csrf_parameter: _csrf_shop_security_token csrf_token_id: shop_authenticate remember_me: @@ -102,29 +90,35 @@ security: remember_me_parameter: _remember_me logout: path: sylius_shop_logout - target: sylius_shop_login + target: sylius_shop_homepage invalidate_session: false - success_handler: sylius.handler.shop_user_logout - anonymous: true + dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false + image_resolver: pattern: ^/media/cache/resolve security: false + access_control: - - { path: "%sylius.security.admin_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] } + - { path: "%sylius.security.admin_regex%/_partial", role: PUBLIC_ACCESS, ips: [127.0.0.1, ::1] } - { path: "%sylius.security.admin_regex%/_partial", role: ROLE_NO_ACCESS } - - { path: "%sylius.security.shop_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] } + - { path: "%sylius.security.shop_regex%/_partial", role: PUBLIC_ACCESS, ips: [127.0.0.1, ::1] } - { path: "%sylius.security.shop_regex%/_partial", role: ROLE_NO_ACCESS } - - { path: "%sylius.security.admin_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%/login", role: PUBLIC_ACCESS } + - { path: "%sylius.security.shop_regex%/login", role: PUBLIC_ACCESS } + + - { path: "%sylius.security.shop_regex%/register", role: PUBLIC_ACCESS } + - { path: "%sylius.security.shop_regex%/verify", role: PUBLIC_ACCESS } + - { path: "%sylius.security.admin_regex%", role: ROLE_ADMINISTRATION_ACCESS } - { path: "%sylius.security.shop_regex%/account", role: ROLE_USER } + + - { path: "%sylius.security.new_api_admin_route%/reset-password-requests", role: PUBLIC_ACCESS } - { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS } - - { path: "%sylius.security.new_api_admin_route%/authentication-token", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.new_api_admin_route%/authentication-token", role: PUBLIC_ACCESS } - { path: "%sylius.security.new_api_user_account_regex%/.*", role: ROLE_USER } - - { path: "%sylius.security.new_api_shop_route%/authentication-token", role: IS_AUTHENTICATED_ANONYMOUSLY } - - { path: "%sylius.security.new_api_shop_regex%/.*", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.new_api_shop_route%/authentication-token", role: PUBLIC_ACCESS } + - { path: "%sylius.security.new_api_shop_regex%/.*", role: PUBLIC_ACCESS } diff --git a/tests/Application/config/sylius/1.13/packages/test/mailer.yaml b/tests/Application/config/sylius/1.13/packages/test/mailer.yaml new file mode 100644 index 0000000..56cc28f --- /dev/null +++ b/tests/Application/config/sylius/1.13/packages/test/mailer.yaml @@ -0,0 +1,7 @@ +framework: + mailer: + dsn: 'null://null' + cache: + pools: + test.mailer_pool: + adapter: cache.adapter.filesystem diff --git a/tests/Application/config/sylius/1.13/packages/test/security.yaml b/tests/Application/config/sylius/1.13/packages/test/security.yaml new file mode 100644 index 0000000..a6f2ff7 --- /dev/null +++ b/tests/Application/config/sylius/1.13/packages/test/security.yaml @@ -0,0 +1,3 @@ +security: + password_hashers: + sha512: sha512 diff --git a/tests/Application/public/index.php b/tests/Application/public/index.php index 14af8ba..71e7fa1 100644 --- a/tests/Application/public/index.php +++ b/tests/Application/public/index.php @@ -1,10 +1,17 @@ defaultVariantResolver = $productVariantResolver; $this->shipmentRepository = $shipmentRepository; diff --git a/tests/Behat/Context/Ui/Admin/ShippingExportContext.php b/tests/Behat/Context/Ui/Admin/ShippingExportContext.php index 00d2557..0b0e852 100644 --- a/tests/Behat/Context/Ui/Admin/ShippingExportContext.php +++ b/tests/Behat/Context/Ui/Admin/ShippingExportContext.php @@ -1,10 +1,11 @@ inPostApiMocker = $inPostApiMocker; $this->indexPage = $indexPage; diff --git a/tests/Behat/Context/Ui/Admin/ShippingGatewayContext.php b/tests/Behat/Context/Ui/Admin/ShippingGatewayContext.php index b5f73ec..1950a74 100644 --- a/tests/Behat/Context/Ui/Admin/ShippingGatewayContext.php +++ b/tests/Behat/Context/Ui/Admin/ShippingGatewayContext.php @@ -1,10 +1,11 @@ createPage = $createPage; $this->currentPageResolver = $currentPageResolver; @@ -94,7 +95,7 @@ public function iShouldBeNotifiedThatTheShippingGatewayWasCreated(): void { $this->notificationChecker->checkNotification( 'Shipping gateway has been successfully', - NotificationType::success() + NotificationType::success(), ); } diff --git a/tests/Behat/Context/Ui/Admin/ShippingMethodContext.php b/tests/Behat/Context/Ui/Admin/ShippingMethodContext.php index 4b73514..83ad0fa 100644 --- a/tests/Behat/Context/Ui/Admin/ShippingMethodContext.php +++ b/tests/Behat/Context/Ui/Admin/ShippingMethodContext.php @@ -1,9 +1,10 @@ updatePage = $updatePage; } diff --git a/tests/Behat/Mocker/InPostApiMocker.php b/tests/Behat/Mocker/InPostApiMocker.php index 2f664c6..e011fba 100644 --- a/tests/Behat/Mocker/InPostApiMocker.php +++ b/tests/Behat/Mocker/InPostApiMocker.php @@ -1,10 +1,11 @@ mocker ->mockService( 'bitbag.sylius_inpost_plugin.api.web_client', - WebClientInterface::class + WebClientInterface::class, ) ->shouldReceive('createShipment') ->andReturn($createShipmentResult) diff --git a/tests/Behat/Page/Admin/ShippingGateway/CreatePage.php b/tests/Behat/Page/Admin/ShippingGateway/CreatePage.php index fcfaf78..2c49add 100644 --- a/tests/Behat/Page/Admin/ShippingGateway/CreatePage.php +++ b/tests/Behat/Page/Admin/ShippingGateway/CreatePage.php @@ -1,10 +1,11 @@ getDocument()->attachFileToField( 'sylius_shipping_method_image_file', - $filesPath . $path + $filesPath . $path, ); } } diff --git a/tests/Behat/Page/Admin/ShippingMethod/UpdatePageInterface.php b/tests/Behat/Page/Admin/ShippingMethod/UpdatePageInterface.php index 3fb9b00..53dc1fd 100644 --- a/tests/Behat/Page/Admin/ShippingMethod/UpdatePageInterface.php +++ b/tests/Behat/Page/Admin/ShippingMethod/UpdatePageInterface.php @@ -1,10 +1,11 @@ address = new Address(); } - public function withPhoneNumber(string $phoneNumber): AddressBuilder + public function withPhoneNumber(string $phoneNumber): self { $this->address->setPhoneNumber($phoneNumber); return $this; } - public function build():AddressInterface + public function build(): AddressInterface { return $this->address; } diff --git a/tests/Spec/Builder/OrderBuilder.php b/tests/Spec/Builder/OrderBuilder.php index fa52ab5..78836a7 100644 --- a/tests/Spec/Builder/OrderBuilder.php +++ b/tests/Spec/Builder/OrderBuilder.php @@ -1,9 +1,10 @@ order = new Order(); } - public function withShipment(ShipmentInterface $shipment):OrderBuilder + public function withShipment(ShipmentInterface $shipment): self { $this->order->addShipment($shipment); return $this; } - public function withNumber(string $number): OrderBuilder + public function withNumber(string $number): self { $this->order->setNumber($number); diff --git a/tests/Spec/Builder/PaymentBuilder.php b/tests/Spec/Builder/PaymentBuilder.php index eea6ac8..9e5a99a 100644 --- a/tests/Spec/Builder/PaymentBuilder.php +++ b/tests/Spec/Builder/PaymentBuilder.php @@ -1,28 +1,25 @@ payment = new Payment(); } - public function withPaymentMethod(PaymentMethodInterface $paymentMethod): PaymentBuilder + public function withPaymentMethod(PaymentMethodInterface $paymentMethod): self { $this->payment->setMethod($paymentMethod); diff --git a/tests/Spec/Builder/PaymentMethodBuilder.php b/tests/Spec/Builder/PaymentMethodBuilder.php index 5c4e0fd..59d7cbc 100644 --- a/tests/Spec/Builder/PaymentMethodBuilder.php +++ b/tests/Spec/Builder/PaymentMethodBuilder.php @@ -1,26 +1,24 @@ paymentMethod = new PaymentMethod(); } - public function withCode(string $code): PaymentMethodBuilder + public function withCode(string $code): self { $this->paymentMethod->setCode($code); diff --git a/tests/Spec/Builder/ShipmentBuilder.php b/tests/Spec/Builder/ShipmentBuilder.php index 6bded39..3efbb6d 100644 --- a/tests/Spec/Builder/ShipmentBuilder.php +++ b/tests/Spec/Builder/ShipmentBuilder.php @@ -1,9 +1,10 @@ shipment = new Shipment(); } - public function withShippingMethod(ShippingMethodInterface $shippingMethod): ShipmentBuilder + public function withShippingMethod(ShippingMethodInterface $shippingMethod): self { $this->shipment->setMethod($shippingMethod); return $this; } - public function withOrder(OrderInterface $order): ShipmentBuilder + public function withOrder(OrderInterface $order): self { $this->shipment->setOrder($order); diff --git a/tests/Spec/Builder/ShippingExportBuilder.php b/tests/Spec/Builder/ShippingExportBuilder.php index cad72cd..cf88bd8 100644 --- a/tests/Spec/Builder/ShippingExportBuilder.php +++ b/tests/Spec/Builder/ShippingExportBuilder.php @@ -1,9 +1,10 @@ shippingExport = new ShippingExport(); } - public function withShipment(ShipmentInterface $shipment): ShippingExportBuilder + public function withShipment(ShipmentInterface $shipment): self { $this->shippingExport->setShipment($shipment); return $this; } - public function withExternalId(string $id): ShippingExportBuilder + public function withExternalId(string $id): self { $this->shippingExport->setExternalId($id); return $this; } - public function withShippingGateway(ShippingGatewayInterface $shippingGateway): ShippingExportBuilder + public function withShippingGateway(ShippingGatewayInterface $shippingGateway): self { $this->shippingExport->setShippingGateway($shippingGateway); diff --git a/tests/Spec/Builder/ShippingGatewayBuilder.php b/tests/Spec/Builder/ShippingGatewayBuilder.php index bba228e..0ed422c 100644 --- a/tests/Spec/Builder/ShippingGatewayBuilder.php +++ b/tests/Spec/Builder/ShippingGatewayBuilder.php @@ -1,9 +1,10 @@ shippingGateway = new ShippingGateway(); } - public function withCode(string $code): ShippingGatewayBuilder + public function withCode(string $code): self { $this->shippingGateway->setCode($code); return $this; } - public function build():ShippingGatewayInterface + public function build(): ShippingGatewayInterface { return $this->shippingGateway; } diff --git a/tests/Spec/Builder/ShippingMethodBuilder.php b/tests/Spec/Builder/ShippingMethodBuilder.php index b72f57e..860027d 100644 --- a/tests/Spec/Builder/ShippingMethodBuilder.php +++ b/tests/Spec/Builder/ShippingMethodBuilder.php @@ -1,17 +1,16 @@ shippingMethod = new ShippingMethod(); } - public function withCode(string $code): ShippingMethodBuilder + public function withCode(string $code): self { $this->shippingMethod->setCode($code);