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

🚧 Add contract tests for Tpay API #30

Closed
34 changes: 18 additions & 16 deletions .github/workflows/_matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@
"ci": {
"include": [
{
"php": "8.0",
"sylius": "1.12.*",
"symfony": "5.4.*",
"php": "8.1",
"sylius": "1.12.x",
"symfony": "5.4.x",
"mysql": "8.0",
"state_machine": "winzou_state_machine"
},
{
"php": "8.3",
"sylius": "1.13.*",
"symfony": "6.4.*",
"sylius": "1.13.x",
"symfony": "6.4.x",
"mysql": "8.0",
"state_machine": "symfony_workflow"
}
]
},
"daily": {
"php": ["8.0", "8.3"],
"sylius": ["1.12.*", "1.13.*"],
"symfony": ["5.4.*", "6.4.*"],
"mysql": ["8.0"],
"state_machine": ["winzou_state_machine", "symfony_workflow"],
"exclude": [
{
"sylius": "1.12.*",
"state_machine": "symfony_workflow"
}
]
"ci": {
"php": ["8.1", "8.3"],
"sylius": ["1.12.x", "1.13.x"],
"symfony": ["5.4.x", "6.4.x"],
"mysql": ["8.0"],
"state_machine": ["winzou_state_machine", "symfony_workflow"],
"exclude": [
{
"sylius": "1.12.x",
"state_machine": "symfony_workflow"
}
]
}
}
}
}
43 changes: 39 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,29 @@ jobs:
APP_ENV: test
DATABASE_URL: "mysql://root:[email protected]/sylius?serverVersion=${{ matrix.mysql }}"
STATE_MACHINE_DEFAULT_ADAPTER: ${{ matrix.state_machine }}
PANTHER_WEB_SERVER_DIR: './tests/Application/public'
PANTHER_NO_SANDBOX: 1
PANTHER_CHROME_ARGUMENTS: '--disable-dev-shm-usage --window-size=1400,900'
TPAY_API_URL: 'http://localhost:4000'
TPAY_CLIENT_ID: '${{ secrets.TPAY_CLIENT_ID }}'
TPAY_CLIENT_SECRET: '${{ secrets.TPAY_CLIENT_SECRET }}'
TPAY_CARDS_API: '${{ secrets.TPAY_CARDS_API }}'
PAYUM_CYPHER_KEY: '${{ secrets.PAYUM_CYPHER_KEY }}'

steps:
-
uses: actions/checkout@v3

-
name: Run Mockoon CLI
uses: mockoon/cli-action@v2
with:
version: "latest"
data-file: "./tests/mockoon_tpay.json"
port: 4000

- name: Build application
uses: SyliusLabs/[email protected]
uses: SyliusLabs/BuildTestAppAction@v2.2.1
with:
build_type: "plugin"
cache_key: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-sylius-${{ matrix.sylius }}-symfony-${{ matrix.symfony }}"
Expand All @@ -57,7 +73,9 @@ jobs:
php_version: ${{ matrix.php }}
symfony_version: ${{ matrix.symfony }}
sylius_version: ${{ matrix.sylius }}
e2e_js: true
e2e: "yes"
e2e_js: "yes"
node_version: '18.x'

- name: Check dependencies
continue-on-error: true
Expand All @@ -69,5 +87,22 @@ jobs:
- name: Check coding standard
run: vendor/bin/ecs check

- name: Run tests
run: vendor/bin/phpunit
- name: Run tests (Unit)
run: vendor/bin/phpunit --testsuite unit

- name: Run tests (E2E)
run: vendor/bin/phpunit --testsuite e2e

- name: Run Tpay contract tests
if: "${{ inputs.type == 'daily' }}"
run: vendor/bin/phpunit --testsuite contract_external

- name: Upload logs
uses: actions/upload-artifact@v3
if: failure()
with:
name: "Logs for (Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}, State Machine ${{ matrix.state_machine }})"
path: |
tests/Application/var/log
tests/Application/var/panther
if-no-files-found: ignore
1 change: 1 addition & 0 deletions .github/workflows/ci__daily.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ jobs:
uses: ./.github/workflows/ci.yaml
with:
type: "daily"
secrets: inherit
1 change: 1 addition & 0 deletions .github/workflows/ci__pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ jobs:
uses: ./.github/workflows/ci.yaml
with:
type: "pr"
secrets: inherit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/drivers/
/public/bundles/
/var/
/vendor/
Expand Down
27 changes: 27 additions & 0 deletions assets/shop/js/card_encoder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
import * as JSEncrypt from './jsencrypt.min';
import * as Sentry from "@sentry/browser";

Sentry.init({
dsn: "https://b4aeb8f84d49fdbae7d336d446bf46b6@o4507962673725440.ingest.de.sentry.io/4507962677395536",

// Alternatively, use `process.env.npm_package_version` for a dynamic release version
// if your build tool supports it.
release: "[email protected]",
integrations: [
Sentry.browserTracingIntegration(),
Sentry.replayIntegration(),
Sentry.captureConsoleIntegration(),
],

// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,

// Set `tracePropagationTargets` to control for which URLs trace propagation should be enabled
tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/],

// Capture Replay for 10% of all sessions,
// plus for 100% of sessions with an error
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
});

document.addEventListener('DOMContentLoaded', () => {
const form = document.querySelector('[name="sylius_checkout_complete"]');
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"require": {
"php": "^8.0",
"php": "^8.1",
"sylius/core-bundle": "^1.12",
"tpay-com/tpay-openapi-php": "^1.8",
"payum/core": "^1.7",
Expand All @@ -31,6 +31,8 @@
"sylius/sylius": "<1.12"
},
"require-dev": {
"coduo/php-matcher": "^6.0",
"dbrekelmans/bdi": "^1.3",
"phpspec/prophecy-phpunit": "^2.2",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^1.8.1",
Expand All @@ -48,7 +50,9 @@
"symfony/flex": "^2.4",
"symfony/intl": "^5.4 || ^6.0",
"symfony/monolog-bundle": "^3.10",
"symfony/web-profiler-bundle": "^5.4 || ^6.0"
"symfony/panther": "^2.1",
"symfony/web-profiler-bundle": "^5.4 || ^6.0",
"theofidry/alice-data-fixtures": "^1.6"
},
"config": {
"sort-packages": true,
Expand Down
2 changes: 1 addition & 1 deletion config/services/payum/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
return function(ContainerConfigurator $container): void {
$services = $container->services();

$services->set(TpayGatewayFactory::class, GatewayFactoryBuilder::class)
$services->set('commerce_weavers_sylius_tpay.payum.factory.tpay_gateway', GatewayFactoryBuilder::class)
->args([
TpayGatewayFactory::class,
])
Expand Down
21 changes: 21 additions & 0 deletions config/services_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\TpayGatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\Test\Payum\Factory\TestTpayGatewayFactory;
use Payum\Core\Bridge\Symfony\Builder\GatewayFactoryBuilder;

return function(ContainerConfigurator $container): void {
$container->import('services/**/*.php');

$services = $container->services();
$services->set('commerce_weavers_sylius_tpay.payum.factory.tpay_gateway', GatewayFactoryBuilder::class)
->args([
TestTpayGatewayFactory::class,
])
->tag('payum.gateway_factory_builder', ['factory' => TpayGatewayFactory::NAME])
;
};
15 changes: 15 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
<testsuites>
<testsuite name="default">
<directory>tests</directory>
<exclude>tests/Contract/Tpay</exclude>
</testsuite>
<testsuite name="unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="e2e">
<directory>tests/E2E</directory>
</testsuite>
<testsuite name="contract_external">
<directory>tests/Contract/Tpay</directory>
</testsuite>
</testsuites>

Expand All @@ -15,8 +25,13 @@

<server name="KERNEL_CLASS_PATH" value="/tests/Application/src/Kernel.php" />
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />
<server name="PANTHER_ERROR_SCREENSHOT_DIR" value="tests/Application/var/panther" />

<env name="APP_ENV" value="test"/>
<env name="SHELL_VERBOSITY" value="-1" />
</php>

<extensions>
<extension class="Symfony\Component\Panther\ServerExtension" />
</extensions>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public function load(array $configs, ContainerBuilder $container): void
$loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../../config'));

$loader->load('services.php');

/** @var string $environment */
$environment = $container->getParameter('kernel.environment');

if (str_starts_with($environment, 'test')) {
$loader->load('services_test.php');
}
}

public function prepend(ContainerBuilder $container): void
Expand Down
37 changes: 37 additions & 0 deletions src/Test/Payum/Factory/TestTpayGatewayFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace CommerceWeavers\SyliusTpayPlugin\Test\Payum\Factory;

use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\GatewayFactory;
use Tpay\OpenApi\Api\TpayApi;

class TestTpayGatewayFactory extends GatewayFactory
{
public const NAME = 'tpay';

protected function populateConfig(ArrayObject $config): void
{
$config->defaults([
'payum.factory_name' => self::NAME,
'payum.factory_title' => ucfirst(self::NAME),
]);

$config['payum.api'] = function (ArrayObject $config): TpayApi {
/** @var array{client_id?: string, client_secret?: string, production_mode?: bool} $config */
$clientId = $config['client_id'] ?? null;
$clientSecret = $config['client_secret'] ?? null;
$productionMode = $config['production_mode'] ?? false;
/** @var string $testApiUrl */
$testApiUrl = getenv('TPAY_API_URL');

if (null === $clientId || null === $clientSecret) {
throw new \InvalidArgumentException('Tpay ClientId and ClientSecret are required.');
}

return new TpayApi($clientId, $clientSecret, $productionMode, apiUrlOverride: $testApiUrl);
};
}
}
30 changes: 30 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@
"ref": "d1227d002b70d1a1f941d91845fcd7ac7fbfc929"
}
},
"nelmio/alice": {
"version": "3.12",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.3",
"ref": "42b52d2065dc3fde27912d502c18ca1926e35ae2"
},
"files": [
"config/packages/nelmio_alice.yaml"
]
},
"nyholm/psr7": {
"version": "1.8",
"recipe": {
Expand Down Expand Up @@ -335,6 +347,15 @@
"config/packages/monolog.yaml"
]
},
"symfony/panther": {
"version": "2.1",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.0",
"ref": "673836afb0eac2b0ec36c44f2ff0379e5a4b2177"
}
},
"symfony/routing": {
"version": "5.4",
"recipe": {
Expand Down Expand Up @@ -442,6 +463,15 @@
"config/packages/workflow.yaml"
]
},
"theofidry/alice-data-fixtures": {
"version": "1.7",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.0",
"ref": "fe5a50faf580eb58f08ada2abe8afbd2d4941e05"
}
},
"willdurand/hateoas-bundle": {
"version": "2.6",
"recipe": {
Expand Down
2 changes: 2 additions & 0 deletions tests/Application/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ SYLIUS_MESSENGER_TRANSPORT_MAIN_FAILED_DSN=sync://
SYLIUS_MESSENGER_TRANSPORT_CATALOG_PROMOTION_REMOVAL_DSN=sync://
SYLIUS_MESSENGER_TRANSPORT_CATALOG_PROMOTION_REMOVAL_FAILED_DSN=sync://
###< symfony/messenger ###

TPAY_CARDS_API=LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0NCk1JR2ZNQTBHQ1NxR1NJYjNEUUVCQVFVQUE0R05BRENCaVFLQmdRQ3ZQc2lCOWZuR0FMd1ZKSnpaM2tOdEw1MVcNCjRGcm1zOXcyWS9vRTY0VmRNM1NFaC83d1orRWZCWlltYUdtcEJkelpOTzZXMDhxd0NkT0Jwa3YxR2k5UnlKQTANCkRsMk5oSURlbnRSSWd2VXR5UllJdVZza3BrcDh3M1pmYTh2akJWdlJYZTRHUERjeEMvVXc4S29heU5oVlhKZnENCnlJZHhEYTRMRHdjRWtJWlE1UUlEQVFBQg0KLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0t
2 changes: 2 additions & 0 deletions tests/Application/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
League\FlysystemBundle\FlysystemBundle::class => ['all' => true],
Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['all' => true],
Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['all' => true],
];

if (SyliusCoreBundle::VERSION_ID >= 11300) {
Expand Down
3 changes: 3 additions & 0 deletions tests/Application/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
},
"devDependencies": {
"@sylius-ui/frontend": "^1.0"
},
"dependencies": {
"@sentry/browser": "^8.30.0"
}
}
Loading
Loading