1
0
Files
PayPal-PHP-Server-SDK/tests/UnitTests/OrdersControllerTest.php
2024-09-06 15:38:17 +05:00

210 lines
6.5 KiB
PHP

<?php
declare(strict_types=1);
/*
* PayPalRESTAPIsLib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
namespace PayPalRESTAPIsLib\Tests\UnitTests;
use PayPalRESTAPIsLib\Controllers\OrdersController;
use PayPalRESTAPIsLib\Models\Builders\ConfirmOrderRequestBuilder;
use PayPalRESTAPIsLib\Models\Builders\OrderRequestBuilder;
use PayPalRESTAPIsLib\Models\Builders\OrderTrackerRequestBuilder;
use PayPalRESTAPIsLib\Models\Builders\PatchBuilder;
use PayPalRESTAPIsLib\Models\Builders\PaymentSourceBuilder;
use PayPalRESTAPIsLib\Models\CheckoutPaymentIntent;
use PayPalRESTAPIsLib\Models\PatchOp;
use PayPalRESTAPIsLib\Tests\Controllers\BaseTestController;
class OrdersControllerTest extends BaseTestController
{
/**
* @var OrdersController OrdersController instance
*/
protected static $controller;
private const NON_EXISTENT_ORDER_ID = 'id-4';
private const NON_EXISTENT_TRACKER_ID = '5UA89551P20376023-443844607820';
private const ALREADY_CAPTURED_ID = '123';
/**
* Setup test class
*/
public static function setUpBeforeClass(): void
{
self::$controller = parent::getClient()->getOrdersController();
}
public function testOrdersCreateWithStatus400()
{
// Parameters for the API call
$request = [
'body' => OrderRequestBuilder::init(
CheckoutPaymentIntent::CAPTURE,
[]
)->build(),
'payPalRequestId' => 'PayPal-Request-Id',
'payPalPartnerAttributionId' => 'PayPal-Partner-Attribution-Id2',
'payPalClientMetadataId' => 'PayPal-Client-Metadata-Id',
'prefer' => 'return=minimal'
];
// Perform API call
$result = self::$controller->ordersCreate($request);
$headers = [];
$headers['Content-Type'] = ['application/json', true];
// Assert result with expected response
$this->assertTrue($result->isError());
$this->newTestCase($result->getResult())
->expectStatus(400)
->allowExtraHeaders()
->expectHeaders($headers)
->assert();
}
public function testOrdersPatchWithStatus400()
{
// Parameters for the API call
$request = [
'body' => PatchBuilder::init(
PatchOp::ADD
)->build(),
'id' => self::NON_EXISTENT_ORDER_ID,
];
// Perform API call
$result = self::$controller->ordersPatch($request);
$headers = [];
$headers['Content-Type'] = ['application/json', true];
// Assert result with expected response
$this->assertTrue($result->isError());
$this->newTestCase($result->getResult())
->expectStatus(400)
->allowExtraHeaders()
->expectHeaders($headers)
->assert();
}
public function testOrdersGetWithStatus204()
{
// Parameters for the API call
$request = [
'id' => self::NON_EXISTENT_ORDER_ID
];
// Perform API call
$result = self::$controller->ordersPatch($request);
// Assert result with expected response
$this->assertTrue($result->isSuccess());
$this->newTestCase($result->getResult())
->expectStatus(204)
->assert();
}
public function testOrdersConfirmWithStatus404()
{
// Parameters for the API call
$request = [
'body' => ConfirmOrderRequestBuilder::init(
PaymentSourceBuilder::init()->build()
)->build(),
'id' => self::NON_EXISTENT_ORDER_ID,
'prefer' => 'return=minimal'
];
// Perform API call
$result = self::$controller->ordersConfirm($request);
$headers = [];
$headers['Content-Type'] = ['application/json', true];
// Assert result with expected response
$this->assertTrue($result->isError());
$this->newTestCase($result->getResult())
->expectStatus(404)
->allowExtraHeaders()
->expectHeaders($headers)
->assert();
}
public function testOrdersAuthorizeWithStatus404()
{
// Parameters for the API call
$request = [
'id' => self::NON_EXISTENT_ORDER_ID,
'prefer' => 'return=minimal'
];
// Perform API call
$result = self::$controller->ordersAuthorize($request);
$headers = [];
$headers['Content-Type'] = ['application/json', true];
// Assert result with expected response
$this->assertTrue($result->isError());
$this->newTestCase($result->getResult())
->expectStatus(404)
->allowExtraHeaders()
->expectHeaders($headers)
->assert();
}
public function testOrdersTrackCreateWithStatus404()
{
// Parameters for the API call
$request = [
'id' => self::NON_EXISTENT_ORDER_ID,
'body' => OrderTrackerRequestBuilder::init(
self::ALREADY_CAPTURED_ID
)->notifyPayer(false)->build(),
];
// Perform API call
$result = self::$controller->ordersTrackCreate($request);
$headers = [];
$headers['Content-Type'] = ['application/json', true];
// Assert result with expected response
$this->assertTrue($result->isError());
$this->newTestCase($result->getResult())
->expectStatus(400)
->allowExtraHeaders()
->expectHeaders($headers)
->assert();
}
public function testOrdersTrackersPatchWithStatus404()
{
// Parameters for the API call
$request = [
'id' => self::NON_EXISTENT_ORDER_ID,
'trackerId' => self::NON_EXISTENT_TRACKER_ID,
'body' => [
PatchBuilder::init(
PatchOp::REPLACE
)
->path('/notify_payer')
->value(true)
->build()
]
];
// Perform API call
$result = self::$controller->ordersTrackersPatch($request);
$headers = [];
$headers['Content-Type'] = ['application/json', true];
// Assert result with expected response
$this->assertTrue($result->isError());
$this->newTestCase($result->getResult())
->expectStatus(404)
->allowExtraHeaders()
->expectHeaders($headers)
->assert();
}
}