/** * @test */ public function shouldForcePaymentActionAuthorization() { $action = new AuthorizeAction(); $action->setGateway($this->createGatewayMock()); $action->execute($request = new Authorize(['PAYMENTREQUEST_0_PAYMENTACTION' => 'FooBarBaz'])); $model = $request->getModel(); $this->assertArrayHasKey('PAYMENTREQUEST_0_PAYMENTACTION', $model); $this->assertEquals(Api::PAYMENTACTION_AUTHORIZATION, $model['PAYMENTREQUEST_0_PAYMENTACTION']); }
/** * @test */ public function shouldSetDetailsBackToPaymentEvenIfExceptionThrown() { $expectedDetails = array('foo' => 'fooVal'); $payment = new Payment(); $payment->setDetails($expectedDetails); $gatewayMock = $this->createGatewayMock(); $gatewayMock->expects($this->at(0))->method('execute')->with($this->isInstanceOf(GetHumanStatus::class))->will($this->returnCallback(function (GetHumanStatus $request) { $request->markPending(); })); $gatewayMock->expects($this->at(1))->method('execute')->with($this->isInstanceOf(Authorize::class))->will($this->returnCallback(function (Authorize $request) { $details = $request->getModel(); $details['bar'] = 'barVal'; throw new \Exception(); })); $action = new AuthorizePaymentAction(); $action->setGateway($gatewayMock); $this->setExpectedException('Exception'); $action->execute($authorize = new Authorize($payment)); $this->assertSame($payment, $authorize->getFirstModel()); $this->assertInstanceOf('ArrayAccess', $authorize->getModel()); $this->assertEquals(array('foo' => 'fooVal', 'bar' => 'barVal'), $payment->getDetails()); }