Fix phpunit

This commit is contained in:
Emili Castells Guasch 2024-10-18 17:36:54 +02:00
parent 9c5d978707
commit 5e803643cb
3 changed files with 2 additions and 168 deletions

View file

@ -1,18 +1,7 @@
import React from 'react';
import * as ReactDOM from 'react-dom/client';
import { App } from './App';
ReactDOM.createRoot(
document.getElementById( 'ppcp-settings-container' )
).render( <App /> );
/*
import React from 'react';
import { createRoot } from 'react-dom/client';
import { App } from './App';
createRoot( document.getElementById( 'ppcp-settings-container' ) ).render(
<App />
);
*/

View file

@ -1,156 +0,0 @@
<?php
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
use Mockery;
use Psr\Log\LoggerInterface;
use Requests_Utility_CaseInsensitiveDictionary;
use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Token;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
use WooCommerce\PayPalCommerce\TestCase;
use WooCommerce\PayPalCommerce\WcGateway\FraudNet\FraudNet;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PaymentSource;
use function Brain\Monkey\Functions\expect;
use function Brain\Monkey\Functions\when;
class PayUponInvoiceOrderEndpointTest extends TestCase
{
private $bearer;
private $orderFactory;
private $fraudnet;
private $logger;
private $testee;
public function setUp(): void
{
parent::setUp();
$this->bearer = Mockery::mock(Bearer::class);
$token = Mockery::mock(Token::class);
$token->shouldReceive('token')->andReturn('');
$this->bearer->shouldReceive('bearer')->andReturn($token);
$this->orderFactory = Mockery::mock(OrderFactory::class);
$this->fraudnet = Mockery::mock(FraudNet::class);
$this->logger = Mockery::mock(LoggerInterface::class);
$this->testee = new PayUponInvoiceOrderEndpoint(
'',
$this->bearer,
$this->orderFactory,
$this->fraudnet,
$this->logger
);
}
public function testCreateOrder()
{
$this->markTestSkipped('must be revisited.');
list($items, $paymentSource, $headers) = $this->setStubs();
$response = [
'body' => '{"is_correct":true}',
'headers' => $headers,
];
expect('wp_remote_get')->andReturn($response);
expect('wp_remote_retrieve_response_code')->with($response)->andReturn(200);
$this->logger->shouldReceive('debug');
$wc_order = Mockery::mock(WC_Order::class);
$result = $this->testee->create($items, $paymentSource, $wc_order );
$this->assertInstanceOf(Order::class, $result);
}
public function testCreateOrderWpError()
{
$this->markTestSkipped('must be revisited.');
list($items, $paymentSource) = $this->setStubsForError();
$wpError = Mockery::mock(\WP_Error::class);
$wpError->shouldReceive('get_error_messages')->andReturn(['foo']);
$wpError->shouldReceive('get_error_message')->andReturn('foo');
expect('wp_remote_get')->andReturn($wpError);
$this->logger->shouldReceive('debug');
$wc_order = Mockery::mock(WC_Order::class);
$this->expectException(\RuntimeException::class);
$this->testee->create($items, $paymentSource, $wc_order);
}
public function testCreateOrderApiError()
{
$this->markTestSkipped('must be revisited.');
list($items, $paymentSource) = $this->setStubsForError();
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
$headers->shouldReceive('getAll');
$response = [
'body' => '{"is_correct":true}',
'headers' => $headers,
];
when('get_bloginfo')->justReturn('de-DE');
expect('wp_remote_get')->andReturn($response);
expect('wp_remote_retrieve_response_code')->with($response)->andReturn(500);
$this->logger->shouldReceive('debug');
$wc_order = Mockery::mock(WC_Order::class);
$this->expectException(PayPalApiException::class);
$this->testee->create($items, $paymentSource, $wc_order);
}
/**
* @return array
*/
private function setStubs(): array
{
$order = Mockery::mock(Order::class);
$this->orderFactory
->expects('from_paypal_response')
->andReturnUsing(function (\stdClass $object) use ($order): ?Order {
return ($object->is_correct) ? $order : null;
});
$this->fraudnet->shouldReceive('session_id')->andReturn('');
$purchaseUnit = Mockery::mock(PurchaseUnit::class);
$purchaseUnit->shouldReceive('to_array')->andReturn([
'items' => [],
]);
$items = [$purchaseUnit];
$paymentSource = Mockery::mock(PaymentSource::class);
$paymentSource->shouldReceive('to_array')->andReturn([]);
$headers = Mockery::mock(Requests_Utility_CaseInsensitiveDictionary::class);
$headers->shouldReceive('getAll');
return array($items, $paymentSource, $headers);
}
/**
* @return array
*/
private function setStubsForError(): array
{
$this->fraudnet->shouldReceive('session_id')->andReturn('');
$purchaseUnit = Mockery::mock(PurchaseUnit::class);
$purchaseUnit->shouldReceive('to_array')->andReturn([
'items' => [],
]);
$items = [$purchaseUnit];
$paymentSource = Mockery::mock(PaymentSource::class);
$paymentSource->shouldReceive('to_array')->andReturn([]);
return array($items, $paymentSource);
}
}

View file

@ -123,7 +123,8 @@ class WcGatewayTest extends TestCase
'Pay via PayPal',
$this->paymentTokensEndpoint,
$this->vaultV3Enabled,
$this->wcPaymentTokens
$this->wcPaymentTokens,
false
);
}