Skip to content

Commit

Permalink
Fix request stack during tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Dec 13, 2022
1 parent abb3dd6 commit d0eb5bf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/Application/config/sylius/1.12/services_test.yaml
Original file line number Diff line number Diff line change
@@ -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'
47 changes: 47 additions & 0 deletions tests/Application/src/Action/GetHttpRequestAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Tests\FluxSE\SyliusPayumMoneticoPlugin\App\Action;

use Payum\Core\Action\ActionInterface;
use Payum\Core\Bridge\Symfony\Action\GetHttpRequestAction as BaseGetHttpRequestAction;
use Payum\Core\Exception\RequestNotSupportedException;
use Symfony\Component\HttpFoundation\RequestStack;

final class GetHttpRequestAction implements ActionInterface
{
/**
* @var BaseGetHttpRequestAction
*/
private $decoratedGetHttpRequestAction;

/**
* @var RequestStack
*/
protected $httpRequestStack;

public function __construct(
BaseGetHttpRequestAction $decoratedGetHttpRequestAction,
RequestStack $httpRequestStack
) {
$this->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);
}
}

0 comments on commit d0eb5bf

Please sign in to comment.