introduce TestCase

This commit is contained in:
David Remer 2020-04-14 09:58:01 +03:00
parent c7aa53a8e4
commit 8d11d75dd0
10 changed files with 75 additions and 49 deletions

View file

@ -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"
}
}

View file

@ -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
{

View file

@ -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 = [

View file

@ -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());

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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,
[],

View file

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\ApiClient;
use function Brain\Monkey\setUp;
use function Brain\Monkey\tearDown;
class TestCase extends \PHPUnit\Framework\TestCase
{
public function setUp(): void
{
parent::setUp();
setUp();
}
public function tearDown(): void
{
tearDown();
\Mockery::close();
parent::tearDown();
}
}