/** * @test */ public function shouldNotOverwriteAlreadySetExtraDetails() { $gatewayMock = $this->getMock(GatewayInterface::class); $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf(GetCurrency::class))->willReturnCallback(function (GetCurrency $request) { $request->name = 'US Dollar'; $request->alpha3 = 'USD'; $request->numeric = 123; $request->exp = 2; $request->country = 'US'; }); $payoutModel = new Payout(); $payoutModel->setRecipientEmail('theRecipientEmail'); $payoutModel->setCurrencyCode('USD'); $payoutModel->setTotalAmount(123); $payoutModel->setDescription('the description'); $payoutModel->setDetails(['foo' => 'fooVal']); $action = new ConvertPayoutAction(); $action->setGateway($gatewayMock); $action->execute($convert = new Convert($payoutModel, 'array')); $details = $convert->getResult(); $this->assertNotEmpty($details); $this->assertEquals(['CURRENCYCODE' => 'USD', 'L_AMT0' => 1.23, 'L_NOTE0' => 'the description', 'RECEIVERTYPE' => 'EmailAddress', 'L_EMAIL0' => 'theRecipientEmail', 'foo' => 'fooVal'], $details); }
/** * @test */ public function shouldSetDetailsBackToPayoutEvenIfExceptionThrown() { $expectedDetails = array('foo' => 'fooVal'); $payoutModel = new PayoutModel(); $payoutModel->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(Payout::class))->will($this->returnCallback(function (Payout $request) { $details = $request->getModel(); $details['bar'] = 'barVal'; throw new \Exception(); })); $action = new PayoutPayoutAction(); $action->setGateway($gatewayMock); $this->setExpectedException('Exception'); $action->execute($payout = new Payout($payoutModel)); $this->assertSame($payoutModel, $payout->getFirstModel()); $this->assertInstanceOf('ArrayAccess', $payout->getModel()); $this->assertEquals(array('foo' => 'fooVal', 'bar' => 'barVal'), $payoutModel->getDetails()); }
/** * @test */ public function shouldAllowGetDetailsPreviouslySet() { $payout = new Payout(); $payout->setDetails(['foo' => 'fooVal']); $this->assertEquals(['foo' => 'fooVal'], $payout->getDetails()); }