mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
more tests
This commit is contained in:
parent
30fa8b2ff2
commit
bf39506270
6 changed files with 523 additions and 0 deletions
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\ApiClient\Entity;
|
||||
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AddressTest extends TestCase
|
||||
{
|
||||
|
||||
public function test() {
|
||||
$testee = new Address(
|
||||
'countryCode',
|
||||
'addressLine1',
|
||||
'addressLine2',
|
||||
'adminArea1',
|
||||
'adminArea2',
|
||||
'postalCode'
|
||||
);
|
||||
|
||||
$this->assertEquals('countryCode', $testee->countryCode());
|
||||
$this->assertEquals('addressLine1', $testee->addressLine1());
|
||||
$this->assertEquals('addressLine2', $testee->addressLine2());
|
||||
$this->assertEquals('adminArea1', $testee->adminArea1());
|
||||
$this->assertEquals('adminArea2', $testee->adminArea2());
|
||||
$this->assertEquals('postalCode', $testee->postalCode());
|
||||
}
|
||||
public function testToArray()
|
||||
{
|
||||
$testee = new Address(
|
||||
'countryCode',
|
||||
'addressLine1',
|
||||
'addressLine2',
|
||||
'adminArea1',
|
||||
'adminArea2',
|
||||
'postalCode'
|
||||
);
|
||||
|
||||
$expected = [
|
||||
'country_code' => 'countryCode',
|
||||
'address_line_1' => 'addressLine1',
|
||||
'address_line_2' => 'addressLine2',
|
||||
'admin_area_1' => 'adminArea1',
|
||||
'admin_area_2' => 'adminArea2',
|
||||
'postal_code' => 'postalCode',
|
||||
];
|
||||
|
||||
$actual = $testee->toArray();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\ApiClient\Entity;
|
||||
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AmountBreakdownTest extends TestCase
|
||||
{
|
||||
|
||||
public function test() {
|
||||
$itemTotal = \Mockery::mock(Money::class);
|
||||
$itemTotal
|
||||
->expects('toArray')->andReturn(['itemTotal']);
|
||||
$shipping = \Mockery::mock(Money::class);
|
||||
$shipping
|
||||
->expects('toArray')->andReturn(['shipping']);
|
||||
$taxTotal = \Mockery::mock(Money::class);
|
||||
$taxTotal
|
||||
->expects('toArray')->andReturn(['taxTotal']);
|
||||
$handling = \Mockery::mock(Money::class);
|
||||
$handling
|
||||
->expects('toArray')->andReturn(['handling']);
|
||||
$insurance = \Mockery::mock(Money::class);
|
||||
$insurance
|
||||
->expects('toArray')->andReturn(['insurance']);
|
||||
$shippingDiscount = \Mockery::mock(Money::class);
|
||||
$shippingDiscount
|
||||
->expects('toArray')->andReturn(['shippingDiscount']);
|
||||
$discount = \Mockery::mock(Money::class);
|
||||
$discount
|
||||
->expects('toArray')->andReturn(['discount']);
|
||||
$testee = new AmountBreakdown(
|
||||
$itemTotal,
|
||||
$shipping,
|
||||
$taxTotal,
|
||||
$handling,
|
||||
$insurance,
|
||||
$shippingDiscount,
|
||||
$discount
|
||||
);
|
||||
|
||||
$this->assertEquals($itemTotal, $testee->itemTotal());
|
||||
$this->assertEquals($shipping, $testee->shipping());
|
||||
$this->assertEquals($taxTotal, $testee->taxTotal());
|
||||
$this->assertEquals($handling, $testee->handling());
|
||||
$this->assertEquals($insurance, $testee->insurance());
|
||||
$this->assertEquals($shippingDiscount, $testee->shippingDiscount());
|
||||
$this->assertEquals($discount, $testee->discount());
|
||||
|
||||
$expected = [
|
||||
'item_total' => ['itemTotal'],
|
||||
'shipping' => ['shipping'],
|
||||
'tax_total' => ['taxTotal'],
|
||||
'handling' => ['handling'],
|
||||
'insurance' => ['insurance'],
|
||||
'shipping_discount' => ['shippingDiscount'],
|
||||
'discount' => ['discount'],
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $testee->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataDropArrayKeyIfNoValueGiven
|
||||
*/
|
||||
public function testDropArrayKeyIfNoValueGiven($keyMissing, $methodName) {
|
||||
|
||||
$itemTotal = \Mockery::mock(Money::class);
|
||||
$itemTotal
|
||||
->expects('toArray')->andReturn(['itemTotal']);
|
||||
$shipping = \Mockery::mock(Money::class);
|
||||
$shipping
|
||||
->expects('toArray')->andReturn(['shipping']);
|
||||
$taxTotal = \Mockery::mock(Money::class);
|
||||
$taxTotal
|
||||
->expects('toArray')->andReturn(['taxTotal']);
|
||||
$handling = \Mockery::mock(Money::class);
|
||||
$handling
|
||||
->expects('toArray')->andReturn(['handling']);
|
||||
$insurance = \Mockery::mock(Money::class);
|
||||
$insurance
|
||||
->expects('toArray')->andReturn(['insurance']);
|
||||
$shippingDiscount = \Mockery::mock(Money::class);
|
||||
$shippingDiscount
|
||||
->expects('toArray')->andReturn(['shippingDiscount']);
|
||||
$discount = \Mockery::mock(Money::class);
|
||||
$discount
|
||||
->expects('toArray')->andReturn(['discount']);
|
||||
|
||||
|
||||
$items = [
|
||||
'item_total' => $itemTotal,
|
||||
'shipping' => $shipping,
|
||||
'tax_total' => $taxTotal,
|
||||
'handling' => $handling,
|
||||
'insurance' => $insurance,
|
||||
'shipping_discount' => $shippingDiscount,
|
||||
'discount' => $discount,
|
||||
];
|
||||
$items[$keyMissing] = null;
|
||||
|
||||
$testee = new AmountBreakdown(...array_values($items));
|
||||
$array = $testee->toArray();
|
||||
$result = ! array_key_exists($keyMissing, $array);
|
||||
$this->assertTrue($result);
|
||||
$this->assertNull($testee->{$methodName}(), "$methodName should return null");
|
||||
}
|
||||
|
||||
public function dataDropArrayKeyIfNoValueGiven() : array {
|
||||
return [
|
||||
['item_total', 'itemTotal'],
|
||||
['shipping', 'shipping'],
|
||||
['tax_total', 'taxTotal'],
|
||||
['handling', 'handling'],
|
||||
['insurance', 'insurance'],
|
||||
['shipping_discount', 'shippingDiscount'],
|
||||
['discount', 'discount'],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\ApiClient\Entity;
|
||||
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AmountTest extends TestCase
|
||||
{
|
||||
|
||||
public function test() {
|
||||
$money = \Mockery::mock(Money::class);
|
||||
$money->expects('currencyCode')->andReturn('currencyCode');
|
||||
$money->expects('value')->andReturn(1.10);
|
||||
$testee = new Amount($money);
|
||||
|
||||
$this->assertEquals('currencyCode', $testee->currencyCode());
|
||||
$this->assertEquals(1.10, $testee->value());
|
||||
}
|
||||
public function testBreakdownIsNull() {
|
||||
$money = \Mockery::mock(Money::class);
|
||||
$money->expects('currencyCode')->andReturn('currencyCode');
|
||||
$money->expects('value')->andReturn(1.10);
|
||||
$testee = new Amount($money);
|
||||
|
||||
$this->assertNull($testee->breakdown());
|
||||
|
||||
$expectedArray = [
|
||||
'currency_code' => 'currencyCode',
|
||||
'value' => 1.10,
|
||||
];
|
||||
$this->assertEquals($expectedArray, $testee->toArray());
|
||||
}
|
||||
public function testBreakdown() {
|
||||
$money = \Mockery::mock(Money::class);
|
||||
$money->expects('currencyCode')->andReturn('currencyCode');
|
||||
$money->expects('value')->andReturn(1.10);
|
||||
$breakdown = \Mockery::mock(AmountBreakdown::class);
|
||||
$breakdown->expects('toArray')->andReturn([1]);
|
||||
$testee = new Amount($money, $breakdown);
|
||||
|
||||
$this->assertEquals($breakdown, $testee->breakdown());
|
||||
|
||||
$expectedArray = [
|
||||
'currency_code' => 'currencyCode',
|
||||
'value' => 1.10,
|
||||
'breakdown' => [1]
|
||||
];
|
||||
$this->assertEquals($expectedArray, $testee->toArray());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\ApiClient\Entity;
|
||||
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ItemTest extends TestCase
|
||||
{
|
||||
|
||||
public function test() {
|
||||
$unitAmount = \Mockery::mock(Money::class);
|
||||
$tax = \Mockery::mock(Money::class);
|
||||
$testee = new Item(
|
||||
'name',
|
||||
$unitAmount,
|
||||
1,
|
||||
'description',
|
||||
$tax,
|
||||
'sku',
|
||||
'PHYSICAL_GOODS'
|
||||
);
|
||||
|
||||
$this->assertEquals('name', $testee->name());
|
||||
$this->assertEquals($unitAmount, $testee->unitAmount());
|
||||
$this->assertEquals(1, $testee->quantity());
|
||||
$this->assertEquals('description', $testee->description());
|
||||
$this->assertEquals($tax, $testee->tax());
|
||||
$this->assertEquals('sku', $testee->sku());
|
||||
$this->assertEquals('PHYSICAL_GOODS', $testee->category());
|
||||
}
|
||||
|
||||
public function testDigitalGoodsCategory() {
|
||||
$unitAmount = \Mockery::mock(Money::class);
|
||||
$tax = \Mockery::mock(Money::class);
|
||||
$testee = new Item(
|
||||
'name',
|
||||
$unitAmount,
|
||||
1,
|
||||
'description',
|
||||
$tax,
|
||||
'sku',
|
||||
'DIGITAL_GOODS'
|
||||
);
|
||||
|
||||
$this->assertEquals('DIGITAL_GOODS', $testee->category());
|
||||
}
|
||||
|
||||
public function testToArray() {
|
||||
|
||||
$unitAmount = \Mockery::mock(Money::class);
|
||||
$unitAmount
|
||||
->expects('toArray')
|
||||
->andReturn([1]);
|
||||
$tax = \Mockery::mock(Money::class);
|
||||
$tax
|
||||
->expects('toArray')
|
||||
->andReturn([2]);
|
||||
$testee = new Item(
|
||||
'name',
|
||||
$unitAmount,
|
||||
1,
|
||||
'description',
|
||||
$tax,
|
||||
'sku',
|
||||
'PHYSICAL_GOODS'
|
||||
);
|
||||
|
||||
$expected = [
|
||||
'name' => 'name',
|
||||
'unit_amount' => [1],
|
||||
'quantity' => 1,
|
||||
'description' => 'description',
|
||||
'sku' => 'sku',
|
||||
'category' => 'PHYSICAL_GOODS',
|
||||
'tax' => [2],
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $testee->toArray());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\ApiClient\Entity;
|
||||
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class MoneyTest extends TestCase
|
||||
{
|
||||
|
||||
public function test() {
|
||||
|
||||
$testee = new Money(1.10, 'currencyCode');
|
||||
$this->assertEquals(1.10, $testee->value());
|
||||
$this->assertEquals('currencyCode', $testee->currencyCode());
|
||||
|
||||
$expected = [
|
||||
'currency_code' => 'currencyCode',
|
||||
'value' => 1.10,
|
||||
];
|
||||
$this->assertEquals($expected, $testee->toArray());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,191 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\ApiClient\Entity;
|
||||
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PurchaseUnitTest extends TestCase
|
||||
{
|
||||
|
||||
public function test() {
|
||||
|
||||
$amount = \Mockery::mock(Amount::class);
|
||||
$amount->expects('breakdown')->andReturnNull();
|
||||
$amount->expects('toArray')->andReturn(['amount']);
|
||||
$item1 = \Mockery::mock(Item::class);
|
||||
$item1->expects('toArray')->andReturn(['item1']);
|
||||
$item2 = \Mockery::mock(Item::class);
|
||||
$item2->expects('toArray')->andReturn(['item2']);
|
||||
$shipping = \Mockery::mock(Shipping::class);
|
||||
$shipping->expects('toArray')->andReturn(['shipping']);
|
||||
$testee = new PurchaseUnit(
|
||||
$amount,
|
||||
[],
|
||||
$shipping,
|
||||
'referenceId',
|
||||
'description',
|
||||
null,
|
||||
'customId',
|
||||
'invoiceId',
|
||||
'softDescriptor'
|
||||
);
|
||||
|
||||
$this->assertEquals($amount, $testee->amount());
|
||||
$this->assertEquals('referenceId', $testee->referenceId());
|
||||
$this->assertEquals('description', $testee->description());
|
||||
$this->assertNull($testee->payee());
|
||||
$this->assertEquals('customId', $testee->customId());
|
||||
$this->assertEquals('invoiceId', $testee->invoiceId());
|
||||
$this->assertEquals('softDescriptor', $testee->softDescriptor());
|
||||
$this->assertEquals($shipping, $testee->shipping());
|
||||
$this->assertEquals([], $testee->items());
|
||||
|
||||
$expected = [
|
||||
'reference_id' => 'referenceId',
|
||||
'amount' => ['amount'],
|
||||
'description' => 'description',
|
||||
'items' => [],
|
||||
'shipping' => ['shipping'],
|
||||
'custom_id' => 'customId',
|
||||
'invoice_id' => 'invoiceId',
|
||||
'soft_descriptor' => 'softDescriptor',
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $testee->toArray());
|
||||
}
|
||||
|
||||
public function testDontDitchBecauseOfBreakdown() {
|
||||
|
||||
$breakdown = \Mockery::mock(AmountBreakdown::class);
|
||||
$breakdown->expects('shipping')->andReturnNull();
|
||||
$breakdown->expects('itemTotal')->andReturnNull();
|
||||
$breakdown->expects('discount')->andReturnNull();
|
||||
$breakdown->expects('taxTotal')->andReturnNull();
|
||||
$breakdown->expects('shippingDiscount')->andReturnNull();
|
||||
$breakdown->expects('handling')->andReturnNull();
|
||||
$breakdown->expects('insurance')->andReturnNull();
|
||||
$amount = \Mockery::mock(Amount::class);
|
||||
$amount->expects('breakdown')->andReturn($breakdown);
|
||||
$amount->expects('value')->andReturn(0.0);
|
||||
$amount->expects('toArray')->andReturn(['amount']);
|
||||
$item1 = \Mockery::mock(Item::class);
|
||||
$item1->expects('toArray')->andReturn(['item1']);
|
||||
$item2 = \Mockery::mock(Item::class);
|
||||
$item2->expects('toArray')->andReturn(['item2']);
|
||||
$shipping = \Mockery::mock(Shipping::class);
|
||||
$shipping->expects('toArray')->andReturn(['shipping']);
|
||||
$testee = new PurchaseUnit(
|
||||
$amount,
|
||||
[],
|
||||
$shipping,
|
||||
'referenceId',
|
||||
'description',
|
||||
null,
|
||||
'customId',
|
||||
'invoiceId',
|
||||
'softDescriptor'
|
||||
);
|
||||
|
||||
$expected = [
|
||||
'reference_id' => 'referenceId',
|
||||
'amount' => ['amount'],
|
||||
'description' => 'description',
|
||||
'shipping' => ['shipping'],
|
||||
'custom_id' => 'customId',
|
||||
'items' => [],
|
||||
'invoice_id' => 'invoiceId',
|
||||
'soft_descriptor' => 'softDescriptor',
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $testee->toArray());
|
||||
}
|
||||
|
||||
public function testDitchBecauseOfBreakdown() {
|
||||
|
||||
$breakdown = \Mockery::mock(AmountBreakdown::class);
|
||||
$breakdown->expects('shipping')->andReturnNull();
|
||||
$breakdown->expects('itemTotal')->andReturnNull();
|
||||
$breakdown->expects('discount')->andReturnNull();
|
||||
$breakdown->expects('taxTotal')->andReturnNull();
|
||||
$breakdown->expects('shippingDiscount')->andReturnNull();
|
||||
$breakdown->expects('handling')->andReturnNull();
|
||||
$breakdown->expects('insurance')->andReturnNull();
|
||||
$amount = \Mockery::mock(Amount::class);
|
||||
$amount->expects('breakdown')->andReturn($breakdown);
|
||||
$amount->expects('value')->andReturn(1.00);
|
||||
$amount->expects('toArray')->andReturn(['amount']);
|
||||
$item1 = \Mockery::mock(Item::class);
|
||||
$item1->expects('toArray')->andReturn(['item1']);
|
||||
$item2 = \Mockery::mock(Item::class);
|
||||
$item2->expects('toArray')->andReturn(['item2']);
|
||||
$shipping = \Mockery::mock(Shipping::class);
|
||||
$shipping->expects('toArray')->andReturn(['shipping']);
|
||||
$testee = new PurchaseUnit(
|
||||
$amount,
|
||||
[],
|
||||
$shipping,
|
||||
'referenceId',
|
||||
'description',
|
||||
null,
|
||||
'customId',
|
||||
'invoiceId',
|
||||
'softDescriptor'
|
||||
);
|
||||
|
||||
$expected = [
|
||||
'reference_id' => 'referenceId',
|
||||
'amount' => ['amount'],
|
||||
'description' => 'description',
|
||||
'shipping' => ['shipping'],
|
||||
'custom_id' => 'customId',
|
||||
'invoice_id' => 'invoiceId',
|
||||
'soft_descriptor' => 'softDescriptor',
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $testee->toArray());
|
||||
}
|
||||
|
||||
public function testPayee() {
|
||||
|
||||
$amount = \Mockery::mock(Amount::class);
|
||||
$amount->expects('breakdown')->andReturnNull();
|
||||
$amount->expects('toArray')->andReturn(['amount']);
|
||||
$item1 = \Mockery::mock(Item::class);
|
||||
$item1->expects('toArray')->andReturn(['item1']);
|
||||
$item2 = \Mockery::mock(Item::class);
|
||||
$item2->expects('toArray')->andReturn(['item2']);
|
||||
$shipping = \Mockery::mock(Shipping::class);
|
||||
$shipping->expects('toArray')->andReturn(['shipping']);
|
||||
$payee = \Mockery::mock(Payee::class);
|
||||
$payee->expects('toArray')->andReturn(['payee']);
|
||||
$testee = new PurchaseUnit(
|
||||
$amount,
|
||||
[],
|
||||
$shipping,
|
||||
'referenceId',
|
||||
'description',
|
||||
$payee,
|
||||
'customId',
|
||||
'invoiceId',
|
||||
'softDescriptor'
|
||||
);
|
||||
|
||||
$this->assertEquals($payee, $testee->payee());
|
||||
|
||||
$expected = [
|
||||
'reference_id' => 'referenceId',
|
||||
'amount' => ['amount'],
|
||||
'description' => 'description',
|
||||
'items' => [],
|
||||
'shipping' => ['shipping'],
|
||||
'custom_id' => 'customId',
|
||||
'invoice_id' => 'invoiceId',
|
||||
'soft_descriptor' => 'softDescriptor',
|
||||
'payee' => ['payee'],
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $testee->toArray());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue