From 7445c91ed72d930ca232d80e06acc33221e23ef5 Mon Sep 17 00:00:00 2001 From: David Remer Date: Mon, 14 Sep 2020 07:51:45 +0300 Subject: [PATCH] fix tests --- composer.json | 2 +- .../src/Entity/class-amount.php | 2 +- .../Authentication/PayPalBearerTest.php | 19 ++++--- .../ApiClient/Endpoint/OrderEndpointTest.php | 34 ++++++------ .../PHPUnit/ApiClient/Endpoint/OrderTest.php | 16 +++--- .../Endpoint/PaymentsEndpointTest.php | 18 +++---- .../PHPUnit/ApiClient/Entity/AddressTest.php | 4 +- .../ApiClient/Entity/AmountBreakdownTest.php | 4 +- tests/PHPUnit/ApiClient/Entity/AmountTest.php | 4 +- .../Entity/AuthorizationStatusTest.php | 6 +-- .../ApiClient/Entity/AuthorizationTest.php | 4 +- tests/PHPUnit/ApiClient/Entity/ItemTest.php | 4 +- tests/PHPUnit/ApiClient/Entity/MoneyTest.php | 4 +- tests/PHPUnit/ApiClient/Entity/PayerTest.php | 4 +- .../PHPUnit/ApiClient/Entity/PaymentsTest.php | 4 +- .../ApiClient/Entity/PurchaseUnitTest.php | 4 +- tests/PHPUnit/ApiClient/Entity/TokenTest.php | 6 +-- .../ApiClient/Factory/AddressFactoryTest.php | 6 +-- .../ApiClient/Factory/AmountFactoryTest.php | 12 ++--- .../Factory/AuthorizationFactoryTest.php | 10 ++-- .../ApiClient/Factory/ItemFactoryTest.php | 8 +-- .../ApiClient/Factory/OrderFactoryTest.php | 18 +++---- .../ApiClient/Factory/PayerFactoryTest.php | 6 +-- .../ApiClient/Factory/PaymentsFactoryTest.php | 8 +-- .../Factory/PurchaseUnitFactoryTest.php | 52 ++++++++++++------- .../Repository/PayeeRepositoryTest.php | 6 +-- tests/PHPUnit/ApiClient/TestCase.php | 2 +- .../Endpoint/ChangeCartEndpointTest.php | 8 +-- .../Button/Helper/ThreeDSecureTest.php | 12 ++--- tests/PHPUnit/TestCase.php | 2 +- .../CheckoutPayPalAddressPresetTest.php | 22 ++++---- .../WcGateway/Gateway/WcGatewayTest.php | 20 +++---- .../AuthorizedPaymentsProcessorTest.php | 22 ++++---- .../Processor/OrderProcessorTest.php | 26 +++++----- .../ApplicationContextRepositoryTest.php | 6 +-- .../Repository/CartRepositoryTest.php | 2 +- tests/PHPUnit/bootstrap.php | 2 +- 37 files changed, 199 insertions(+), 190 deletions(-) diff --git a/composer.json b/composer.json index 1b9dd8420..25399e795 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ }, "autoload-dev": { "psr-4": { - "Inpsyde\\PayPalCommerce\\": "tests/PHPUnit/" + "WooCommerce\\PayPalCommerce\\": "tests/PHPUnit/" } }, "minimum-stability": "dev", diff --git a/modules/ppcp-api-client/src/Entity/class-amount.php b/modules/ppcp-api-client/src/Entity/class-amount.php index 99c261e8e..0148da6b3 100644 --- a/modules/ppcp-api-client/src/Entity/class-amount.php +++ b/modules/ppcp-api-client/src/Entity/class-amount.php @@ -62,7 +62,7 @@ class Amount { * * @return AmountBreakdown|null */ - public function breakdown(): AmountBreakdown { + public function breakdown() { return $this->breakdown; } diff --git a/tests/PHPUnit/ApiClient/Authentication/PayPalBearerTest.php b/tests/PHPUnit/ApiClient/Authentication/PayPalBearerTest.php index aedec07f2..c7349c420 100644 --- a/tests/PHPUnit/ApiClient/Authentication/PayPalBearerTest.php +++ b/tests/PHPUnit/ApiClient/Authentication/PayPalBearerTest.php @@ -1,12 +1,11 @@ andReturnUsing('json_encode'); $json = '{"access_token":"abc","expires_in":100, "created":' . time() . '}'; - $cache = Mockery::mock(CacheInterface::class); + $cache = Mockery::mock(Cache::class); $cache ->expects('get') ->andReturn('{"access_token":"abc","expires_in":100, "created":100}'); @@ -67,7 +66,7 @@ class PayPalBearerTest extends TestCase { expect('wp_json_encode')->andReturnUsing('json_encode'); $json = '{"access_token":"abc","expires_in":100, "created":' . time() . '}'; - $cache = Mockery::mock(CacheInterface::class); + $cache = Mockery::mock(Cache::class); $cache ->expects('get') ->andReturn(''); @@ -115,7 +114,7 @@ class PayPalBearerTest extends TestCase public function testCachedTokenIsStillValid() { $json = '{"access_token":"abc","expires_in":100, "created":' . time() . '}'; - $cache = Mockery::mock(CacheInterface::class); + $cache = Mockery::mock(Cache::class); $cache ->expects('get') ->andReturn($json); @@ -135,7 +134,7 @@ class PayPalBearerTest extends TestCase public function testExceptionThrownOnError() { $json = '{"access_token":"abc","expires_in":100, "created":' . time() . '}'; - $cache = Mockery::mock(CacheInterface::class); + $cache = Mockery::mock(Cache::class); $cache ->expects('get') ->andReturn(''); @@ -178,7 +177,7 @@ class PayPalBearerTest extends TestCase public function testExceptionThrownBecauseOfHttpStatusCode() { $json = '{"access_token":"abc","expires_in":100, "created":' . time() . '}'; - $cache = Mockery::mock(CacheInterface::class); + $cache = Mockery::mock(Cache::class); $cache ->expects('get') ->andReturn(''); diff --git a/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php b/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php index 0eac41ef7..975185f14 100644 --- a/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php +++ b/tests/PHPUnit/ApiClient/Endpoint/OrderEndpointTest.php @@ -1,26 +1,24 @@ shouldReceive('payee')->andReturn($payee); + $item = Mockery::mock(Item::class); + $item->shouldReceive('category')->andReturn(Item::PHYSICAL_GOODS); $itemFactory = Mockery::mock(ItemFactory::class); $itemFactory ->shouldReceive('from_wc_order') ->with($wcOrder) - ->andReturn([]); + ->andReturn([$item]); $address = Mockery::mock(Address::class); $address @@ -77,7 +79,7 @@ class PurchaseUnitFactoryTest extends TestCase $this->assertEquals('WC-' . $wcOrderId, $unit->custom_id()); $this->assertEquals('', $unit->soft_descriptor()); $this->assertEquals('WC-' . $wcOrderId, $unit->invoice_id()); - $this->assertEquals([], $unit->items()); + $this->assertEquals([$item], $unit->items()); $this->assertEquals($amount, $unit->amount()); $this->assertEquals($shipping, $unit->shipping()); } @@ -98,11 +100,12 @@ class PurchaseUnitFactoryTest extends TestCase $payee = Mockery::mock(Payee::class); $payeeRepository ->expects('payee')->andReturn($payee); + $item = Mockery::mock(Item::class, ['category' => Item::PHYSICAL_GOODS]); $itemFactory = Mockery::mock(ItemFactory::class); $itemFactory ->expects('from_wc_order') ->with($wcOrder) - ->andReturn([]); + ->andReturn([$item]); $address = Mockery::mock(Address::class); $address @@ -152,11 +155,12 @@ class PurchaseUnitFactoryTest extends TestCase $payee = Mockery::mock(Payee::class); $payeeRepository ->expects('payee')->andReturn($payee); + $item = Mockery::mock(Item::class, ['category' => Item::PHYSICAL_GOODS]); $itemFactory = Mockery::mock(ItemFactory::class); $itemFactory ->expects('from_wc_order') ->with($wcOrder) - ->andReturn([]); + ->andReturn([$item]); $address = Mockery::mock(Address::class); $address @@ -203,11 +207,14 @@ class PurchaseUnitFactoryTest extends TestCase $payee = Mockery::mock(Payee::class); $payeeRepository ->expects('payee')->andReturn($payee); + + $item = Mockery::mock(Item::class); + $item->shouldReceive('category')->andReturn(Item::PHYSICAL_GOODS); $itemFactory = Mockery::mock(ItemFactory::class); $itemFactory ->expects('from_wc_cart') ->with($wcCart) - ->andReturn([]); + ->andReturn([$item]); $address = Mockery::mock(Address::class); $address @@ -244,7 +251,7 @@ class PurchaseUnitFactoryTest extends TestCase $this->assertEquals('', $unit->custom_id()); $this->assertEquals('', $unit->soft_descriptor()); $this->assertEquals('', $unit->invoice_id()); - $this->assertEquals([], $unit->items()); + $this->assertEquals([$item], $unit->items()); $this->assertEquals($amount, $unit->amount()); $this->assertEquals($shipping, $unit->shipping()); } @@ -266,11 +273,13 @@ class PurchaseUnitFactoryTest extends TestCase $payee = Mockery::mock(Payee::class); $payeeRepository ->expects('payee')->andReturn($payee); + $item = Mockery::mock(Item::class); + $item->shouldReceive('category')->andReturn(Item::PHYSICAL_GOODS); $itemFactory = Mockery::mock(ItemFactory::class); $itemFactory ->expects('from_wc_cart') ->with($wcCart) - ->andReturn([]); + ->andReturn([$item]); $shippingFactory = Mockery::mock(ShippingFactory::class); $paymentsFacory = Mockery::mock(PaymentsFactory::class); $testee = new PurchaseUnitFactory( @@ -303,11 +312,13 @@ class PurchaseUnitFactoryTest extends TestCase $payee = Mockery::mock(Payee::class); $payeeRepository ->expects('payee')->andReturn($payee); + $item = Mockery::mock(Item::class); + $item->shouldReceive('category')->andReturn(Item::PHYSICAL_GOODS); $itemFactory = Mockery::mock(ItemFactory::class); $itemFactory ->expects('from_wc_cart') ->with($wcCart) - ->andReturn([]); + ->andReturn([$item]); $address = Mockery::mock(Address::class); $address @@ -355,11 +366,12 @@ class PurchaseUnitFactoryTest extends TestCase $payee = Mockery::mock(Payee::class); $payeeRepository ->expects('payee')->andReturn($payee); + $item = Mockery::mock(Item::class, ['category' => Item::PHYSICAL_GOODS]); $itemFactory = Mockery::mock(ItemFactory::class); $itemFactory ->expects('from_wc_cart') ->with($wcCart) - ->andReturn([]); + ->andReturn([$item]); $address = Mockery::mock(Address::class); $address @@ -552,7 +564,7 @@ class PurchaseUnitFactoryTest extends TestCase 'shipping' => '', ]; - $this->expectException(\Inpsyde\PayPalCommerce\ApiClient\Exception\RuntimeException::class); + $this->expectException(\WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException::class); $testee->from_paypal_response($response); } diff --git a/tests/PHPUnit/ApiClient/Repository/PayeeRepositoryTest.php b/tests/PHPUnit/ApiClient/Repository/PayeeRepositoryTest.php index 74610bead..8a25c48d8 100644 --- a/tests/PHPUnit/ApiClient/Repository/PayeeRepositoryTest.php +++ b/tests/PHPUnit/ApiClient/Repository/PayeeRepositoryTest.php @@ -1,10 +1,10 @@