Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repo initialized with test cases #2

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .codegenignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests/E2E/**
tests/UnitTests/**
tests/ClientFactory.php
tests/WebDriverUtilities.php
tests/bootstrap.php
tests/Controllers/BaseTestController.php
.gitignore
.github/**
phpunit.xml
selenium.jar
46 changes: 46 additions & 0 deletions .github/workflows/test-runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Tests

on:
workflow_dispatch:

jobs:
test:
name: Running all tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'

- name: Install dependencies
run: |
composer install
composer require php-webdriver/webdriver --dev
composer require phpunit/phpunit --dev

- name: Run Lint Tests
run: composer lint

- name: Run Analyzer Tests
run: composer analyze

- name: Set up Java 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: Run Selenium Server
run: java -jar selenium.jar standalone &

- name: Run tests
run: ./vendor/bin/phpunit --testdox
env:
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
EMAIL: ${{ secrets.EMAIL }}
PASSWORD: ${{ secrets.PASSWORD }}
16 changes: 16 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="tests/bootstrap.php" colors="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="SDK Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
</php>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
Binary file added selenium.jar
Binary file not shown.
File renamed without changes.
58 changes: 58 additions & 0 deletions tests/ClientFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

/*
* PaypalServerSDKLib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/

namespace PaypalServerSDKLib\Tests;

use Core\Types\CallbackCatcher;
use PaypalServerSDKLib\Authentication\ClientCredentialsAuthCredentialsBuilder;
use PaypalServerSDKLib\Environment;
use PaypalServerSDKLib\PaypalServerSDKClient;
use PaypalServerSDKLib\PaypalServerSDKClientBuilder;

class ClientFactory
{
public static function create(CallbackCatcher $httpCallback): PaypalServerSDKClient
{
$clientBuilder = PaypalServerSDKClientBuilder::init();
$clientBuilder = self::addConfigurationFromEnvironment($clientBuilder);
$clientBuilder = self::addTestConfiguration($clientBuilder);
return $clientBuilder->httpCallback($httpCallback)->build();
}

public static function addTestConfiguration(PaypalServerSDKClientBuilder $builder): PaypalServerSDKClientBuilder
{
return $builder;
}

public static function addConfigurationFromEnvironment(
PaypalServerSDKClientBuilder $builder
): PaypalServerSDKClientBuilder {
$timeout = '10000';
$environment = Environment::SANDBOX;
$oAuthClientId = getenv('CLIENT_ID');
$oAuthClientSecret = getenv('CLIENT_SECRET');

if (!empty($timeout) && \is_numeric($timeout)) {
$builder->timeout(intval($timeout));
}

if (!empty($environment)) {
$builder->environment($environment);
}

if (!empty($oAuthClientId) && !empty($oAuthClientSecret)) {
$builder->clientCredentialsAuthCredentials(
ClientCredentialsAuthCredentialsBuilder::init($oAuthClientId, $oAuthClientSecret)
);
}

return $builder;
}
}
36 changes: 36 additions & 0 deletions tests/Controllers/BaseTestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

/*
* PaypalServerSDKLib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/

namespace PaypalServerSDKLib\Tests\Controllers;

use Core\TestCase\CoreTestCase;
use Core\Types\CallbackCatcher;
use PaypalServerSDKLib\PaypalServerSDKClient;
use PaypalServerSDKLib\Tests\ClientFactory;
use PHPUnit\Framework\TestCase;

class BaseTestController extends TestCase
{
/**
* @var CallbackCatcher Callback
*/
protected static $callbackCatcher;

protected function newTestCase($result): CoreTestCase
{
return new CoreTestCase($this, self::$callbackCatcher, $result);
}

protected static function getClient(): PaypalServerSDKClient
{
self::$callbackCatcher = new CallbackCatcher();
return ClientFactory::create(self::$callbackCatcher);
}
}
203 changes: 203 additions & 0 deletions tests/E2E/AddShippingTrackerInformationToOrderFlowTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
<?php

declare(strict_types=1);

/*
* PaypalServerSDKLib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/

namespace PaypalServerSDKLib\Tests\E2E;

use Exception;
use PaypalServerSDKLib\Controllers\OrdersController;
use PaypalServerSDKLib\Models\Builders\AmountWithBreakdownBuilder;
use PaypalServerSDKLib\Models\Builders\OrderRequestBuilder;
use PaypalServerSDKLib\Models\Builders\OrderTrackerItemBuilder;
use PaypalServerSDKLib\Models\Builders\OrderTrackerRequestBuilder;
use PaypalServerSDKLib\Models\Builders\PatchBuilder;
use PaypalServerSDKLib\Models\Builders\PaymentSourceBuilder;
use PaypalServerSDKLib\Models\Builders\PayPalWalletBuilder;
use PaypalServerSDKLib\Models\Builders\PayPalWalletExperienceContextBuilder;
use PaypalServerSDKLib\Models\Builders\PurchaseUnitRequestBuilder;
use PaypalServerSDKLib\Models\Builders\UniversalProductCodeBuilder;
use PaypalServerSDKLib\Models\CheckoutPaymentIntent;
use PaypalServerSDKLib\Models\Order;
use PaypalServerSDKLib\Models\PatchOp;
use PaypalServerSDKLib\Models\PayPalExperienceLandingPage;
use PaypalServerSDKLib\Models\ShipmentCarrier;
use PaypalServerSDKLib\Models\UPCType;
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;
use PaypalServerSDKLib\Tests\WebDriverUtilities;

class AddShippingTrackerInformationToOrderFlowTest extends BaseTestController
{
/**
* @var OrdersController OrdersController instance
*/
protected static $ordersController;

/**
* Setup test class
*/
public static function setUpBeforeClass(): void
{
$client = parent::getClient();
self::$ordersController = $client->getOrdersController();
}

public function testCreateOrder(): Order
{
$request = [
'body' => OrderRequestBuilder::init(
CheckoutPaymentIntent::CAPTURE,
[
PurchaseUnitRequestBuilder::init(
AmountWithBreakdownBuilder::init(
'USD',
'100.00'
)->build()
)
->referenceId('d9f80740-38f0-11e8-b467-0ed5f89f718b')
->build()
]
)
->paymentSource(
PaymentSourceBuilder::init()
->paypal(
PayPalWalletBuilder::init()
->experienceContext(
PayPalWalletExperienceContextBuilder::init()
->locale('en-US')
->returnUrl('https://example.com/returnUrl')
->cancelUrl('https://example.com/cancelUrl')
->landingPage(PayPalExperienceLandingPage::LOGIN)
->build()
)
->build()
)
->build()
)
->build()
];

$response = self::$ordersController->ordersCreate($request);

$this->assertTrue($response->isSuccess());
$this->assertEquals(200, $response->getStatusCode());

return $response->getResult();
}

/**
* @depends testCreateOrder
* @throws Exception
*/
public function testCompletePayment(Order $orderDetail): void
{
$links = $orderDetail->getLinks();
$url = null;
if (isset($links)) {
$url = $links[1]->getHref();
}
$this->assertNotNull($url);
WebDriverUtilities::completePayment($url ?? '');
}

/**
* @depends testCreateOrder
* @depends testCompletePayment
*/
public function testCaptureOrder(Order $orderDetail): Order
{
$request = [
'id' => $orderDetail->getId(),
'payPalRequestId' => strval(rand(1, 99999999999)),
'prefer' => 'return=representation'
];

$response = self::$ordersController->ordersCapture($request);

$this->assertTrue($response->isSuccess());
$this->assertEquals(201, $response->getStatusCode());

return $response->getResult();
}

/**
* @depends testCaptureOrder
*/
public function testCreateOrderTrack(Order $captureDetail): Order
{
$purchaseUnits = $captureDetail->getPurchaseUnits();
$captureId = null;
if (isset($purchaseUnits)) {
$captures = $purchaseUnits[0]->getPayments()->getCaptures();
if (isset($captures)) {
$captureId = $captures[0]->getId();
}
}
$this->assertNotNull($captureId);
$request = [
'id' => $captureDetail->getId(),
'body' => OrderTrackerRequestBuilder::init($captureId ?? '')
->trackingNumber('443844607820')
->carrier(ShipmentCarrier::FEDEX)
->notifyPayer(false)
->items(
[
OrderTrackerItemBuilder::init()
->name('T-Shirt')
->quantity('1')
->sku('sku02')
->url('https://www.example.com/example')
->imageUrl('https://www.example.com/example.jpg')
->upc(UniversalProductCodeBuilder::init(UPCType::UPCA, 'upc001')->build())
->build()
]
)
->build(),
];

$response = self::$ordersController->ordersTrackCreate($request);

$this->assertTrue($response->isSuccess());
$this->assertEquals(201, $response->getStatusCode());

return $response->getResult();
}

/**
* @depends testCreateOrderTrack
*/
public function testUpdateOrderTrack(Order $shippingOrder): void
{
$purchaseUnits = $shippingOrder->getPurchaseUnits();
$trackerId = null;
if (isset($purchaseUnits)) {
$trackers = $purchaseUnits[0]->getShipping()->getTrackers();
if (isset($trackers)) {
$trackerId = $trackers[0]->getId();
}
}
$this->assertNotNull($trackerId);
$request = [
'id' => $shippingOrder->getId(),
'trackerId' => $trackerId ?? '',
'body' => [
PatchBuilder::init(
PatchOp::REPLACE
)
->path('/notify_payer')
->value(true)
->build()
]
];

$response = self::$ordersController->ordersTrackersPatch($request);

$this->assertTrue($response->isSuccess());
$this->assertEquals(204, $response->getStatusCode());
}
}
Loading