/** * @test */ public function shouldExecuteAuthorizeRequest() { $request = Request::create('/'); $request->query->set('foo', 'fooVal'); $token = new Token; $token->setPaymentName('thePayment'); $token->setAfterUrl('http://example.com/theAfterUrl'); $tokenVerifierMock = $this->getMock('Payum\Core\Security\HttpRequestVerifierInterface'); $tokenVerifierMock ->expects($this->once()) ->method('verify') ->with($this->identicalTo($request)) ->will($this->returnValue($token)) ; $tokenVerifierMock ->expects($this->once()) ->method('invalidate') ->with($this->identicalTo($token)) ; $paymentMock = $this->getMock('Payum\Core\PaymentInterface'); $paymentMock ->expects($this->once()) ->method('execute') ->with($this->isInstanceOf('Payum\Core\Request\Authorize')) ; $registryMock = $this->getMock('Payum\Core\Registry\RegistryInterface'); $registryMock ->expects($this->once()) ->method('getPayment') ->with('thePayment') ->will($this->returnValue($paymentMock)) ; $container = new Container; $container->set('payum', $registryMock); $container->set('payum.security.http_request_verifier', $tokenVerifierMock); $controller = new AuthorizeController; $controller->setContainer($container); $response = $controller->doAction($request); $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response); $this->assertEquals('http://example.com/theAfterUrl', $response->getTargetUrl()); }
/** * @test */ public function shouldExecuteAuthorizeRequest() { $request = Request::create('/'); $request->query->set('foo', 'fooVal'); $token = new Token(); $token->setGatewayName('theGateway'); $token->setAfterUrl('http://example.com/theAfterUrl'); $httpRequestVerifierMock = $this->getMock(HttpRequestVerifierInterface::class); $httpRequestVerifierMock->expects($this->once())->method('verify')->with($this->identicalTo($request))->will($this->returnValue($token)); $httpRequestVerifierMock->expects($this->once())->method('invalidate')->with($this->identicalTo($token)); $gatewayMock = $this->getMock(GatewayInterface::class); $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf(Authorize::class)); $registryMock = $this->getMock(RegistryInterface::class); $registryMock->expects($this->once())->method('getGateway')->with('theGateway')->will($this->returnValue($gatewayMock)); $payum = new Payum($registryMock, $httpRequestVerifierMock, $this->getMock(GenericTokenFactoryInterface::class), $this->getMock(StorageInterface::class)); $container = new Container(); $container->set('payum', $payum); $controller = new AuthorizeController(); $controller->setContainer($container); $response = $controller->doAction($request); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertEquals('http://example.com/theAfterUrl', $response->getTargetUrl()); }