Skip to content

Commit

Permalink
Register payum service in PayumController
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredup committed Apr 1, 2021
1 parent 7bf6527 commit 7cc019c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 58 deletions.
21 changes: 7 additions & 14 deletions Controller/PayumController.php
Expand Up @@ -9,25 +9,18 @@
abstract class PayumController extends AbstractController
{
/**
* @var Payum
*/
private $payum;

/**
* PayumController constructor.
* @param Payum $payum
* @return Payum
*/
public function __construct(Payum $payum)
protected function getPayum()
{
$this->payum = $payum;
return $this->get('payum');
}

/**
* @return Payum
*/
protected function getPayum()
public static function getSubscribedServices()
{
return $this->payum;
return array_merge(parent::getSubscribedServices(), [
'payum' => Payum::class,
]);
}

/**
Expand Down
12 changes: 3 additions & 9 deletions Tests/Controller/AuthorizeControllerTest.php
Expand Up @@ -3,17 +3,10 @@

use Payum\Bundle\PayumBundle\Controller\AuthorizeController;
use Payum\Core\GatewayInterface;
use Payum\Core\Model\Token;
use Payum\Core\Payum;
use Payum\Core\Registry\RegistryInterface;
use Payum\Core\Request\Authorize;
use Payum\Core\Security\GenericTokenFactoryInterface;
use Payum\Core\Security\HttpRequestVerifierInterface;
use Payum\Core\Storage\StorageInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;

class AuthorizeControllerTest extends AbstractControllerTest
{
Expand All @@ -32,7 +25,8 @@ public function shouldBeSubClassOfController()
*/
public function shouldExecuteAuthorizeRequest()
{
$controller = new AuthorizeController($this->payum);
$controller = new AuthorizeController();
$controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }]));

$response = $controller->doAction($this->request);

Expand Down
15 changes: 5 additions & 10 deletions Tests/Controller/CancelControllerTest.php
Expand Up @@ -3,17 +3,10 @@

use Payum\Bundle\PayumBundle\Controller\CancelController;
use Payum\Core\GatewayInterface;
use Payum\Core\Model\Token;
use Payum\Core\Payum;
use Payum\Core\Registry\RegistryInterface;
use Payum\Core\Request\Cancel;
use Payum\Core\Security\GenericTokenFactoryInterface;
use Payum\Core\Security\HttpRequestVerifierInterface;
use Payum\Core\Storage\StorageInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class CancelControllerTest extends AbstractControllerTest
Expand All @@ -33,7 +26,8 @@ public function shouldBeSubClassOfController()
*/
public function shouldExecuteCancelRequest()
{
$controller = new CancelController($this->payum);
$controller = new CancelController();
$controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }]));

$response = $controller->doAction($this->request);

Expand All @@ -48,7 +42,8 @@ public function shouldExecuteCancelRequestWithoutAfterUrl()
{
$this->token->setAfterUrl(null);

$controller = new CancelController($this->payum);
$controller = new CancelController();
$controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }]));

$response = $controller->doAction($this->request);

Expand Down
25 changes: 13 additions & 12 deletions Tests/Controller/CaptureControllerTest.php
Expand Up @@ -3,15 +3,11 @@

use Payum\Bundle\PayumBundle\Controller\CaptureController;
use Payum\Core\GatewayInterface;
use Payum\Core\Model\Token;
use Payum\Core\Payum;
use Payum\Core\Registry\RegistryInterface;
use Payum\Core\Request\Capture;
use Payum\Core\Security\GenericTokenFactoryInterface;
use Payum\Core\Security\HttpRequestVerifierInterface;
use Payum\Core\Storage\StorageInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
Expand Down Expand Up @@ -43,7 +39,8 @@ public function throwBadRequestIfSessionNotStartedOnDoSessionAction()
HttpRequestVerifierInterface::class
);

$controller = new CaptureController($this->payum);
$controller = new CaptureController();
$controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }]));

$request = Request::create('/');

Expand All @@ -66,7 +63,8 @@ public function throwBadRequestIfSessionNotContainPayumTokenOnDoSessionAction()
HttpRequestVerifierInterface::class
);

$controller = new CaptureController($this->payum);
$controller = new CaptureController();
$controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }]));

$request = Request::create('/');
$request->setSession(new Session(new MockArraySessionStorage()));
Expand All @@ -90,16 +88,18 @@ public function shouldDoRedirectToCaptureWithTokenUrl()
->will($this->returnValue('/payment/capture/theToken?foo=fooVal'))
;

$container = new Container;
$container->set('router', $routerMock);
$locator = new ServiceLocator([
'payum' => function () { return $this->payum; },
'router' => function () use ($routerMock) { return $routerMock; }
]);

$this->registryMock = $this->createMock(RegistryInterface::class);
$this->httpRequestVerifierMock = $this->createMock(
HttpRequestVerifierInterface::class
);

$controller = new CaptureController($this->payum);
$controller->setContainer($container);
$controller = new CaptureController();
$controller->setContainer($locator);

$this->request = Request::create('/');
$this->request->query->set('foo', 'fooVal');
Expand All @@ -118,7 +118,8 @@ public function shouldDoRedirectToCaptureWithTokenUrl()
*/
public function shouldExecuteCaptureRequest()
{
$controller = new CaptureController($this->payum);
$controller = new CaptureController();
$controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }]));

$response = $controller->doAction($this->request);

Expand Down
4 changes: 3 additions & 1 deletion Tests/Controller/NotifyControllerTest.php
Expand Up @@ -8,6 +8,7 @@
use Payum\Core\Request\Notify;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

Expand Down Expand Up @@ -44,7 +45,8 @@ public function shouldExecuteNotifyRequestOnDoUnsafe()
->with('theGatewayName')
->will($this->returnValue($gatewayMock));

$controller = new NotifyController($registryMock);
$controller = new NotifyController();
$controller->setContainer(new ServiceLocator(['payum' => function () use ($registryMock) { return $registryMock; }]));

$response = $controller->doUnsafeAction($request);

Expand Down
12 changes: 3 additions & 9 deletions Tests/Controller/PayoutControllerTest.php
Expand Up @@ -3,17 +3,10 @@

use Payum\Bundle\PayumBundle\Controller\PayoutController;
use Payum\Core\GatewayInterface;
use Payum\Core\Model\Token;
use Payum\Core\Payum;
use Payum\Core\Registry\RegistryInterface;
use Payum\Core\Request\Payout;
use Payum\Core\Security\GenericTokenFactoryInterface;
use Payum\Core\Security\HttpRequestVerifierInterface;
use Payum\Core\Storage\StorageInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;

class PayoutControllerTest extends AbstractControllerTest
{
Expand All @@ -32,7 +25,8 @@ public function shouldBeSubClassOfController()
*/
public function shouldExecutePayoutRequest()
{
$controller = new PayoutController($this->payum);
$controller = new PayoutController();
$controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }]));

$response = $controller->doAction($this->request);

Expand Down
7 changes: 5 additions & 2 deletions Tests/Controller/RefundControllerTest.php
Expand Up @@ -6,6 +6,7 @@
use Payum\Core\GatewayInterface;
use Payum\Core\Request\Refund;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -26,7 +27,8 @@ public function shouldBeSubClassOfController()
*/
public function shouldExecuteRefundRequest()
{
$controller = new RefundController($this->payum);
$controller = new RefundController();
$controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }]));

$response = $controller->doAction($this->request);

Expand All @@ -41,7 +43,8 @@ public function shouldExecuteRefundRequestWithoutAfterUrl()
{
$this->token->setAfterUrl(null);

$controller = new RefundController($this->payum);
$controller = new RefundController();
$controller->setContainer(new ServiceLocator(['payum' => function () { return $this->payum; }]));

$response = $controller->doAction($this->request);

Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/app/AppKernel.php
Expand Up @@ -58,4 +58,4 @@ public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__ . '/config/config.yml');
}
}
}

0 comments on commit 7cc019c

Please sign in to comment.