Skip to content

Commit

Permalink
refactor #263 [Maintenance] Add support for Symfony 6 (NoResponseMate)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.5-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | master
| Bug fix?        | no
| New feature?    | no
| Related tickets | -


Commits
-------

e5559ce [Maintenance] Remove sylius 1.10 leftovers
3095304 [Maintenance] Fix incorrect spec location
dfbf928 [Maintenance] Conditional Swiftmailer/Symfony Mailer config
902015f [Maintenance] Use request stack for flash setting
32ef0ab [Maintenance] Allow usage with sylius 1.12 and symfony 6
d045553 [Maintenance] Use only the new security config file
e287815 [Maintenance] Add deprecation notices for flash bags
  • Loading branch information
GSadee authored Oct 21, 2022
2 parents bc89d7b + e287815 commit 0695c70
Show file tree
Hide file tree
Showing 38 changed files with 230 additions and 325 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:
php: ["8.0", "8.1"]
node: ["16.x"]
mysql: ["5.7", "8.0"]
symfony: ["^4.4", "^5.4"]
sylius: ["1.11.*", "~1.12.x-dev"]
symfony: ["^5.4", "^6.0"]
sylius: ["~1.11.0", "~1.12.x-dev"]
exclude:
-
symfony: "^4.4"
sylius: "~1.12.x-dev"
symfony: "^6.0"
sylius: "~1.11.0"
env:
APP_ENV: test
DATABASE_URL: "mysql://root:[email protected]/sylius?serverVersion=${{ matrix.mysql }}"
Expand Down Expand Up @@ -120,12 +120,6 @@ jobs:
name: Install JS dependencies
run: (cd tests/Application && yarn install)

-
name: Prepare configuration for Sylius 1.10
if: matrix.sylius == '1.10.*'
run: |
rm tests/Behat/Resources/suites.yml
cp tests/Behat/Resources/sylius-1.10/suites.yml tests/Behat/Resources
-
name: Prepare test application database
run: |
Expand Down
31 changes: 16 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"license": "MIT",
"require": {
"php": "^8.0",
"doctrine/doctrine-migrations-bundle": "^3.0",
"phpseclib/phpseclib": "^2.0",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"sylius-labs/doctrine-migrations-extra-bundle": "^0.1.4 || ^0.2",
"sylius/sylius": "~1.11.0 || 1.12.x-dev",
"phpseclib/phpseclib": "^2.0",
"sylius-labs/doctrine-migrations-extra-bundle": "^0.1.3",
"doctrine/doctrine-migrations-bundle": "^3.0"
"symfony/mailer": "^5.4 || ^6.0"
},
"require-dev": {
"behat/behat": "^3.6.1",
Expand All @@ -25,27 +26,23 @@
"friends-of-behat/suite-settings-extension": "^1.0",
"friends-of-behat/symfony-extension": "^2.1",
"friends-of-behat/variadic-extension": "^1.3",
"friendsofsymfony/oauth-server-bundle": ">2.0.0-alpha.0 ^2.0@dev",
"phpspec/phpspec": "^7.0",
"phpstan/phpstan": "0.12.98",
"phpstan/phpstan-doctrine": "0.12.33",
"phpstan/phpstan-webmozart-assert": "0.12.12",
"phpunit/phpunit": "^8.5",
"sensiolabs/security-checker": "^6.0",
"sylius-labs/coding-standard": "^4.0",
"symfony/browser-kit": "^4.4 || ^5.2",
"symfony/debug-bundle": "^4.4 || ^5.2",
"symfony/dotenv": "^4.4 || ^5.2",
"symfony/intl": "^4.4 || ^5.2",
"symfony/web-profiler-bundle": "^4.4 || ^5.2",
"symfony/web-server-bundle": "^4.4|^5.0",
"symfony/browser-kit": "^5.4 || ^6.0",
"symfony/debug-bundle": "^5.4 || ^6.0",
"symfony/dotenv": "^5.4 || ^6.0",
"symfony/intl": "^5.4 || ^6.0",
"symfony/web-profiler-bundle": "^5.4 || ^6.0",
"vimeo/psalm": "4.27.0",
"rector/rector": "^0.11.53",
"lchrusciel/api-test-case": "^5.1",
"symfony/webpack-encore-bundle": "^1.15"
},
"conflict": {
"symfony/doctrine-bridge": "4.4.16",
"doctrine/doctrine-bundle": "2.3.0",
"doctrine/dbal": "^3.0.0",
"sylius/invoicing-plugin": "<0.16.0"
Expand All @@ -60,10 +57,12 @@
"classmap": ["tests/Application/Kernel.php"]
},
"config": {
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false,
"ocramius/package-versions": false,
"symfony/flex": true
"ocramius/package-versions": false,
"symfony/flex": true,
"symfony/thanks": false
}
},
"extra": {
Expand All @@ -80,5 +79,7 @@
"fix": [
"vendor/bin/ecs check src/ spec/ --fix"
]
}
},
"prefer-stable": true,
"minimum-stability": "dev"
}
7 changes: 6 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ parameters:
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false

excludes_analyse:
paths:
- 'src/'

excludePaths:
# Makes PHPStan crash
- 'src/DependencyInjection/Configuration.php'
- 'src/DependencyInjection/SyliusPayPalExtension.php'
- 'src/Command/CompletePaidPaymentsCommand.php'

# Test dependencies
- 'tests/Application/app/**.php'
Expand Down
13 changes: 8 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.5/phpunit.xsd"
colors="true"
bootstrap="tests/Application/config/bootstrap.php">
bootstrap="tests/Application/config/bootstrap.php"
>
<testsuites>
<testsuite name="SyliusPayPalPlugin Test Suite">
<directory>tests</directory>
Expand All @@ -13,10 +14,12 @@
<php>
<ini name="error_reporting" value="-1" />

<server name="KERNEL_CLASS_PATH" value="/tests/Application/AppKernel.php" />
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />

<env name="APP_ENV" value="test"/>
<!-- ###+ symfony/framework-bundle ### -->
<env name="APP_ENV" value="test" />
<env name="SHELL_VERBOSITY" value="-1" />
<!-- ###- symfony/framework-bundle ### -->

<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />
<server name="ESCAPE_JSON" value="true" />
</php>
</phpunit>
10 changes: 3 additions & 7 deletions spec/Factory/PayPalPaymentMethodNewResourceFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\PayPalPlugin\Onboarding\Processor\OnboardingProcessorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\HttpClient\HttpClientInterface;

final class PayPalPaymentMethodNewResourceFactorySpec extends ObjectBehavior
{
function let(
NewResourceFactoryInterface $newResourceFactory,
OnboardingProcessorInterface $onboardingProcessor,
HttpClientInterface $httpClient
): void {
$this->beConstructedWith($newResourceFactory, $onboardingProcessor, $httpClient, 'test-url');
$this->beConstructedWith($newResourceFactory, $onboardingProcessor);
}

function it_is_a_new_resource_factory(): void
Expand All @@ -37,7 +35,6 @@ function it_processes_onboarding_if_payment_method_and_request_are_supported(
FactoryInterface $factory,
PaymentMethodInterface $paymentMethod,
PaymentMethodInterface $processedPaymentMethod,
HttpClientInterface $httpClient
): void {
$newResourceFactory->create($requestConfiguration, $factory)->willReturn($paymentMethod);

Expand All @@ -56,7 +53,6 @@ function it_does_nothing_if_payment_method_and_request_are_unsupported(
Request $request,
FactoryInterface $factory,
PaymentMethodInterface $paymentMethod,
HttpClientInterface $httpClient
): void {
$newResourceFactory->create($requestConfiguration, $factory)->willReturn($paymentMethod);

Expand All @@ -66,14 +62,14 @@ function it_does_nothing_if_payment_method_and_request_are_unsupported(

$this->create($requestConfiguration, $factory)->shouldReturn($paymentMethod);

$onboardingProcessor->process($paymentMethod, $request, $httpClient, 'test-url')->shouldNotHaveBeenCalled();
$onboardingProcessor->process($paymentMethod, $request)->shouldNotHaveBeenCalled();
}

function it_does_nothing_if_created_resource_is_not_a_payment_method(
NewResourceFactoryInterface $newResourceFactory,
RequestConfiguration $requestConfiguration,
FactoryInterface $factory,
ResourceInterface $resource
ResourceInterface $resource,
): void {
$newResourceFactory->create($requestConfiguration, $factory)->willReturn($resource);

Expand Down
File renamed without changes.
14 changes: 10 additions & 4 deletions src/Controller/CancelPayPalOrderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\PayPalPlugin\Provider\FlashBagProvider;
use Sylius\PayPalPlugin\Provider\PaymentProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;

Expand All @@ -17,16 +19,20 @@ final class CancelPayPalOrderAction

private OrderRepositoryInterface $orderRepository;

private FlashBag $flashBag;
private FlashBag|RequestStack $flashBagOrRequestStack;

public function __construct(
PaymentProviderInterface $paymentProvider,
OrderRepositoryInterface $orderRepository,
FlashBag $flashBag
FlashBag|RequestStack $flashBagOrRequestStack
) {
if ($flashBagOrRequestStack instanceof FlashBag) {
trigger_deprecation('sylius/paypal-plugin', '1.5', sprintf('Passing an instance of %s as constructor argument for %s is deprecated as of PayPalPlugin 1.5 and will be removed in 2.0. Pass an instance of %s instead.', FlashBag::class, self::class, RequestStack::class));
}

$this->paymentProvider = $paymentProvider;
$this->orderRepository = $orderRepository;
$this->flashBag = $flashBag;
$this->flashBagOrRequestStack = $flashBagOrRequestStack;
}

public function __invoke(Request $request): Response
Expand All @@ -39,7 +45,7 @@ public function __invoke(Request $request): Response
$order = $payment->getOrder();
$this->orderRepository->remove($order);

$this->flashBag->add('success', 'sylius.pay_pal.order_cancelled');
FlashBagProvider::getFlashBag($this->flashBagOrRequestStack)->add('success', 'sylius.pay_pal.order_cancelled');

return new Response('', Response::HTTP_NO_CONTENT);
}
Expand Down
16 changes: 12 additions & 4 deletions src/Controller/CancelPayPalPaymentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Order\Processor\OrderProcessorInterface;
use Sylius\Component\Payment\PaymentTransitions;
use Sylius\PayPalPlugin\Provider\FlashBagProvider;
use Sylius\PayPalPlugin\Provider\PaymentProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;

Expand All @@ -20,7 +22,7 @@ final class CancelPayPalPaymentAction

private ObjectManager $objectManager;

private FlashBag $flashBag;
private FlashBag|RequestStack $flashBagOrRequestStack;

private FactoryInterface $stateMachineFactory;

Expand All @@ -29,13 +31,17 @@ final class CancelPayPalPaymentAction
public function __construct(
PaymentProviderInterface $paymentProvider,
ObjectManager $objectManager,
FlashBag $flashBag,
FlashBag|RequestStack $flashBagOrRequestStack,
FactoryInterface $stateMachineFactory,
OrderProcessorInterface $orderPaymentProcessor
) {
if ($flashBagOrRequestStack instanceof FlashBag) {
trigger_deprecation('sylius/paypal-plugin', '1.5', sprintf('Passing an instance of %s as constructor argument for %s is deprecated as of PayPalPlugin 1.5 and will be removed in 2.0. Pass an instance of %s instead.', FlashBag::class, self::class, RequestStack::class));
}

$this->paymentProvider = $paymentProvider;
$this->objectManager = $objectManager;
$this->flashBag = $flashBag;
$this->flashBagOrRequestStack = $flashBagOrRequestStack;
$this->stateMachineFactory = $stateMachineFactory;
$this->orderPaymentProcessor = $orderPaymentProcessor;
}
Expand All @@ -55,7 +61,9 @@ public function __invoke(Request $request): Response
$this->orderPaymentProcessor->process($order);
$this->objectManager->flush();

$this->flashBag->add('success', 'sylius.pay_pal.payment_cancelled');
FlashBagProvider::getFlashBag($this->flashBagOrRequestStack)
->add('success', 'sylius.pay_pal.payment_cancelled')
;

return new Response('', Response::HTTP_NO_CONTENT);
}
Expand Down
16 changes: 12 additions & 4 deletions src/Controller/PayPalPaymentOnErrorAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,34 @@
namespace Sylius\PayPalPlugin\Controller;

use Psr\Log\LoggerInterface;
use Sylius\PayPalPlugin\Provider\FlashBagProvider;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;

final class PayPalPaymentOnErrorAction
{
private FlashBagInterface $flashBag;
private FlashBagInterface|RequestStack $flashBagOrRequestStack;

private LoggerInterface $logger;

public function __construct(FlashBagInterface $flashBag, LoggerInterface $logger)
public function __construct(FlashBagInterface|RequestStack $flashBagOrRequestStack, LoggerInterface $logger)
{
$this->flashBag = $flashBag;
if ($flashBagOrRequestStack instanceof FlashBagInterface) {
trigger_deprecation('sylius/paypal-plugin', '1.5', sprintf('Passing an instance of %s as constructor argument for %s is deprecated as of PayPalPlugin 1.5 and will be removed in 2.0. Pass an instance of %s instead.', FlashBagInterface::class, self::class, RequestStack::class));
}

$this->flashBagOrRequestStack = $flashBagOrRequestStack;
$this->logger = $logger;
}

public function __invoke(Request $request): Response
{
$this->logger->error((string) $request->getContent());
$this->flashBag->add('error', 'sylius.pay_pal.something_went_wrong');
FlashBagProvider::getFlashBag($this->flashBagOrRequestStack)
->add('error', 'sylius.pay_pal.something_went_wrong')
;

return new Response();
}
Expand Down
16 changes: 12 additions & 4 deletions src/Listener/PayPalPaymentMethodListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\PayPalPlugin\Exception\PayPalPaymentMethodNotFoundException;
use Sylius\PayPalPlugin\Onboarding\Initiator\OnboardingInitiatorInterface;
use Sylius\PayPalPlugin\Provider\FlashBagProvider;
use Sylius\PayPalPlugin\Provider\PayPalPaymentMethodProviderInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Webmozart\Assert\Assert;
Expand All @@ -21,19 +23,23 @@ final class PayPalPaymentMethodListener

private UrlGeneratorInterface $urlGenerator;

private FlashBagInterface $flashBag;
private FlashBagInterface|RequestStack $flashBagOrRequestStack;

private PayPalPaymentMethodProviderInterface $payPalPaymentMethodProvider;

public function __construct(
OnboardingInitiatorInterface $onboardingInitiator,
UrlGeneratorInterface $urlGenerator,
FlashBagInterface $flashBag,
FlashBagInterface|RequestStack $flashBagOrRequestStack,
PayPalPaymentMethodProviderInterface $payPalPaymentMethodProvider
) {
if ($flashBagOrRequestStack instanceof FlashBagInterface) {
trigger_deprecation('sylius/paypal-plugin', '1.5', sprintf('Passing an instance of %s as constructor argument for %s is deprecated as of PayPalPlugin 1.5 and will be removed in 2.0. Pass an instance of %s instead.', FlashBagInterface::class, self::class, RequestStack::class));
}

$this->onboardingInitiator = $onboardingInitiator;
$this->urlGenerator = $urlGenerator;
$this->flashBag = $flashBag;
$this->flashBagOrRequestStack = $flashBagOrRequestStack;
$this->payPalPaymentMethodProvider = $payPalPaymentMethodProvider;
}

Expand All @@ -49,7 +55,9 @@ public function initializeCreate(ResourceControllerEvent $event): void
}

if ($this->isTherePayPalPaymentMethod()) {
$this->flashBag->add('error', 'sylius.pay_pal.more_than_one_seller_not_allowed');
FlashBagProvider::getFlashBag($this->flashBagOrRequestStack)
->add('error', 'sylius.pay_pal.more_than_one_seller_not_allowed')
;

$event->setResponse(new RedirectResponse($this->urlGenerator->generate('sylius_admin_payment_method_index')));

Expand Down
Loading

0 comments on commit 0695c70

Please sign in to comment.