Add test to check the payments are added when the PayPal response contains it

This commit is contained in:
Mészáros Róbert 2020-04-15 16:17:33 +03:00
parent f1b8ee128a
commit 60e979a4a2

View file

@ -552,4 +552,55 @@ class PurchaseUnitFactoryTest extends TestCase
$testee->fromPayPalResponse($response);
}
public function testFromPayPalResponsePaymentsGetAppended()
{
$rawItem = (object)['items' => 1];
$rawAmount = (object)['amount' => 1];
$rawPayee = (object)['payee' => 1];
$rawShipping = (object)['shipping' => 1];
$rawPayments = (object)['payments' => 1];
$amountFactory = Mockery::mock(AmountFactory::class);
$amount = Mockery::mock(Amount::class);
$amountFactory->expects('fromPayPalResponse')->with($rawAmount)->andReturn($amount);
$payeeFactory = Mockery::mock(PayeeFactory::class);
$payee = Mockery::mock(Payee::class);
$payeeFactory->expects('fromPayPalResponse')->with($rawPayee)->andReturn($payee);
$payeeRepository = Mockery::mock(PayeeRepository::class);
$itemFactory = Mockery::mock(ItemFactory::class);
$item = Mockery::mock(Item::class);
$itemFactory->expects('fromPayPalResponse')->with($rawItem)->andReturn($item);
$shippingFactory = Mockery::mock(ShippingFactory::class);
$shipping = Mockery::mock(Shipping::class);
$shippingFactory->expects('fromPayPalResponse')->with($rawShipping)->andReturn($shipping);
$paymentsFactory = Mockery::mock(PaymentsFactory::class);
$payments = Mockery::mock(Payments::class);
$paymentsFactory->expects('fromPayPalResponse')->with($rawPayments)->andReturn($payments);
$testee = new PurchaseUnitFactory(
$amountFactory,
$payeeRepository,
$payeeFactory,
$itemFactory,
$shippingFactory,
$paymentsFactory
);
$response = (object)[
'reference_id' => 'default',
'description' => 'description',
'customId' => 'customId',
'invoiceId' => 'invoiceId',
'softDescriptor' => 'softDescriptor',
'amount' => $rawAmount,
'items' => [$rawItem],
'payee' => $rawPayee,
'shipping' => $rawShipping,
'payments' => $rawPayments,
];
$unit = $testee->fromPayPalResponse($response);
$this->assertEquals($payments, $unit->payments());
}
}