Skip to content

Commit

Permalink
Merge pull request #256 from payplug/qa
Browse files Browse the repository at this point in the history
Release 1.9.3
  • Loading branch information
dmurillo-payplug authored Aug 20, 2024
2 parents 695c5b3 + 4d0e75a commit 7409ca2
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 80 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -90,4 +88,4 @@ jobs:
-Dsonar.sources=src/
-Dsonar.test.exclusions=tests/**
-Dsonar.tests=tests/
-Dsonar.verbose=true
-Dsonar.verbose=true
41 changes: 8 additions & 33 deletions .github/workflows/sylius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}'
Expand All @@ -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'
Expand All @@ -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'
Expand Down
39 changes: 18 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
14 changes: 9 additions & 5 deletions rulesets/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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]+::\$#'
Expand Down
28 changes: 18 additions & 10 deletions src/Creator/PayPlugPaymentDataCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DateInterval;
use DateTime;
use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumberFormat as PhoneNumberFormat;
use libphonenumber\PhoneNumberType;
use libphonenumber\PhoneNumberUtil as PhoneNumberUtil;
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/Creator/RefundUnitsCommandCreatorDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Gateway/Form/Type/AbstractGatewayConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' => [
Expand Down
2 changes: 1 addition & 1 deletion src/PayPlugSyliusPayPlugPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final class PayPlugSyliusPayPlugPlugin extends Bundle
{
public const VERSION = '1.9.2';
public const VERSION = '1.9.3';

use SyliusPluginTrait;
}
2 changes: 1 addition & 1 deletion src/Resources/dev/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
5 changes: 5 additions & 0 deletions src/Twig/OneyRulesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
6 changes: 5 additions & 1 deletion src/Twig/OneySimulationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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.');
Expand Down

0 comments on commit 7409ca2

Please sign in to comment.