diff --git a/Controller/PayumController.php b/Controller/PayumController.php index 7c626182..35ea40ee 100644 --- a/Controller/PayumController.php +++ b/Controller/PayumController.php @@ -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, + ]); } /** diff --git a/Tests/Controller/AuthorizeControllerTest.php b/Tests/Controller/AuthorizeControllerTest.php index bb426ce9..8a5185af 100644 --- a/Tests/Controller/AuthorizeControllerTest.php +++ b/Tests/Controller/AuthorizeControllerTest.php @@ -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 { @@ -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); diff --git a/Tests/Controller/CancelControllerTest.php b/Tests/Controller/CancelControllerTest.php index d0950e26..02222a72 100644 --- a/Tests/Controller/CancelControllerTest.php +++ b/Tests/Controller/CancelControllerTest.php @@ -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 @@ -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); @@ -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); diff --git a/Tests/Controller/CaptureControllerTest.php b/Tests/Controller/CaptureControllerTest.php index 32ce62fb..7cf79db5 100644 --- a/Tests/Controller/CaptureControllerTest.php +++ b/Tests/Controller/CaptureControllerTest.php @@ -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; @@ -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('/'); @@ -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())); @@ -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'); @@ -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); diff --git a/Tests/Controller/NotifyControllerTest.php b/Tests/Controller/NotifyControllerTest.php index 2aee5376..2d5678c7 100644 --- a/Tests/Controller/NotifyControllerTest.php +++ b/Tests/Controller/NotifyControllerTest.php @@ -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; @@ -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); diff --git a/Tests/Controller/PayoutControllerTest.php b/Tests/Controller/PayoutControllerTest.php index 50c529f2..266b896c 100644 --- a/Tests/Controller/PayoutControllerTest.php +++ b/Tests/Controller/PayoutControllerTest.php @@ -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 { @@ -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); diff --git a/Tests/Controller/RefundControllerTest.php b/Tests/Controller/RefundControllerTest.php index add2357d..a72a35aa 100644 --- a/Tests/Controller/RefundControllerTest.php +++ b/Tests/Controller/RefundControllerTest.php @@ -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; @@ -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); @@ -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); diff --git a/Tests/Functional/app/AppKernel.php b/Tests/Functional/app/AppKernel.php index f9f38f85..2d3bf8a8 100644 --- a/Tests/Functional/app/AppKernel.php +++ b/Tests/Functional/app/AppKernel.php @@ -58,4 +58,4 @@ public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load(__DIR__ . '/config/config.yml'); } -} \ No newline at end of file +}