-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
390 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,36 @@ jobs: | |
with: | ||
files: ./coverage.xml | ||
|
||
phpunit-application: | ||
runs-on: ubuntu-latest | ||
services: | ||
mariadb: | ||
image: mariadb:10.5 | ||
env: | ||
MARIADB_ROOT_PASSWORD: swagbraintree | ||
MYSQL_DATABASE: swagbraintree_test | ||
ports: [ '3306:3306' ] | ||
env: | ||
DATABASE_URL: mysql://root:[email protected]:3306/swagbraintree | ||
BRAINTREE_TEST_ENVIRONMENT: sandbox | ||
BRAINTREE_TEST_MERCHANT_ID: ${{ secrets.BRAINTREE_TEST_MERCHANT_ID }} | ||
BRAINTREE_TEST_MERCHANT_ACCOUNT_ID: ${{ secrets.BRAINTREE_TEST_MERCHANT_ACCOUNT_ID }} | ||
BRAINTREE_TEST_PUBLIC_KEY: ${{ secrets.BRAINTREE_TEST_PUBLIC_KEY }} | ||
BRAINTREE_TEST_PRIVATE_KEY: ${{ secrets.BRAINTREE_TEST_PRIVATE_KEY }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./.github/actions/setup-php | ||
- name: Setup database | ||
run: composer setup:test | ||
- name: Run PHPUnit | ||
continue-on-error: true | ||
run: composer phpunit:application -- --coverage-clover=coverage.xml | ||
- name: Codecov | ||
if: steps.phpunit-application.outcome == 'success' && steps.phpunit-application.conclusion == 'success' | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
files: ./coverage.xml | ||
|
||
infection: | ||
runs-on: ubuntu-latest | ||
services: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
https://symfony.com/schema/dic/services/services-1.0.xsd" | ||
> | ||
<parameters> | ||
<parameter key="BRAINTREE_TEST_MERCHANT_ACCOUNT_ID">%env(BRAINTREE_TEST_MERCHANT_ACCOUNT_ID)%</parameter> | ||
<parameter key="BRAINTREE_TEST_MERCHANT_ID">%env(BRAINTREE_TEST_MERCHANT_ID)%</parameter> | ||
<parameter key="BRAINTREE_TEST_ENVIRONMENT">%env(BRAINTREE_TEST_ENVIRONMENT)%</parameter> | ||
<parameter key="BRAINTREE_TEST_PUBLIC_KEY">%env(BRAINTREE_TEST_PUBLIC_KEY)%</parameter> | ||
<parameter key="BRAINTREE_TEST_PRIVATE_KEY">%env(BRAINTREE_TEST_PRIVATE_KEY)%</parameter> | ||
</parameters> | ||
|
||
<services> | ||
<service id="Swag\Braintree\Tests\Braintree\Gateway\BraintreeTestGatewayFactory"> | ||
<argument>%env(BRAINTREE_TEST_ENVIRONMENT)%</argument> | ||
<argument>%env(BRAINTREE_TEST_MERCHANT_ID)%</argument> | ||
<argument>%env(BRAINTREE_TEST_PUBLIC_KEY)%</argument> | ||
<argument>%env(BRAINTREE_TEST_PRIVATE_KEY)%</argument> | ||
</service> | ||
|
||
<service id="Braintree\Gateway"> | ||
<factory service="Swag\Braintree\Tests\Braintree\Gateway\BraintreeTestGatewayFactory" method="createBraintreeGateway"/> | ||
</service> | ||
</services> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Swag\Braintree\Tests; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Swag\Braintree\Entity\CurrencyMappingEntity; | ||
use Swag\Braintree\Entity\ShopEntity; | ||
use Swag\Braintree\Repository\ConfigRepository; | ||
use Swag\Braintree\Repository\CurrencyMappingRepository; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
trait ApplicationBootstrapTrait | ||
{ | ||
abstract protected static function getContainer(): ContainerInterface; | ||
|
||
public function registerShop(): ShopEntity | ||
{ | ||
$container = static::getContainer(); | ||
$em = $container->get(EntityManagerInterface::class); | ||
|
||
$shop = new ShopEntity(Ids::get('shop-id'), 'https://platform.dev.localhost', 'this-is-shop-secret'); | ||
$shop->setBraintreeMerchantId($container->getParameter('BRAINTREE_TEST_MERCHANT_ID')); | ||
$shop->setBraintreePublicKey($container->getParameter('BRAINTREE_TEST_PUBLIC_KEY')); | ||
$shop->setBraintreePrivateKey($container->getParameter('BRAINTREE_TEST_PRIVATE_KEY')); | ||
$shop->setShopActive(true); | ||
$shop->setShopApiCredentials('this-is-the-client-id', 'this-is-the-client-secret'); | ||
$shop->setBraintreeSandbox(true); | ||
|
||
$em->persist($shop); | ||
$em->flush(); | ||
|
||
static::getContainer() | ||
->get(ConfigRepository::class) | ||
->upsert([[ | ||
'salesChannelId' => null, | ||
'threeDSecureEnforced' => true, | ||
'shipsFromPostalCode' => '48268', | ||
]], $shop); | ||
|
||
$currencyMapping = new CurrencyMappingEntity(); | ||
$currencyMapping->setCurrencyId('EUR'); | ||
$currencyMapping->setMerchantAccountId($container->getParameter('BRAINTREE_TEST_MERCHANT_ACCOUNT_ID')); | ||
$currencyMapping->setShop($shop); | ||
|
||
static::getContainer() | ||
->get(CurrencyMappingRepository::class) | ||
->upsert([[ | ||
'salesChannelId' => null, | ||
'currencyId' => Ids::get('currency-id'), | ||
'currencyIso' => 'EUR', | ||
'merchantAccountId' => $container->getParameter('BRAINTREE_TEST_MERCHANT_ACCOUNT_ID'), | ||
]], $shop); | ||
|
||
return $shop; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Tests/Braintree/Gateway/BraintreeTestGatewayFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Swag\Braintree\Tests\Braintree\Gateway; | ||
|
||
use Braintree\Configuration; | ||
use Braintree\Gateway; | ||
|
||
class BraintreeTestGatewayFactory | ||
{ | ||
public function __construct( | ||
private readonly string $braintreeEnv, | ||
private readonly string $braintreeMerchantId, | ||
private readonly string $braintreePublicKey, | ||
private readonly string $braintreePrivateKey, | ||
) { | ||
} | ||
|
||
public function createBraintreeGateway(): Gateway | ||
{ | ||
$configuration = new Configuration( | ||
[ | ||
'environment' => $this->braintreeEnv, | ||
'merchantId' => $this->braintreeMerchantId, | ||
'publicKey' => $this->braintreePublicKey, | ||
'privateKey' => $this->braintreePrivateKey, | ||
] | ||
); | ||
|
||
return new Gateway($configuration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -416,4 +416,141 @@ protected static function createOrderWithDiscount(): Order | |
'id' => Ids::get('order-discount-id'), | ||
]); | ||
} | ||
|
||
private function createOrderForApplication(): Order | ||
{ | ||
return new Order([ | ||
'orderNumber' => '10068', | ||
'salesChannelId' => Ids::get('order-sales-channel-id'), | ||
'price' => [ | ||
'netPrice' => 100, | ||
'totalPrice' => 119, | ||
'calculatedTaxes' => [['tax' => 19, 'taxRate' => 19, 'price' => 100]], | ||
'taxRules' => [['taxRate' => 19, 'percentage' => 100]], | ||
'positionPrice' => 119, | ||
'taxStatus' => 'gross', | ||
'rawTotal' => 100, | ||
], | ||
'amountTotal' => 119, | ||
'amountNet' => 100, | ||
'positionPrice' => 100, | ||
'taxStatus' => 'gross', | ||
'shippingTotal' => 0, | ||
'shippingCosts' => [ | ||
'unitPrice' => 0, | ||
'quantity' => 0, | ||
'totalPrice' => 0, | ||
'calculatedTaxes' => [['tax' => 19, 'taxRate' => 19, 'price' => 100]], | ||
'taxRules' => [['taxRate' => 19, 'percentage' => 100]], | ||
], | ||
'orderCustomer' => [ | ||
'email' => '[email protected]', | ||
'orderId' => Ids::get('order-id'), | ||
'firstName' => 'Application', | ||
'lastName' => 'Tester', | ||
'title' => null, | ||
'company' => 'shopware AG', | ||
'customerNumber' => '1337', | ||
'customerId' => Ids::get('order-customer-id'), | ||
'id' => Ids::get('order-order-customer-id'), | ||
], | ||
'currency' => [ | ||
'isoCode' => 'EUR', | ||
'symbol' => '€', | ||
'shortName' => 'EUR', | ||
'name' => 'Euro', | ||
'itemRounding' => ['decimals' => 2, 'interval' => 0.01, 'roundForNet' => true], | ||
'totalRounding' => ['decimals' => 2, 'interval' => 0.01, 'roundForNet' => true], | ||
'id' => Ids::get('currency-id'), | ||
], | ||
'billingAddress' => [ | ||
'firstName' => 'Application', | ||
'lastName' => 'Tester', | ||
'street' => 'Bahnhofstraße 27', | ||
'zipcode' => '10332', | ||
'city' => 'Berlin', | ||
'company' => null, | ||
'title' => null, | ||
'additionalAddressLine1' => null, | ||
'additionalAddressLine2' => null, | ||
'country' => [ | ||
'name' => 'Haiti', | ||
'iso' => 'HT', | ||
'iso3' => 'HTI', | ||
'id' => Ids::get('order-country-id'), | ||
], | ||
'id' => Ids::get('order-billing-address-id'), | ||
], | ||
'deliveries' => [[ | ||
'shippingCosts' => [ | ||
'unitPrice' => 0, | ||
'quantity' => 0, | ||
'totalPrice' => 0, | ||
'calculatedTaxes' => [[ | ||
'tax' => 0, | ||
'taxRate' => 0, | ||
'price' => 0, | ||
]], | ||
], | ||
'shippingOrderAddress' => [ | ||
'firstName' => 'Application', | ||
'lastName' => 'Tester', | ||
'street' => 'Ebbinghoff 10', | ||
'zipcode' => '1234567890', | ||
'city' => 'Schöppingen', | ||
'company' => 'company', | ||
'title' => null, | ||
'additionalAddressLine1' => 'additionalAddressLine1', | ||
'additionalAddressLine2' => null, | ||
'country' => [ | ||
'name' => 'Hungary', | ||
'iso' => 'HU', | ||
'iso3' => 'HUN', | ||
'id' => Ids::get('order-country-id'), | ||
], | ||
'countryState' => [ | ||
'name' => 'countryState', | ||
], | ||
'id' => Ids::get('order-shipping-address-id'), | ||
], | ||
'id' => Ids::get('order-delivery-id'), | ||
]], | ||
'lineItems' => [[ | ||
'quantity' => 1, | ||
'unitPrice' => 100, | ||
'totalPrice' => 100, | ||
'label' => 'Product 1 - Application test', | ||
'description' => 'Product description 1 from application test', | ||
'good' => true, | ||
'type' => 'product', | ||
'referencedId' => 'product-1', | ||
'payload' => [ | ||
'customFields' => [ | ||
OrderInformationService::LINE_ITEM_COMMODITY_CODE_CUSTOM_FIELD => '1234567890', | ||
], | ||
], | ||
'price' => [ | ||
'unitPrice' => 100, | ||
'quantity' => 1, | ||
'totalPrice' => 100, | ||
'calculatedTaxes' => [['tax' => 19, 'taxRate' => 19, 'price' => 100]], | ||
'taxRules' => [['taxRate' => 19, 'percentage' => 100]], | ||
], | ||
'id' => Ids::get('order-line-item-id'), | ||
]], | ||
'transactions' => [[ | ||
'amount' => [ | ||
'unitPrice' => 100, | ||
'quantity' => 1, | ||
'totalPrice' => 100, | ||
'calculatedTaxes' => [['tax' => 19, 'taxRate' => 10, 'price' => 100]], | ||
'taxRules' => [['taxRate' => 19, 'percentage' => 100]], | ||
], | ||
'id' => Ids::get('order-discount-transaction-id'), | ||
]], | ||
'itemRounding' => ['decimals' => 2, 'interval' => 0.01, 'roundForNet' => true], | ||
'totalRounding' => ['decimals' => 2, 'interval' => 0.01, 'roundForNet' => true], | ||
'id' => Ids::get('order-discount-id'), | ||
]); | ||
} | ||
} |
Oops, something went wrong.