From d0eb5bf99188ecb876b9af33ab87760573bf2828 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Tue, 13 Dec 2022 13:25:32 +0100 Subject: [PATCH] Fix request stack during tests --- .../config/sylius/1.12/services_test.yaml | 7 +++ .../src/Action/GetHttpRequestAction.php | 47 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/Application/config/sylius/1.12/services_test.yaml create mode 100644 tests/Application/src/Action/GetHttpRequestAction.php diff --git a/tests/Application/config/sylius/1.12/services_test.yaml b/tests/Application/config/sylius/1.12/services_test.yaml new file mode 100644 index 0000000..8d086f8 --- /dev/null +++ b/tests/Application/config/sylius/1.12/services_test.yaml @@ -0,0 +1,7 @@ +services: + + Tests\FluxSE\SyliusPayumMoneticoPlugin\App\Action\GetHttpRequestAction: + decorates: payum.action.get_http_request + arguments: + $decoratedGetHttpRequestAction: '@Tests\FluxSE\SyliusPayumMoneticoPlugin\App\Action\GetHttpRequestAction.inner' + $httpRequestStack: '@request_stack' diff --git a/tests/Application/src/Action/GetHttpRequestAction.php b/tests/Application/src/Action/GetHttpRequestAction.php new file mode 100644 index 0000000..9fddc8a --- /dev/null +++ b/tests/Application/src/Action/GetHttpRequestAction.php @@ -0,0 +1,47 @@ +decoratedGetHttpRequestAction = $decoratedGetHttpRequestAction; + $this->httpRequestStack = $httpRequestStack; + } + + public function execute($request): void + { + RequestNotSupportedException::assertSupports($this, $request); + + if ($this->httpRequestStack->getCurrentRequest() !== $this->httpRequestStack->getMainRequest()) + { + $this->decoratedGetHttpRequestAction->setHttpRequest($this->httpRequestStack->getCurrentRequest()); + } + $this->decoratedGetHttpRequestAction->execute($request); + } + + public function supports($request): bool + { + return $this->decoratedGetHttpRequestAction->supports($request); + } +}