Skip to content

Commit

Permalink
unit-testing: reduce creating entities to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
rommelfreddy committed Apr 18, 2024
1 parent 2929345 commit ec9e9d6
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testItReturnsDefaultCalculatorData(): void

$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
$installmentService = $this->getInstallmentService();
$this->fillCart($salesChannelContext->getToken(), 100);
$this->fillCart($salesChannelContext, 100);

$calculatorData = $installmentService->getInstallmentCalculatorData($salesChannelContext);

Expand Down Expand Up @@ -69,7 +69,7 @@ public function testItReturnsCalculatorDataByTime(): void

$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
$installmentService = $this->getInstallmentService();
$this->fillCart($salesChannelContext->getToken(), 100);
$this->fillCart($salesChannelContext, 100);

$dataBag = new RequestDataBag([
'ratepayInstallmentType' => CalculationRequestParameterBuilder::INSTALLMENT_TYPE_TIME,
Expand Down Expand Up @@ -106,7 +106,7 @@ public function testItReturnsCalculatorDataByRate(): void

$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
$installmentService = $this->getInstallmentService();
$this->fillCart($salesChannelContext->getToken(), 100);
$this->fillCart($salesChannelContext, 100);

$dataBag = new RequestDataBag([
'ratepayInstallmentType' => CalculationRequestParameterBuilder::INSTALLMENT_TYPE_RATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testItReturnsInstallmentOptions(): void
$installmentService = $this->getInstallmentService($client);

$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
$this->fillCart($salesChannelContext->getToken(), 510.50);
$this->fillCart($salesChannelContext);

$installmentOptions = $installmentService->getInstallmentOptions($salesChannelContext);

Expand Down Expand Up @@ -61,7 +61,7 @@ public function testItReturnsInstallmentOptionsWithout0Index(): void
$installmentService = $this->getInstallmentService($client);

$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
$this->fillCart($salesChannelContext->getToken(), 510.50);
$this->fillCart($salesChannelContext);

$installmentOptions = $installmentService->getInstallmentOptions($salesChannelContext);

Expand Down Expand Up @@ -97,7 +97,7 @@ public function testItReturnsEmptyOptionsOnFailedRequest(): void
$installmentService = $this->getInstallmentService($client);

$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
$this->fillCart($salesChannelContext->getToken(), 510.50);
$this->fillCart($salesChannelContext);

$installmentOptions = $installmentService->getInstallmentOptions($salesChannelContext);

Expand Down
4 changes: 4 additions & 0 deletions tests/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ interface Constants
public const PAYONE_TRANSACTION_ID = 'test-transaction-id';
public const COUNTRY_ID = 'ea3a25f690f848359a4d64c1c46077ea';
public const SALUTATION_ID = 'c954f5baf0894e95a7ed8b172e59b145';

public const DEFAULT_PRODUCT_PRICE = 119;

public const CUSTOMER_ID = '8c7b6ac55c4647bd997451fa3892aa8d';
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testItFiltersPaymentMethodsByProfilesOnCheckoutConfirmPage(strin
$this->setPaymentMethods($page);

$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
$this->fillCart($salesChannelContext->getToken(), $cartValue);
$this->fillCart($salesChannelContext, $cartValue);

$event = new CheckoutConfirmPageLoadedEvent($page, $salesChannelContext, new Request());
$listener = $this->getContainer()->get(CheckoutConfirmRatepayEventListener::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PayonePayment\Components\ConfigReader\ConfigReader;
use PayonePayment\Components\GenericExpressCheckout\Struct\CreateExpressCheckoutSessionStruct;
use PayonePayment\Constants;
use PayonePayment\PaymentHandler\PayoneAmazonPayExpressPaymentHandler;
use PayonePayment\Payone\RequestParameter\RequestParameterFactory;
use PayonePayment\TestCaseBase\PayoneTestBehavior;
Expand All @@ -28,7 +29,12 @@ public function testIfParametersGotCreatedSuccessfulWithoutRestriction(): void
$context = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

// cart got stored automatically in the CartService, which is reused in the plugin
$this->createCartWithProduct($context, 200, 2);
$this->createCartWithProduct($context);

/** @var SystemConfigService $configService */
$configService = $this->getContainer()->get(SystemConfigService::class);
$configService->set(ConfigReader::getConfigKeyByPaymentHandler(PayoneAmazonPayExpressPaymentHandler::class, 'RestrictPOBoxes'), false);
$configService->set(ConfigReader::getConfigKeyByPaymentHandler(PayoneAmazonPayExpressPaymentHandler::class, 'RestrictPackstations'), false);

$requestParams = $factory->getRequestParameter(new CreateExpressCheckoutSessionStruct(
$context,
Expand All @@ -42,7 +48,7 @@ public function testIfParametersGotCreatedSuccessfulWithoutRestriction(): void
static::assertArrayHasKey('wallettype', $requestParams);
static::assertEquals('AMP', $requestParams['wallettype']);
static::assertArrayHasKey('amount', $requestParams);
static::assertEquals(400 * 100, $requestParams['amount']);
static::assertEquals(Constants::DEFAULT_PRODUCT_PRICE * 100, $requestParams['amount']);
static::assertArrayHasKey('currency', $requestParams);
static::assertArrayHasKey('add_paydata[action]', $requestParams);
static::assertEquals('createCheckoutSessionPayload', $requestParams['add_paydata[action]']);
Expand Down Expand Up @@ -74,7 +80,7 @@ public function testIfParametersGotCreatedSuccessfulWithRestriction(array $restr
}

// cart got stored automatically in the CartService, which is reused in the plugin
$this->createCartWithProduct($context, 200, 2);
$this->createCartWithProduct($context);

$requestParams = $factory->getRequestParameter(new CreateExpressCheckoutSessionStruct(
$context,
Expand All @@ -86,7 +92,7 @@ public function testIfParametersGotCreatedSuccessfulWithRestriction(array $restr
static::assertArrayHasKey('wallettype', $requestParams);
static::assertEquals('AMP', $requestParams['wallettype']);
static::assertArrayHasKey('amount', $requestParams);
static::assertEquals(400 * 100, $requestParams['amount']);
static::assertEquals(Constants::DEFAULT_PRODUCT_PRICE * 100, $requestParams['amount']);
static::assertArrayHasKey('currency', $requestParams);
static::assertArrayHasKey('add_paydata[action]', $requestParams);
static::assertEquals('createCheckoutSessionPayload', $requestParams['add_paydata[action]']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testIfSuccessful(): void
$context = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

// cart got stored automatically in the CartService, which is reused in the plugin
$this->createCartWithProduct($context, 200, 2);
$this->createCartWithProduct($context);

$struct = new AmazonPayExpressUpdateCheckoutSessionStruct($context, 'test-123');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace PayonePayment\Functional\Payment\PaypalExpress;

use PayonePayment\Components\GenericExpressCheckout\Struct\CreateExpressCheckoutSessionStruct;
use PayonePayment\Constants;
use PayonePayment\PaymentHandler\PayonePaypalExpressPaymentHandler;
use PayonePayment\Payone\RequestParameter\RequestParameterFactory;
use PayonePayment\TestCaseBase\PayoneTestBehavior;
Expand All @@ -25,7 +26,7 @@ public function testIfParametersGotCreatedSuccessful(): void

$context = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
// cart got stored automatically in the CartService, which is reused in the plugin
$this->createCartWithProduct($context, 200, 2);
$this->createCartWithProduct($context);

$requestParams = $factory->getRequestParameter(new CreateExpressCheckoutSessionStruct(
$context,
Expand All @@ -37,7 +38,7 @@ public function testIfParametersGotCreatedSuccessful(): void
static::assertArrayHasKey('wallettype', $requestParams);
static::assertEquals('PPE', $requestParams['wallettype']);
static::assertArrayHasKey('amount', $requestParams);
static::assertEquals(400 * 100, $requestParams['amount']);
static::assertEquals(Constants::DEFAULT_PRODUCT_PRICE * 100, $requestParams['amount']);
static::assertArrayHasKey('currency', $requestParams);
static::assertArrayHasKey('add_paydata[action]', $requestParams);
static::assertEquals('setexpresscheckout', $requestParams['add_paydata[action]']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testItAddsCorrectCreateSessionParameters(): void
{
$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

$this->createCartWithProduct($salesChannelContext, 123.45, 4);
$this->createCartWithProduct($salesChannelContext);

$struct = new KlarnaCreateSessionStruct($salesChannelContext, PayoneKlarnaInvoicePaymentHandler::class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace PayonePayment\Payone\RequestParameter\Builder\PayolutionInstallment;

use DMS\PHPUnitExtensions\ArraySubset\Assert;
use PayonePayment\Constants;
use PayonePayment\PaymentHandler\AbstractPayonePaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionInstallmentPaymentHandler;
use PayonePayment\PaymentHandler\PayoneRatepayDebitPaymentHandler;
Expand Down Expand Up @@ -81,7 +82,7 @@ public function testItAddsCorrectPreCheckParameters(): void
'financingtype' => AbstractPayonePaymentHandler::PAYONE_FINANCING_PYS,
'add_paydata[action]' => 'pre_check',
'add_paydata[payment_type]' => 'Payolution-Installment',
'amount' => 10000,
'amount' => Constants::DEFAULT_PRODUCT_PRICE * 100,
'currency' => 'EUR',
'workorderid' => '',
'birthday' => '20000101',
Expand All @@ -95,7 +96,7 @@ protected function getPayolutionAdditionalActionStruct(
string $requestAction = AbstractRequestParameterBuilder::REQUEST_ACTION_PAYOLUTION_PRE_CHECK
): PayolutionAdditionalActionStruct {
$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
$cart = $this->fillCart($salesChannelContext->getToken(), 100);
$cart = $this->fillCart($salesChannelContext);

$dataBag = new RequestDataBag([
'payoneBirthday' => '2000-01-01',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace PayonePayment\Payone\RequestParameter\Builder\PayolutionInvoicing;

use DMS\PHPUnitExtensions\ArraySubset\Assert;
use PayonePayment\Constants;
use PayonePayment\Installer\ConfigInstaller;
use PayonePayment\PaymentHandler\AbstractPayonePaymentHandler;
use PayonePayment\PaymentHandler\PayonePayolutionInvoicingPaymentHandler;
Expand Down Expand Up @@ -82,7 +83,7 @@ public function testItAddsCorrectPreCheckParameters(): void
'financingtype' => AbstractPayonePaymentHandler::PAYONE_FINANCING_PYV,
'add_paydata[action]' => 'pre_check',
'add_paydata[payment_type]' => 'Payolution-Invoicing',
'amount' => 10000,
'amount' => Constants::DEFAULT_PRODUCT_PRICE * 100,
'currency' => 'EUR',
'workorderid' => '',
'birthday' => '20000101',
Expand Down Expand Up @@ -112,7 +113,7 @@ public function testItAddsCorrectCompanyParametersByBillingAddress(): void
'financingtype' => AbstractPayonePaymentHandler::PAYONE_FINANCING_PYV,
'add_paydata[action]' => 'pre_check',
'add_paydata[payment_type]' => 'Payolution-Invoicing',
'amount' => 10000,
'amount' => Constants::DEFAULT_PRODUCT_PRICE * 100,
'currency' => 'EUR',
'workorderid' => '',
'birthday' => '20000101',
Expand Down Expand Up @@ -144,7 +145,7 @@ public function testItAddsCorrectCompanyParametersByCustomer(): void
'financingtype' => AbstractPayonePaymentHandler::PAYONE_FINANCING_PYV,
'add_paydata[action]' => 'pre_check',
'add_paydata[payment_type]' => 'Payolution-Invoicing',
'amount' => 10000,
'amount' => Constants::DEFAULT_PRODUCT_PRICE * 100,
'currency' => 'EUR',
'workorderid' => '',
'birthday' => '20000101',
Expand Down Expand Up @@ -179,7 +180,7 @@ protected function getPayolutionAdditionalActionStruct(
string $requestAction = AbstractRequestParameterBuilder::REQUEST_ACTION_PAYOLUTION_PRE_CHECK
): PayolutionAdditionalActionStruct {
$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
$cart = $this->fillCart($salesChannelContext->getToken(), 100);
$cart = $this->fillCart($salesChannelContext);

$dataBag = new RequestDataBag([
'payoneBirthday' => '2000-01-01',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DMS\PHPUnitExtensions\ArraySubset\Assert;
use PayonePayment\Components\Ratepay\Profile\ProfileService;
use PayonePayment\Constants;
use PayonePayment\PaymentHandler\AbstractPayonePaymentHandler;
use PayonePayment\PaymentHandler\PayoneRatepayDebitPaymentHandler;
use PayonePayment\PaymentHandler\PayoneRatepayInstallmentPaymentHandler;
Expand Down Expand Up @@ -95,7 +96,7 @@ public function testItAddsTheInstallmentCalculationRequestParametersByRate(): vo
'add_paydata[customer_allow_credit_inquiry]' => 'yes',
'add_paydata[calculation_type]' => 'calculation-by-rate',
'add_paydata[rate]' => 1000,
'amount' => 10000,
'amount' => Constants::DEFAULT_PRODUCT_PRICE * 100,
'currency' => 'EUR',
],
$parameters
Expand All @@ -119,7 +120,7 @@ public function testItAddsTheInstallmentCalculationRequestParametersByTime(): vo
'add_paydata[customer_allow_credit_inquiry]' => 'yes',
'add_paydata[calculation_type]' => 'calculation-by-time',
'add_paydata[month]' => 10,
'amount' => 10000,
'amount' => Constants::DEFAULT_PRODUCT_PRICE * 100,
'currency' => 'EUR',
],
$parameters
Expand All @@ -133,7 +134,7 @@ protected function getRatepayCalculationStruct(
string $requestAction = AbstractRequestParameterBuilder::REQUEST_ACTION_RATEPAY_CALCULATION
): RatepayCalculationStruct {
$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
$cart = $this->fillCart($salesChannelContext->getToken(), 100);
$cart = $this->fillCart($salesChannelContext);
$profile = $this->getContainer()->get(ProfileService::class)->getProfileBySalesChannelContext(
$salesChannelContext,
$paymentHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace PayonePayment\Payone\RequestParameter\Builder\SecuredInstallment;

use DMS\PHPUnitExtensions\ArraySubset\Assert;
use PayonePayment\Constants;
use PayonePayment\PaymentHandler\AbstractPayonePaymentHandler;
use PayonePayment\PaymentHandler\PayoneSecuredInstallmentPaymentHandler;
use PayonePayment\PaymentHandler\PayoneSecuredInvoicePaymentHandler;
Expand Down Expand Up @@ -76,7 +77,7 @@ public function testItAddsTheInstallmentOptionsRequestParameters(): void
'financingtype' => AbstractPayonePaymentHandler::PAYONE_FINANCING_PIN,
'add_paydata[action]' => 'installment_options',
'add_paydata[businessRelation]' => 'b2c',
'amount' => 30000,
'amount' => Constants::DEFAULT_PRODUCT_PRICE * 100,
'currency' => 'EUR',
],
$parameters
Expand All @@ -88,7 +89,7 @@ protected function getSecuredInstallmentOptionsStruct(
string $requestAction = AbstractRequestParameterBuilder::REQUEST_ACTION_SECURED_INSTALLMENT_OPTIONS
): SecuredInstallmentOptionsStruct {
$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
$cart = $this->fillCart($salesChannelContext->getToken(), 300);
$cart = $this->fillCart($salesChannelContext);

$dataBag = new RequestDataBag([]);

Expand Down
Loading

0 comments on commit ec9e9d6

Please sign in to comment.