From 3025c7a27f07d8f6d7a5388841fb5b49516f6379 Mon Sep 17 00:00:00 2001 From: Nicolas MELONI Date: Thu, 20 Jun 2024 10:40:03 +0200 Subject: [PATCH 1/4] Fix CI --- .github/workflows/analysis.yaml | 8 ++-- .github/workflows/sylius.yaml | 41 ++++--------------- Makefile | 39 ++++++++---------- rulesets/phpstan.neon | 14 ++++--- .../RefundUnitsCommandCreatorDecorator.php | 5 ++- src/Twig/OneyRulesExtension.php | 5 +++ src/Twig/OneySimulationExtension.php | 6 ++- 7 files changed, 52 insertions(+), 66 deletions(-) diff --git a/.github/workflows/analysis.yaml b/.github/workflows/analysis.yaml index dba79f5a..a27d6a91 100644 --- a/.github/workflows/analysis.yaml +++ b/.github/workflows/analysis.yaml @@ -17,11 +17,9 @@ jobs: strategy: matrix: php: - - 8.0 - - 8.1 + - 8.2 symfony: - - '5.4.*' - - '6.1.*' + - '6.2.*' env: APP_ENV: test steps: @@ -90,4 +88,4 @@ jobs: -Dsonar.sources=src/ -Dsonar.test.exclusions=tests/** -Dsonar.tests=tests/ - -Dsonar.verbose=true \ No newline at end of file + -Dsonar.verbose=true diff --git a/.github/workflows/sylius.yaml b/.github/workflows/sylius.yaml index ec633e4a..4aa0da6d 100644 --- a/.github/workflows/sylius.yaml +++ b/.github/workflows/sylius.yaml @@ -18,35 +18,13 @@ jobs: fail-fast: false matrix: php: - - 8.0 - - 8.1 + - 8.2 sylius: - - 1.11.0 - 1.12.0 symfony: - - 5.4 - - 6.1 + - 6.2 node: - 14.x - exclude: - - - sylius: 1.11.0 - symfony: 6.1 - - - php: '8.0' - symfony: 6.1 - - - sylius: 1.9.0 - symfony: 6.1 - - - sylius: 1.10.0 - symfony: 6.1 - - - sylius: 1.11.0 - symfony: 6.1 - - - php: '8.0' - symfony: 6.1 env: APP_ENV: test package-name: payplug/sylius-payplug-plugin @@ -62,21 +40,21 @@ jobs: coverage: none - name: 'Setup Node' - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: '${{ matrix.node }}' - name: 'Wkhtmltopdf - Install' run: "sudo apt-get update\nsudo apt-get install xvfb libfontconfig wkhtmltopdf\nprintf '#!/bin/bash\\nxvfb-run -a --server-args=\"-screen 0, 1024x768x24\" /usr/bin/wkhtmltopdf -q $*' | sudo tee /usr/bin/wkhtmltopdf.sh\nsudo chmod a+x /usr/bin/wkhtmltopdf.sh\nsudo ln -s /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf\n" - - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: 'Composer - Get Cache Directory' id: composer-cache - run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"' + run: 'echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT' - name: 'Composer - Set cache' - uses: actions/cache@v2 + uses: actions/cache@v3 id: cache-composer with: path: '${{ steps.composer-cache.outputs.dir }}' @@ -92,18 +70,16 @@ jobs: - name: 'Yarn - Get cache directory' id: yarn-cache - run: 'echo "::set-output name=dir::$(yarn cache dir)"' + run: 'echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT' - name: 'Yarn - Set Cache' - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: '${{ steps.yarn-cache.outputs.dir }}' key: 'node-${{ matrix.node }}-yarn-${{ hashFiles(''**/package.json **/yarn.lock'') }}' restore-keys: "node-${{ matrix.node }}-yarn-\n" - name: 'Install Sylius-Standard and Plugin' - env: - SYMFONY_REQUIRE: '${{ matrix.symfony }}.*' run: 'make install -e SYLIUS_VERSION=${{ matrix.sylius }} SYMFONY_VERSION=${{ matrix.symfony }} PHP_VERSION=${{ matrix.php }}' - name: 'Output PHP version for Symfony CLI' @@ -126,7 +102,6 @@ jobs: name: 'Doctrine Schema Validate - Run' working-directory: ./tests/Application run: 'php bin/console doctrine:schema:validate --skip-sync' - if: 'always() && steps.end-of-setup-sylius.outcome == ''success''' - name: 'Run PHPUnit' run: 'make phpunit' diff --git a/Makefile b/Makefile index ff24247d..cc5d2e48 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,15 @@ .DEFAULT_GOAL := help SHELL=/bin/bash COMPOSER_ROOT=composer -PLUGIN_NAME=payplug/sylius-payplug-plugin -SYLIUS_VERSION=1.12.0 -SYMFONY_VERSION=6.1 -PHP_VERSION=8.1 TEST_DIRECTORY=tests/Application -YARN=cd tests/Application && yarn CONSOLE=cd tests/Application && php bin/console -e test COMPOSER=cd tests/Application && composer +YARN=cd tests/Application && yarn + +SYLIUS_VERSION=1.12.0 +SYMFONY_VERSION=6.1 +PHP_VERSION=8.1 +PLUGIN_NAME=payplug/sylius-payplug-plugin ### ### DEVELOPMENT @@ -18,6 +19,9 @@ install: sylius ## Install Plugin on Sylius [SYLIUS_VERSION=1.12.0] [SYMFONY_VER .PHONY: install reset: ## Remove dependencies +ifneq ("$(wildcard tests/Application/bin/console)","") + ${CONSOLE} doctrine:database:drop --force --if-exists || true +endif rm -rf tests/Application .PHONY: reset @@ -28,35 +32,28 @@ phpunit: phpunit-configure phpunit-run ## Run PHPUnit ### OTHER ### ¯¯¯¯¯¯ -sylius: sylius-standard update-dependencies install-plugin install-sylius +sylius: sylius-standard install-plugin install-sylius .PHONY: sylius sylius-standard: +ifeq ($(shell [[ $(SYLIUS_VERSION) == *dev ]] && echo true ),true) + ${COMPOSER_ROOT} create-project sylius/sylius-standard:${SYLIUS_VERSION} ${TEST_DIRECTORY} --no-install --no-scripts +else ${COMPOSER_ROOT} create-project sylius/sylius-standard ${TEST_DIRECTORY} "~${SYLIUS_VERSION}" --no-install --no-scripts +endif ${COMPOSER} config allow-plugins true +ifeq ($(shell [[ $(SYLIUS_VERSION) == *dev ]] && echo true ),true) + ${COMPOSER} require sylius/sylius:"${SYLIUS_VERSION}" +else ${COMPOSER} require sylius/sylius:"~${SYLIUS_VERSION}" - -update-dependencies: - ${COMPOSER} config extra.symfony.require "~${SYMFONY_VERSION}" - ${COMPOSER} require --dev donatj/mock-webserver:^2.1 --no-scripts --no-update -# FIX since https://github.com/Sylius/Sylius/pull/13215 is not merged - ${COMPOSER} require doctrine/dbal:"^2.6" doctrine/orm:"^2.9" --no-scripts --no-update -ifeq ($(shell [[ $(SYMFONY_VERSION) == 4.4 && $(PHP_VERSION) == 7.4 ]] && echo true ),true) - ${COMPOSER} require sylius/admin-api-bundle:1.10 --no-scripts --no-update -endif -ifeq ($(SYLIUS_VERSION), 1.8.0) - ${COMPOSER} update --no-progress --no-scripts --prefer-dist -n endif - ${COMPOSER} require symfony/asset:^${SYMFONY_VERSION} --no-scripts --no-update - ${COMPOSER} update --no-progress -n install-plugin: ${COMPOSER} config repositories.plugin '{"type": "path", "url": "../../"}' ${COMPOSER} config extra.symfony.allow-contrib true ${COMPOSER} config minimum-stability "dev" ${COMPOSER} config prefer-stable true - ${COMPOSER} req ${PLUGIN_NAME}:* --prefer-source --no-scripts - ${COMPOSER} symfony:recipes:install "${PLUGIN_NAME}" --force + ${COMPOSER} require "${PLUGIN_NAME}:*" --prefer-source --no-scripts cp -r install/Application tests sed -i "4a \ \ \ \ form_themes: ['form/form_gateway_config_row.html.twig']" ${TEST_DIRECTORY}/config/packages/twig.yaml diff --git a/rulesets/phpstan.neon b/rulesets/phpstan.neon index b65d3ebd..c7466a84 100644 --- a/rulesets/phpstan.neon +++ b/rulesets/phpstan.neon @@ -6,18 +6,22 @@ parameters: reportUnmatchedIgnoredErrors: false checkMissingIterableValueType: false checkGenericClassInNonGenericObjectType: false + bootstrapFiles: + - ../vendor/autoload.php excludePaths: # Makes PHPStan crash - ../src/DependencyInjection/Configuration.php - ../src/Repository/PaymentMethodRepository.php - ../src/Migrations/ + - ../src/Entity/ + - ../tests/PHPUnit + - ../src/Manager/SettingsManager.php + - ../src/Form/Type/SettingsType.php # Test dependencies - - ../tests - - # PHPSpec - - ../spec - + - ../tests/Application + - ../tests/PHPUnit + - ../install ignoreErrors: # ignore false positive - '#Access to an undefined property Payplug\\Resource\\[a-zA-Z0-9]+::\$#' diff --git a/src/Creator/RefundUnitsCommandCreatorDecorator.php b/src/Creator/RefundUnitsCommandCreatorDecorator.php index 8e5f0cc9..b2313b82 100644 --- a/src/Creator/RefundUnitsCommandCreatorDecorator.php +++ b/src/Creator/RefundUnitsCommandCreatorDecorator.php @@ -105,8 +105,11 @@ public function fromRequest(Request $request): RefundUnits } if (OneyGatewayFactory::FACTORY_NAME === $gateway->getFactoryName()) { + $orderNumber = $request->get('orderNumber'); + Assert::string($orderNumber); + /** @var OrderInterface|null $order */ - $order = $this->orderRepository->findOneByNumber($request->get('orderNumber')); + $order = $this->orderRepository->findOneByNumber($orderNumber); Assert::isInstanceOf($order, OrderInterface::class); $this->canOneyRefundBeMade($order); diff --git a/src/Twig/OneyRulesExtension.php b/src/Twig/OneyRulesExtension.php index f90b7cb3..64ff192c 100644 --- a/src/Twig/OneyRulesExtension.php +++ b/src/Twig/OneyRulesExtension.php @@ -189,11 +189,16 @@ public function isProductEligible(): bool } Assert::notNull($currentCart->getLocaleCode()); + Assert::isArray($request->get('_route_params')); + Assert::keyExists($request->get('_route_params'), 'slug'); + Assert::string($request->get('_route_params')['slug']); + $product = $this->productRepository->findOneByChannelAndSlug( $channel, $currentCart->getLocaleCode(), $request->get('_route_params')['slug'] ); + Assert::isInstanceOf($product, ProductInterface::class); /** @var ProductVariantInterface|null $firstVariant */ diff --git a/src/Twig/OneySimulationExtension.php b/src/Twig/OneySimulationExtension.php index 4668771a..63cfe274 100644 --- a/src/Twig/OneySimulationExtension.php +++ b/src/Twig/OneySimulationExtension.php @@ -14,6 +14,7 @@ use Symfony\Component\HttpFoundation\RequestStack; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; +use Webmozart\Assert\Assert; final class OneySimulationExtension extends AbstractExtension { @@ -70,7 +71,10 @@ private function getCartOrOrder(): OrderInterface return $cart; } - $order = $this->orderRepository->findOneByTokenValue($currentRequest->get('tokenValue')); + $tokenValue = $currentRequest->get('tokenValue'); + Assert::string($tokenValue); + + $order = $this->orderRepository->findOneByTokenValue($tokenValue); if (!$order instanceof OrderInterface) { throw new \Exception('No order found.'); From 94f089939a909e47631c28d2b69271c89e45411a Mon Sep 17 00:00:00 2001 From: Nicolas MELONI Date: Tue, 18 Jun 2024 11:43:43 +0200 Subject: [PATCH 2/4] SYL-218 - catch invalid phone number as they are not required --- src/Creator/PayPlugPaymentDataCreator.php | 28 +++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Creator/PayPlugPaymentDataCreator.php b/src/Creator/PayPlugPaymentDataCreator.php index 2973b02b..ae99e267 100644 --- a/src/Creator/PayPlugPaymentDataCreator.php +++ b/src/Creator/PayPlugPaymentDataCreator.php @@ -6,6 +6,7 @@ use DateInterval; use DateTime; +use libphonenumber\NumberParseException; use libphonenumber\PhoneNumberFormat as PhoneNumberFormat; use libphonenumber\PhoneNumberType; use libphonenumber\PhoneNumberUtil as PhoneNumberUtil; @@ -107,22 +108,29 @@ public function create( public function formatNumber(string $phoneNumber, ?string $isoCode): array { - $phoneNumberUtil = PhoneNumberUtil::getInstance(); - $parsed = $phoneNumberUtil->parse($phoneNumber, $isoCode); + try { + $phoneNumberUtil = PhoneNumberUtil::getInstance(); + $parsed = $phoneNumberUtil->parse($phoneNumber, $isoCode); + + if (!$phoneNumberUtil->isValidNumber($parsed)) { + return [ + 'phone' => null, + 'is_mobile' => null, + ]; + } + + $formatted = $phoneNumberUtil->format($parsed, PhoneNumberFormat::E164); - if (!$phoneNumberUtil->isValidNumber($parsed)) { + return [ + 'phone' => $formatted, + 'is_mobile' => PhoneNumberType::MOBILE === $phoneNumberUtil->getNumberType($parsed), + ]; + } catch (NumberParseException) { return [ 'phone' => null, 'is_mobile' => null, ]; } - - $formatted = $phoneNumberUtil->format($parsed, PhoneNumberFormat::E164); - - return [ - 'phone' => $formatted, - 'is_mobile' => PhoneNumberType::MOBILE === $phoneNumberUtil->getNumberType($parsed), - ]; } private function formatTitle(CustomerInterface $customer): ?string From 8f37c51a5526af91ca76bba33dca9d136ea7814f Mon Sep 17 00:00:00 2001 From: Nicolas MELONI Date: Tue, 18 Jun 2024 08:58:46 +0200 Subject: [PATCH 3/4] SYL-220 - set payplug key as password --- src/Gateway/Form/Type/AbstractGatewayConfigurationType.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Gateway/Form/Type/AbstractGatewayConfigurationType.php b/src/Gateway/Form/Type/AbstractGatewayConfigurationType.php index d6de6749..d8871100 100644 --- a/src/Gateway/Form/Type/AbstractGatewayConfigurationType.php +++ b/src/Gateway/Form/Type/AbstractGatewayConfigurationType.php @@ -12,7 +12,7 @@ use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\Extension\Core\Type\TextType; +use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormEvent; @@ -58,7 +58,7 @@ public function __construct( public function buildForm(FormBuilderInterface $builder, array $options): void { $builder - ->add('secretKey', TextType::class, [ + ->add('secretKey', PasswordType::class, [ 'label' => 'payplug_sylius_payplug_plugin.ui.secret_key', 'validation_groups' => self::VALIDATION_GROUPS, 'constraints' => [ From 5e38f09c4f1c0aaff9cc7e93c2ad31887a2827b0 Mon Sep 17 00:00:00 2001 From: Daniel FLOREZ MURILLO Date: Wed, 14 Aug 2024 10:21:53 +0200 Subject: [PATCH 4/4] chore: release 1.9.3 --- src/PayPlugSyliusPayPlugPlugin.php | 2 +- src/Resources/dev/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PayPlugSyliusPayPlugPlugin.php b/src/PayPlugSyliusPayPlugPlugin.php index 81bc5d2f..30cc0813 100644 --- a/src/PayPlugSyliusPayPlugPlugin.php +++ b/src/PayPlugSyliusPayPlugPlugin.php @@ -9,7 +9,7 @@ final class PayPlugSyliusPayPlugPlugin extends Bundle { - public const VERSION = '1.9.2'; + public const VERSION = '1.9.3'; use SyliusPluginTrait; } diff --git a/src/Resources/dev/package.json b/src/Resources/dev/package.json index 5dd606ba..74100cad 100644 --- a/src/Resources/dev/package.json +++ b/src/Resources/dev/package.json @@ -1,6 +1,6 @@ { "name": "sylius-payplug-plugin", - "version": "1.9.2", + "version": "1.9.3", "description": "Sylius Payplug Plugin", "source": "src/index.js", "scripts": {