mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Fix phpunit
This commit is contained in:
parent
f47d7cec18
commit
db9852b535
2 changed files with 0 additions and 150 deletions
|
@ -45,7 +45,6 @@ class PurchaseUnitTest extends TestCase
|
|||
$shipping,
|
||||
'referenceId',
|
||||
'description',
|
||||
null,
|
||||
'customId',
|
||||
'invoiceId',
|
||||
'softDescriptor'
|
||||
|
@ -54,7 +53,6 @@ class PurchaseUnitTest extends TestCase
|
|||
$this->assertEquals($amount, $testee->amount());
|
||||
$this->assertEquals('referenceId', $testee->reference_id());
|
||||
$this->assertEquals('description', $testee->description());
|
||||
$this->assertNull($testee->payee());
|
||||
$this->assertEquals('customId', $testee->custom_id());
|
||||
$this->assertEquals('invoiceId', $testee->invoice_id());
|
||||
$this->assertEquals('softDescriptor', $testee->soft_descriptor());
|
||||
|
@ -808,46 +806,4 @@ class PurchaseUnitTest extends TestCase
|
|||
|
||||
return $values;
|
||||
}
|
||||
|
||||
public function testPayee()
|
||||
{
|
||||
$amount = Mockery::mock(Amount::class);
|
||||
$amount->shouldReceive('breakdown')->andReturnNull();
|
||||
$amount->shouldReceive('to_array')->andReturn(['amount']);
|
||||
$item1 = Mockery::mock(Item::class);
|
||||
$item1->shouldReceive('to_array')->andReturn(['item1']);
|
||||
$item2 = Mockery::mock(Item::class);
|
||||
$item2->shouldReceive('to_array')->andReturn(['item2']);
|
||||
$shipping = Mockery::mock(Shipping::class);
|
||||
$shipping->shouldReceive('to_array')->andReturn(['shipping']);
|
||||
$payee = Mockery::mock(Payee::class);
|
||||
$payee->shouldReceive('to_array')->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->to_array());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,9 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Address;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Amount;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Item;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payee;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payments;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Shipping;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayeeRepository;
|
||||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use Mockery;
|
||||
|
||||
|
@ -45,11 +43,6 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
->shouldReceive('from_wc_order')
|
||||
->with($wcOrder)
|
||||
->andReturn($amount);
|
||||
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||
$payee = Mockery::mock(Payee::class);
|
||||
$payeeRepository
|
||||
->shouldReceive('payee')->andReturn($payee);
|
||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||
$itemFactory
|
||||
->shouldReceive('from_wc_order')
|
||||
|
@ -82,7 +75,6 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
|
||||
$unit = $testee->from_wc_order($wcOrder);
|
||||
$this->assertTrue(is_a($unit, PurchaseUnit::class));
|
||||
$this->assertEquals($payee, $unit->payee());
|
||||
$this->assertEquals('', $unit->description());
|
||||
$this->assertEquals('default', $unit->reference_id());
|
||||
$this->assertEquals($this->wcOrderId, $unit->custom_id());
|
||||
|
@ -104,11 +96,6 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
->shouldReceive('from_wc_order')
|
||||
->with($wcOrder)
|
||||
->andReturn($amount);
|
||||
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||
$payee = Mockery::mock(Payee::class);
|
||||
$payeeRepository
|
||||
->shouldReceive('payee')->andReturn($payee);
|
||||
|
||||
$fee = Mockery::mock(Item::class, [
|
||||
'category' => Item::DIGITAL_GOODS,
|
||||
|
@ -158,11 +145,6 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
->expects('from_wc_order')
|
||||
->with($wcOrder)
|
||||
->andReturn($amount);
|
||||
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||
$payee = Mockery::mock(Payee::class);
|
||||
$payeeRepository
|
||||
->expects('payee')->andReturn($payee);
|
||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||
$itemFactory
|
||||
->expects('from_wc_order')
|
||||
|
@ -210,11 +192,6 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
->expects('from_wc_order')
|
||||
->with($wcOrder)
|
||||
->andReturn($amount);
|
||||
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||
$payee = Mockery::mock(Payee::class);
|
||||
$payeeRepository
|
||||
->expects('payee')->andReturn($payee);
|
||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||
$itemFactory
|
||||
->expects('from_wc_order')
|
||||
|
@ -259,11 +236,6 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
->expects('from_wc_cart')
|
||||
->with($wcCart)
|
||||
->andReturn($amount);
|
||||
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||
$payee = Mockery::mock(Payee::class);
|
||||
$payeeRepository
|
||||
->expects('payee')->andReturn($payee);
|
||||
|
||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||
$itemFactory
|
||||
|
@ -298,7 +270,6 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
|
||||
$unit = $testee->from_wc_cart($wcCart);
|
||||
$this->assertTrue(is_a($unit, PurchaseUnit::class));
|
||||
$this->assertEquals($payee, $unit->payee());
|
||||
$this->assertEquals('', $unit->description());
|
||||
$this->assertEquals('default', $unit->reference_id());
|
||||
$this->assertEquals('', $unit->custom_id());
|
||||
|
@ -321,11 +292,6 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
->expects('from_wc_cart')
|
||||
->with($wcCart)
|
||||
->andReturn($amount);
|
||||
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||
$payee = Mockery::mock(Payee::class);
|
||||
$payeeRepository
|
||||
->expects('payee')->andReturn($payee);
|
||||
|
||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||
$itemFactory
|
||||
|
@ -357,11 +323,6 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
->expects('from_wc_cart')
|
||||
->with($wcCart)
|
||||
->andReturn($amount);
|
||||
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||
$payee = Mockery::mock(Payee::class);
|
||||
$payeeRepository
|
||||
->expects('payee')->andReturn($payee);
|
||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||
$itemFactory
|
||||
->expects('from_wc_cart')
|
||||
|
@ -396,15 +357,10 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
{
|
||||
$rawItem = (object) ['items' => 1];
|
||||
$rawAmount = (object) ['amount' => 1];
|
||||
$rawPayee = (object) ['payee' => 1];
|
||||
$rawShipping = (object) ['shipping' => 1];
|
||||
$amountFactory = Mockery::mock(AmountFactory::class);
|
||||
$amount = Mockery::mock(Amount::class);
|
||||
$amountFactory->expects('from_paypal_response')->with($rawAmount)->andReturn($amount);
|
||||
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||
$payee = Mockery::mock(Payee::class);
|
||||
$payeeFactory->expects('from_paypal_response')->with($rawPayee)->andReturn($payee);
|
||||
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||
$itemFactory->expects('from_paypal_response')->with($rawItem)->andReturn($this->item);
|
||||
$shippingFactory = Mockery::mock(ShippingFactory::class);
|
||||
|
@ -426,13 +382,11 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
'soft_descriptor' => 'softDescriptor',
|
||||
'amount' => $rawAmount,
|
||||
'items' => [$rawItem],
|
||||
'payee' => $rawPayee,
|
||||
'shipping' => $rawShipping,
|
||||
];
|
||||
|
||||
$unit = $testee->from_paypal_response($response);
|
||||
$this->assertTrue(is_a($unit, PurchaseUnit::class));
|
||||
$this->assertEquals($payee, $unit->payee());
|
||||
$this->assertEquals('description', $unit->description());
|
||||
$this->assertEquals('default', $unit->reference_id());
|
||||
$this->assertEquals('customId', $unit->custom_id());
|
||||
|
@ -443,57 +397,13 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
$this->assertEquals($shipping, $unit->shipping());
|
||||
}
|
||||
|
||||
public function testFromPayPalResponsePayeeIsNull()
|
||||
{
|
||||
$rawItem = (object) ['items' => 1];
|
||||
$rawAmount = (object) ['amount' => 1];
|
||||
$rawPayee = (object) ['payee' => 1];
|
||||
$rawShipping = (object) ['shipping' => 1];
|
||||
$amountFactory = Mockery::mock(AmountFactory::class);
|
||||
$amount = Mockery::mock(Amount::class);
|
||||
$amountFactory->expects('from_paypal_response')->with($rawAmount)->andReturn($amount);
|
||||
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||
$itemFactory->expects('from_paypal_response')->with($rawItem)->andReturn($this->item);
|
||||
$shippingFactory = Mockery::mock(ShippingFactory::class);
|
||||
$shipping = Mockery::mock(Shipping::class);
|
||||
$shippingFactory->expects('from_paypal_response')->with($rawShipping)->andReturn($shipping);
|
||||
$paymentsFacory = Mockery::mock(PaymentsFactory::class);
|
||||
$testee = new PurchaseUnitFactory(
|
||||
$amountFactory,
|
||||
$itemFactory,
|
||||
$shippingFactory,
|
||||
$paymentsFacory
|
||||
);
|
||||
|
||||
$response = (object) [
|
||||
'reference_id' => 'default',
|
||||
'description' => 'description',
|
||||
'customId' => 'customId',
|
||||
'invoiceId' => 'invoiceId',
|
||||
'softDescriptor' => 'softDescriptor',
|
||||
'amount' => $rawAmount,
|
||||
'items' => [$rawItem],
|
||||
'shipping' => $rawShipping,
|
||||
];
|
||||
|
||||
$unit = $testee->from_paypal_response($response);
|
||||
$this->assertNull($unit->payee());
|
||||
}
|
||||
|
||||
public function testFromPayPalResponseShippingIsNull()
|
||||
{
|
||||
$rawItem = (object) ['items' => 1];
|
||||
$rawAmount = (object) ['amount' => 1];
|
||||
$rawPayee = (object) ['payee' => 1];
|
||||
$amountFactory = Mockery::mock(AmountFactory::class);
|
||||
$amount = Mockery::mock(Amount::class);
|
||||
$amountFactory->expects('from_paypal_response')->with($rawAmount)->andReturn($amount);
|
||||
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||
$payee = Mockery::mock(Payee::class);
|
||||
$payeeFactory->expects('from_paypal_response')->with($rawPayee)->andReturn($payee);
|
||||
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||
$itemFactory->expects('from_paypal_response')->with($rawItem)->andReturn($this->item);
|
||||
$shippingFactory = Mockery::mock(ShippingFactory::class);
|
||||
|
@ -513,7 +423,6 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
'softDescriptor' => 'softDescriptor',
|
||||
'amount' => $rawAmount,
|
||||
'items' => [$rawItem],
|
||||
'payee' => $rawPayee,
|
||||
];
|
||||
|
||||
$unit = $testee->from_paypal_response($response);
|
||||
|
@ -523,8 +432,6 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
public function testFromPayPalResponseNeedsReferenceId()
|
||||
{
|
||||
$amountFactory = Mockery::mock(AmountFactory::class);
|
||||
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||
$shippingFactory = Mockery::mock(ShippingFactory::class);
|
||||
$paymentsFacory = Mockery::mock(PaymentsFactory::class);
|
||||
|
@ -542,7 +449,6 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
'softDescriptor' => 'softDescriptor',
|
||||
'amount' => '',
|
||||
'items' => [],
|
||||
'payee' => '',
|
||||
'shipping' => '',
|
||||
];
|
||||
|
||||
|
@ -554,17 +460,12 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
{
|
||||
$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('from_paypal_response')->with($rawAmount)->andReturn($amount);
|
||||
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||
$payee = Mockery::mock(Payee::class);
|
||||
$payeeFactory->expects('from_paypal_response')->with($rawPayee)->andReturn($payee);
|
||||
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||
$item = Mockery::mock(Item::class, ['category' => Item::PHYSICAL_GOODS]);
|
||||
$itemFactory->expects('from_paypal_response')->with($rawItem)->andReturn($item);
|
||||
|
@ -591,7 +492,6 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
'softDescriptor' => 'softDescriptor',
|
||||
'amount' => $rawAmount,
|
||||
'items' => [$rawItem],
|
||||
'payee' => $rawPayee,
|
||||
'shipping' => $rawShipping,
|
||||
'payments' => $rawPayments,
|
||||
];
|
||||
|
@ -604,17 +504,12 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
{
|
||||
$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('from_paypal_response')->with($rawAmount)->andReturn($amount);
|
||||
$payeeFactory = Mockery::mock(PayeeFactory::class);
|
||||
$payee = Mockery::mock(Payee::class);
|
||||
$payeeFactory->expects('from_paypal_response')->with($rawPayee)->andReturn($payee);
|
||||
$payeeRepository = Mockery::mock(PayeeRepository::class);
|
||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||
$item = Mockery::mock(Item::class, ['category' => Item::PHYSICAL_GOODS]);
|
||||
$itemFactory->expects('from_paypal_response')->with($rawItem)->andReturn($item);
|
||||
|
@ -639,7 +534,6 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
'softDescriptor' => 'softDescriptor',
|
||||
'amount' => $rawAmount,
|
||||
'items' => [$rawItem],
|
||||
'payee' => $rawPayee,
|
||||
'shipping' => $rawShipping,
|
||||
];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue