Update tests

This commit is contained in:
Alex P 2022-02-09 16:28:27 +02:00
parent 10c786fdb9
commit 361d2365fc
31 changed files with 48 additions and 73 deletions

View file

@ -6,9 +6,9 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Authentication;
use Requests_Utility_CaseInsensitiveDictionary;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use Psr\Log\LoggerInterface;
use Mockery;
use WooCommerce\PayPalCommerce\TestCase;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use function Brain\Monkey\Functions\expect;

View file

@ -10,8 +10,8 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Token;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Repository\CustomerRepository;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use Mockery;
use WooCommerce\PayPalCommerce\TestCase;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use function Brain\Monkey\Functions\expect;
use function Brain\Monkey\Functions\when;
@ -89,7 +89,6 @@ class IdentityTokenTest extends TestCase
expect('is_wp_error')->with($rawResponse)->andReturn(false);
expect('wp_remote_retrieve_response_code')->with($rawResponse)->andReturn(200);
when('wc_print_r')->returnArg();
when('get_user_meta')->justReturn('');
$result = $this->sut->generate_for_user(1);
@ -108,7 +107,6 @@ class IdentityTokenTest extends TestCase
$headers->shouldReceive('getAll');
expect('wp_remote_get')->andReturn(['headers' => $headers,]);
expect('is_wp_error')->andReturn(true);
when('wc_print_r')->returnArg();
$this->logger->shouldReceive('log');
$this->logger->shouldReceive('debug');
$this->settings->shouldReceive('has')->andReturn(true);
@ -135,7 +133,6 @@ class IdentityTokenTest extends TestCase
]);
expect('is_wp_error')->andReturn(false);
expect('wp_remote_retrieve_response_code')->andReturn(500);
when('wc_print_r')->returnArg();
$this->logger->shouldReceive('log');
$this->logger->shouldReceive('debug');
$this->settings->shouldReceive('has')->andReturn(true);

View file

@ -24,10 +24,10 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\PatchCollectionFactory;
use WooCommerce\PayPalCommerce\ApiClient\Helper\ErrorResponse;
use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository;
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use Mockery;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
use WooCommerce\PayPalCommerce\TestCase;
use function Brain\Monkey\Functions\expect;
use function Brain\Monkey\Functions\when;
@ -38,7 +38,6 @@ class OrderEndpointTest extends TestCase
public function setUp(): void
{
parent::setUp();
when('wc_print_r')->returnArg();
$this->shipping = new Shipping('shipping', new Address('US', 'street', '', 'CA', '', '12345'));
}

View file

@ -9,8 +9,8 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use Mockery;
use WooCommerce\PayPalCommerce\TestCase;
class OrderTest extends TestCase
{

View file

@ -12,9 +12,9 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentTokenFactory;
use WooCommerce\PayPalCommerce\ApiClient\Repository\CustomerRepository;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use WooCommerce\PayPalCommerce\TestCase;
use function Brain\Monkey\Functions\expect;
class PaymentTokenEndpointTest extends TestCase

View file

@ -13,10 +13,9 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Token;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\AuthorizationFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\CaptureFactory;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use Mockery;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\TestCase;
use function Brain\Monkey\Functions\expect;
class PaymentsEndpointTest extends TestCase

View file

@ -3,7 +3,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
class AddressTest extends TestCase
{

View file

@ -3,7 +3,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
use Mockery;
class AmountBreakdownTest extends TestCase

View file

@ -3,7 +3,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
use Mockery;
class AmountTest extends TestCase

View file

@ -5,7 +5,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
class AuthorizationStatusTest extends TestCase
{

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
class AuthorizationTest extends TestCase
{

View file

@ -3,7 +3,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
use Mockery;
class ItemTest extends TestCase

View file

@ -3,7 +3,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
class MoneyTest extends TestCase
{

View file

@ -3,7 +3,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
use Mockery;
class PayerTest extends TestCase

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
class PaymentsTest extends TestCase
{

View file

@ -3,7 +3,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
use Mockery;
class PurchaseUnitTest extends TestCase

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
use Mockery;
class AddressFactoryTest extends TestCase

View file

@ -6,7 +6,7 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Item;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
use Mockery;
use function Brain\Monkey\Functions\expect;
use function Brain\Monkey\Functions\when;

View file

@ -7,7 +7,7 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
use WooCommerce\PayPalCommerce\ApiClient\Entity\AuthorizationStatus;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
class AuthorizationFactoryTest extends TestCase
{

View file

@ -5,7 +5,7 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Item;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
use function Brain\Monkey\Functions\expect;
use function Brain\Monkey\Functions\when;
use Mockery;

View file

@ -10,7 +10,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentSource;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
use Mockery;
class OrderFactoryTest extends TestCase

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Address;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
use Mockery;
class PayerFactoryTest extends TestCase

View file

@ -7,7 +7,7 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payments;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
use Mockery;
class PaymentsFactoryTest extends TestCase

View file

@ -11,7 +11,7 @@ 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\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\TestCase;
use Mockery;
use function Brain\Monkey\Functions\expect;

View file

@ -3,8 +3,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Repository;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use WooCommerce\PayPalCommerce\Button\Assets\SmartButton;
use WooCommerce\PayPalCommerce\TestCase;
use function Brain\Monkey\Functions\when;
class ApplicationContextRepositoryTest extends TestCase

View file

@ -3,9 +3,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Repository;
use WooCommerce\PayPalCommerce\ApiClient\Config\Config;
use WooCommerce\PayPalCommerce\ApiClient\TestCase;
use Mockery;
use WooCommerce\PayPalCommerce\TestCase;
class PayeeRepositoryTest extends TestCase
{

View file

@ -1,28 +0,0 @@
<?php
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient;
use function Brain\Monkey\setUp;
use function Brain\Monkey\tearDown;
use function Brain\Monkey\Functions\expect;
use Mockery;
class TestCase extends \PHPUnit\Framework\TestCase
{
public function setUp(): void
{
parent::setUp();
expect('__')->andReturnUsing(function (string $text) {
return $text;
});
setUp();
}
public function tearDown(): void
{
tearDown();
Mockery::close();
parent::tearDown();
}
}

View file

@ -36,7 +36,6 @@ class ThreeDSecureTest extends TestCase
$order->shouldReceive('payment_source')->andReturn($source);
$logger = \Mockery::mock(LoggerInterface::class);
$logger->shouldReceive('info');
when('wc_print_r')->justReturn();
$testee = new ThreeDSecure($logger);
$result = $testee->proceed_with_order($order);

View file

@ -25,6 +25,9 @@ class TestCase extends \PHPUnit\Framework\TestCase
when('sanitize_text_field')->returnArg();
when('wp_kses_post')->returnArg();
when('wp_unslash')->returnArg();
when('wc_print_r')->alias(function ($value, bool $return = false) {
return print_r($value, $return);
});
setUp();
}

View file

@ -12,6 +12,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
use WooCommerce\PayPalCommerce\ApiClient\Entity\AuthorizationStatus;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
use WooCommerce\PayPalCommerce\ApiClient\Entity\CaptureStatus;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payments;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
@ -26,6 +27,8 @@ class AuthorizedPaymentsProcessorTest extends TestCase
private $wcOrder;
private $paypalOrderId = 'abc';
private $authorizationId = 'qwe';
private $amount = 42.0;
private $currency = 'EUR';
private $paypalOrder;
private $orderEndpoint;
private $paymentsEndpoint;
@ -64,13 +67,13 @@ class AuthorizedPaymentsProcessorTest extends TestCase
public function testSuccess() {
$this->paymentsEndpoint
->expects('capture')
->with($this->authorizationId)
->with($this->authorizationId, equalTo(new Money($this->amount, $this->currency)))
->andReturn($this->createCapture(CaptureStatus::COMPLETED));
$this->assertEquals(AuthorizedPaymentsProcessor::SUCCESSFUL, $this->testee->process($this->wcOrder));
}
public function testCapturesAllCaptureable() {
public function testCapturesLastCaptureable() {
$authorizations = [
$this->createAuthorization('id1', AuthorizationStatus::CREATED),
$this->createAuthorization('id2', AuthorizationStatus::VOIDED),
@ -82,12 +85,10 @@ class AuthorizedPaymentsProcessorTest extends TestCase
];
$this->paypalOrder = $this->createPaypalOrder($authorizations);
foreach ([$authorizations[0], $authorizations[2]] as $authorization) {
$this->paymentsEndpoint
->expects('capture')
->with($authorization->id())
->andReturn($this->createCapture(CaptureStatus::COMPLETED));
}
$this->paymentsEndpoint
->expects('capture')
->with($authorizations[2]->id(), equalTo(new Money($this->amount, $this->currency)))
->andReturn($this->createCapture(CaptureStatus::COMPLETED));
$this->assertEquals(AuthorizedPaymentsProcessor::SUCCESSFUL, $this->testee->process($this->wcOrder));
}
@ -113,7 +114,7 @@ class AuthorizedPaymentsProcessorTest extends TestCase
public function testCaptureFails() {
$this->paymentsEndpoint
->expects('capture')
->with($this->authorizationId)
->with($this->authorizationId, equalTo(new Money($this->amount, $this->currency)))
->andThrow(RuntimeException::class);
$this->assertEquals(AuthorizedPaymentsProcessor::FAILED, $this->testee->process($this->wcOrder));
@ -137,7 +138,7 @@ class AuthorizedPaymentsProcessorTest extends TestCase
$this->paymentsEndpoint
->expects('capture')
->with($this->authorizationId)
->with($this->authorizationId, equalTo(new Money($this->amount, $this->currency)))
->andReturn($this->createCapture(CaptureStatus::COMPLETED));
$this->wcOrder->shouldReceive('payment_complete')->andReturn(true);
@ -172,6 +173,12 @@ class AuthorizedPaymentsProcessorTest extends TestCase
->shouldReceive('get_meta')
->with(PayPalGateway::ORDER_ID_META_KEY)
->andReturn($paypalOrderId);
$wcOrder
->shouldReceive('get_total')
->andReturn($this->amount);
$wcOrder
->shouldReceive('get_currency')
->andReturn($this->currency);
return $wcOrder;
}

View file

@ -8,3 +8,5 @@ require_once ROOT_DIR . '/vendor/autoload.php';
require_once TESTS_ROOT_DIR . '/stubs/WC_Payment_Gateway.php';
require_once TESTS_ROOT_DIR . '/stubs/WC_Payment_Gateway_CC.php';
require_once TESTS_ROOT_DIR . '/stubs/WC_Ajax.php';
Hamcrest\Util::registerGlobalFunctions();