From 8d11d75dd0ca04e96a29b5f731ec5309606824d5 Mon Sep 17 00:00:00 2001 From: David Remer Date: Tue, 14 Apr 2020 09:58:01 +0300 Subject: [PATCH] introduce TestCase --- modules.local/ppcp-api-client/composer.json | 8 ++++ .../tests/PHPUnit/Entity/AddressTest.php | 2 +- .../PHPUnit/Entity/AmountBreakdownTest.php | 16 +++---- .../tests/PHPUnit/Entity/AmountTest.php | 16 +++---- .../Entity/ErrorResponseCollectionTest.php | 3 +- .../PHPUnit/Entity/ErrorResponseTest.php | 3 +- .../tests/PHPUnit/Entity/ItemTest.php | 3 +- .../tests/PHPUnit/Entity/MoneyTest.php | 3 +- .../tests/PHPUnit/Entity/PurchaseUnitTest.php | 47 +++++++++---------- .../tests/PHPUnit/TestCase.php | 23 +++++++++ 10 files changed, 75 insertions(+), 49 deletions(-) create mode 100644 modules.local/ppcp-api-client/tests/PHPUnit/TestCase.php diff --git a/modules.local/ppcp-api-client/composer.json b/modules.local/ppcp-api-client/composer.json index e388aa55c..081b6320f 100644 --- a/modules.local/ppcp-api-client/composer.json +++ b/modules.local/ppcp-api-client/composer.json @@ -17,5 +17,13 @@ "psr-4": { "Inpsyde\\PayPalCommerce\\ApiClient\\": "src/" } + }, + "autoload-dev": { + "psr-4": { + "Inpsyde\\PayPalCommerce\\ApiClient\\": "tests/PHPUnit" + } + }, + "scripts": { + "unit": "./vendor/bin/phpunit --coverage-html build/coverage-report" } } \ No newline at end of file diff --git a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/AddressTest.php b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/AddressTest.php index 5c00e2954..cdabefa16 100644 --- a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/AddressTest.php +++ b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/AddressTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Inpsyde\PayPalCommerce\ApiClient\Entity; -use PHPUnit\Framework\TestCase; +use Inpsyde\PayPalCommerce\ApiClient\TestCase; class AddressTest extends TestCase { diff --git a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/AmountBreakdownTest.php b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/AmountBreakdownTest.php index bc18959ba..f7779f5ae 100644 --- a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/AmountBreakdownTest.php +++ b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/AmountBreakdownTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Inpsyde\PayPalCommerce\ApiClient\Entity; -use PHPUnit\Framework\TestCase; +use Inpsyde\PayPalCommerce\ApiClient\TestCase; class AmountBreakdownTest extends TestCase { @@ -69,25 +69,25 @@ class AmountBreakdownTest extends TestCase $itemTotal = \Mockery::mock(Money::class); $itemTotal - ->expects('toArray')->andReturn(['itemTotal']); + ->shouldReceive('toArray')->zeroOrMoreTimes()->andReturn(['itemTotal']); $shipping = \Mockery::mock(Money::class); $shipping - ->expects('toArray')->andReturn(['shipping']); + ->shouldReceive('toArray')->zeroOrMoreTimes()->andReturn(['shipping']); $taxTotal = \Mockery::mock(Money::class); $taxTotal - ->expects('toArray')->andReturn(['taxTotal']); + ->shouldReceive('toArray')->zeroOrMoreTimes()->andReturn(['taxTotal']); $handling = \Mockery::mock(Money::class); $handling - ->expects('toArray')->andReturn(['handling']); + ->shouldReceive('toArray')->zeroOrMoreTimes()->andReturn(['handling']); $insurance = \Mockery::mock(Money::class); $insurance - ->expects('toArray')->andReturn(['insurance']); + ->shouldReceive('toArray')->zeroOrMoreTimes()->andReturn(['insurance']); $shippingDiscount = \Mockery::mock(Money::class); $shippingDiscount - ->expects('toArray')->andReturn(['shippingDiscount']); + ->shouldReceive('toArray')->zeroOrMoreTimes()->andReturn(['shippingDiscount']); $discount = \Mockery::mock(Money::class); $discount - ->expects('toArray')->andReturn(['discount']); + ->shouldReceive('toArray')->zeroOrMoreTimes()->andReturn(['discount']); $items = [ diff --git a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/AmountTest.php b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/AmountTest.php index 306e3336e..a43c40112 100644 --- a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/AmountTest.php +++ b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/AmountTest.php @@ -4,15 +4,15 @@ declare(strict_types=1); namespace Inpsyde\PayPalCommerce\ApiClient\Entity; -use PHPUnit\Framework\TestCase; +use Inpsyde\PayPalCommerce\ApiClient\TestCase; class AmountTest extends TestCase { public function test() { $money = \Mockery::mock(Money::class); - $money->expects('currencyCode')->andReturn('currencyCode'); - $money->expects('value')->andReturn(1.10); + $money->shouldReceive('currencyCode')->andReturn('currencyCode'); + $money->shouldReceive('value')->andReturn(1.10); $testee = new Amount($money); $this->assertEquals('currencyCode', $testee->currencyCode()); @@ -20,8 +20,8 @@ class AmountTest extends TestCase } public function testBreakdownIsNull() { $money = \Mockery::mock(Money::class); - $money->expects('currencyCode')->andReturn('currencyCode'); - $money->expects('value')->andReturn(1.10); + $money->shouldReceive('currencyCode')->andReturn('currencyCode'); + $money->shouldReceive('value')->andReturn(1.10); $testee = new Amount($money); $this->assertNull($testee->breakdown()); @@ -34,10 +34,10 @@ class AmountTest extends TestCase } public function testBreakdown() { $money = \Mockery::mock(Money::class); - $money->expects('currencyCode')->andReturn('currencyCode'); - $money->expects('value')->andReturn(1.10); + $money->shouldReceive('currencyCode')->andReturn('currencyCode'); + $money->shouldReceive('value')->andReturn(1.10); $breakdown = \Mockery::mock(AmountBreakdown::class); - $breakdown->expects('toArray')->andReturn([1]); + $breakdown->shouldReceive('toArray')->andReturn([1]); $testee = new Amount($money, $breakdown); $this->assertEquals($breakdown, $testee->breakdown()); diff --git a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/ErrorResponseCollectionTest.php b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/ErrorResponseCollectionTest.php index e40574359..a7fb3546f 100644 --- a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/ErrorResponseCollectionTest.php +++ b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/ErrorResponseCollectionTest.php @@ -3,8 +3,7 @@ declare(strict_types=1); namespace Inpsyde\PayPalCommerce\ApiClient\Entity; - -use PHPUnit\Framework\TestCase; +use Inpsyde\PayPalCommerce\ApiClient\TestCase; class ErrorResponseCollectionTest extends TestCase { diff --git a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/ErrorResponseTest.php b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/ErrorResponseTest.php index 84c022d66..f7f288ca3 100644 --- a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/ErrorResponseTest.php +++ b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/ErrorResponseTest.php @@ -3,8 +3,7 @@ declare(strict_types=1); namespace Inpsyde\PayPalCommerce\ApiClient\Entity; - -use PHPUnit\Framework\TestCase; +use Inpsyde\PayPalCommerce\ApiClient\TestCase; class ErrorResponseTest extends TestCase { diff --git a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/ItemTest.php b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/ItemTest.php index a8e6574c4..d8c882bbe 100644 --- a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/ItemTest.php +++ b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/ItemTest.php @@ -3,8 +3,7 @@ declare(strict_types=1); namespace Inpsyde\PayPalCommerce\ApiClient\Entity; - -use PHPUnit\Framework\TestCase; +use Inpsyde\PayPalCommerce\ApiClient\TestCase; class ItemTest extends TestCase { diff --git a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/MoneyTest.php b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/MoneyTest.php index 347210200..83770e3fb 100644 --- a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/MoneyTest.php +++ b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/MoneyTest.php @@ -3,8 +3,7 @@ declare(strict_types=1); namespace Inpsyde\PayPalCommerce\ApiClient\Entity; - -use PHPUnit\Framework\TestCase; +use Inpsyde\PayPalCommerce\ApiClient\TestCase; class MoneyTest extends TestCase { diff --git a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/PurchaseUnitTest.php b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/PurchaseUnitTest.php index e654544e0..c327fb3a3 100644 --- a/modules.local/ppcp-api-client/tests/PHPUnit/Entity/PurchaseUnitTest.php +++ b/modules.local/ppcp-api-client/tests/PHPUnit/Entity/PurchaseUnitTest.php @@ -3,8 +3,7 @@ declare(strict_types=1); namespace Inpsyde\PayPalCommerce\ApiClient\Entity; - -use PHPUnit\Framework\TestCase; +use Inpsyde\PayPalCommerce\ApiClient\TestCase; use Mockery; class PurchaseUnitTest extends TestCase @@ -13,14 +12,14 @@ class PurchaseUnitTest extends TestCase public function test() { $amount = Mockery::mock(Amount::class); - $amount->expects('breakdown')->andReturnNull(); - $amount->expects('toArray')->andReturn(['amount']); + $amount->shouldReceive('breakdown')->andReturnNull(); + $amount->shouldReceive('toArray')->andReturn(['amount']); $item1 = Mockery::mock(Item::class); - $item1->expects('toArray')->andReturn(['item1']); + $item1->shouldReceive('toArray')->andReturn(['item1']); $item2 = Mockery::mock(Item::class); - $item2->expects('toArray')->andReturn(['item2']); + $item2->shouldReceive('toArray')->andReturn(['item2']); $shipping = Mockery::mock(Shipping::class); - $shipping->expects('toArray')->andReturn(['shipping']); + $shipping->shouldReceive('toArray')->andReturn(['shipping']); $testee = new PurchaseUnit( $amount, @@ -382,34 +381,34 @@ class PurchaseUnitTest extends TestCase $items = []; foreach ($test['items'] as $key => $item) { $unitAmount = Mockery::mock(Money::class); - $unitAmount->expects('value')->andReturn($item['value']); + $unitAmount->shouldReceive('value')->andReturn($item['value']); $tax = Mockery::mock(Money::class); - $tax->expects('value')->andReturn($item['tax']); + $tax->shouldReceive('value')->andReturn($item['tax']); $items[$key] = Mockery::mock(Item::class); - $items[$key]->expects('unitAmount')->andReturn($unitAmount); - $items[$key]->expects('tax')->andReturn($tax); - $items[$key]->expects('quantity')->andReturn($item['quantity']); - $items[$key]->expects('toArray')->andReturn([]); + $items[$key]->shouldReceive('unitAmount')->andReturn($unitAmount); + $items[$key]->shouldReceive('tax')->andReturn($tax); + $items[$key]->shouldReceive('quantity')->andReturn($item['quantity']); + $items[$key]->shouldReceive('toArray')->andReturn([]); } $breakdown = null; if ($test['breakdown']) { $breakdown = Mockery::mock(AmountBreakdown::class); foreach ($test['breakdown'] as $method => $value) { - $breakdown->expects($method)->andReturnUsing(function() use ($value) { + $breakdown->shouldReceive($method)->andReturnUsing(function() use ($value) { if (! is_numeric($value)) { return null; } $money = Mockery::mock(Money::class); - $money->expects('value')->andReturn($value); + $money->shouldReceive('value')->andReturn($value); return $money; }); } } $amount = Mockery::mock(Amount::class); - $amount->expects('toArray')->andReturn(['value' => [], 'breakdown' => []]); - $amount->expects('value')->andReturn($test['amount']); - $amount->expects('breakdown')->andReturn($breakdown); + $amount->shouldReceive('toArray')->andReturn(['value' => [], 'breakdown' => []]); + $amount->shouldReceive('value')->andReturn($test['amount']); + $amount->shouldReceive('breakdown')->andReturn($breakdown); $values[$testKey] = [ $items, @@ -425,16 +424,16 @@ class PurchaseUnitTest extends TestCase public function testPayee() { $amount = Mockery::mock(Amount::class); - $amount->expects('breakdown')->andReturnNull(); - $amount->expects('toArray')->andReturn(['amount']); + $amount->shouldReceive('breakdown')->andReturnNull(); + $amount->shouldReceive('toArray')->andReturn(['amount']); $item1 = Mockery::mock(Item::class); - $item1->expects('toArray')->andReturn(['item1']); + $item1->shouldReceive('toArray')->andReturn(['item1']); $item2 = Mockery::mock(Item::class); - $item2->expects('toArray')->andReturn(['item2']); + $item2->shouldReceive('toArray')->andReturn(['item2']); $shipping = Mockery::mock(Shipping::class); - $shipping->expects('toArray')->andReturn(['shipping']); + $shipping->shouldReceive('toArray')->andReturn(['shipping']); $payee = Mockery::mock(Payee::class); - $payee->expects('toArray')->andReturn(['payee']); + $payee->shouldReceive('toArray')->andReturn(['payee']); $testee = new PurchaseUnit( $amount, [], diff --git a/modules.local/ppcp-api-client/tests/PHPUnit/TestCase.php b/modules.local/ppcp-api-client/tests/PHPUnit/TestCase.php new file mode 100644 index 000000000..636d9b01e --- /dev/null +++ b/modules.local/ppcp-api-client/tests/PHPUnit/TestCase.php @@ -0,0 +1,23 @@ +