From e5bba270c6640d8560721ebde4651e3e5f8e6c4f Mon Sep 17 00:00:00 2001 From: mandan2 <61560082+mandan2@users.noreply.github.com> Date: Tue, 12 Sep 2023 11:28:04 +0300 Subject: [PATCH] PIPRES-306: Configuration updateValue multishop context fix (#808) * PIPRES-306: Configuration updateValue multishop context fix * tests fix * stan fix --- mollie.php | 8 +- src/Adapter/ConfigurationAdapter.php | 70 +++++------ src/Adapter/Context.php | 5 + src/Adapter/ToolsAdapter.php | 14 ++- src/Service/CartLinesService.php | 2 +- src/Service/SettingsSaveService.php | 111 +++++++++--------- subscription/Install/AttributeInstaller.php | 2 +- subscription/Install/AttributeUninstaller.php | 2 +- tests/Integration/BaseTestCase.php | 2 +- tests/Unit/Service/CartLinesServiceTest.php | 28 +---- tests/Unit/Validator/VoucherValidatorTest.php | 5 +- 11 files changed, 121 insertions(+), 128 deletions(-) diff --git a/mollie.php b/mollie.php index 0b419b8d2..3ce85292f 100755 --- a/mollie.php +++ b/mollie.php @@ -176,7 +176,13 @@ public function install() $subscriptionInstaller = new Installer( new DatabaseTableInstaller(), - new AttributeInstaller(new NullLogger(), new ConfigurationAdapter(), $this, new LanguageAdapter(), new ProductAttributeAdapter()), + new AttributeInstaller( + new NullLogger(), + $this->getService(ConfigurationAdapter::class), + $this, + new LanguageAdapter(), + new ProductAttributeAdapter() + ), new HookInstaller($this) ); diff --git a/src/Adapter/ConfigurationAdapter.php b/src/Adapter/ConfigurationAdapter.php index 38ddb4d5a..ecee7e379 100644 --- a/src/Adapter/ConfigurationAdapter.php +++ b/src/Adapter/ConfigurationAdapter.php @@ -12,59 +12,51 @@ namespace Mollie\Adapter; -use Context; use Mollie\Config\Config; -use Shop; class ConfigurationAdapter { - public function get($key, $idShop = null, $idLang = null, $idShopGroup = null) + /** @var Context */ + private $context; + + public function __construct(Context $context) { - if (is_array($key)) { - if ((int) $this->get(Config::MOLLIE_ENVIRONMENT)) { - $key = $key['production']; - } else { - $key = $key['sandbox']; - } - } + $this->context = $context; + } + + /** + * @param string|array{production: string, sandbox: string} $key + */ + public function get($key, $idShop = null, $idLang = null, $idShopGroup = null): ?string + { + $key = $this->parseKeyByEnvironment($key); if (!$idShop) { - $idShop = Context::getContext()->shop->id; + $idShop = $this->context->getShopId(); } if (!$idShopGroup) { - $idShopGroup = Context::getContext()->shop->id_shop_group; + $idShopGroup = $this->context->getShopGroupId(); } - return \Configuration::get($key, $idLang, $idShopGroup, $idShop); + $result = \Configuration::get($key, $idLang, $idShopGroup, $idShop); + + return !empty($result) ? $result : null; } /** * @param string|array{production: string, sandbox: string} $key - * @param mixed $value - * @param ?int $idShop - * @param bool $html - * @param ?int $idShopGroup - * - * @return void */ - public function updateValue($key, $value, $idShop = null, $html = false, $idShopGroup = null) + public function updateValue($key, $value, $idShop = null, $html = false, $idShopGroup = null): void { - if (is_array($key)) { - if ((int) $this->get(Config::MOLLIE_ENVIRONMENT)) { - $key = $key['production']; - } else { - $key = $key['sandbox']; - } - } + $key = $this->parseKeyByEnvironment($key); - if ($idShop === null) { - $shops = Shop::getShops(true); - foreach ($shops as $shop) { - \Configuration::updateValue($key, $value, $html, $shop['id_shop_group'], $shop['id_shop']); - } + if (!$idShop) { + $idShop = $this->context->getShopId(); + } - return; + if (!$idShopGroup) { + $idShopGroup = $this->context->getShopGroupId(); } \Configuration::updateValue($key, $value, $html, $idShopGroup, $idShop); @@ -73,7 +65,15 @@ public function updateValue($key, $value, $idShop = null, $html = false, $idShop /** * @param string|array{production: string, sandbox: string} $key */ - public function delete($key) + public function delete($key): void + { + \Configuration::deleteByName($this->parseKeyByEnvironment($key)); + } + + /** + * @param string|array{production: string, sandbox: string} $key + */ + private function parseKeyByEnvironment($key): string { if (is_array($key)) { if ((int) $this->get(Config::MOLLIE_ENVIRONMENT)) { @@ -83,6 +83,6 @@ public function delete($key) } } - \Configuration::deleteByName($key); + return $key; } } diff --git a/src/Adapter/Context.php b/src/Adapter/Context.php index a2de76c69..2bdf0a9d5 100644 --- a/src/Adapter/Context.php +++ b/src/Adapter/Context.php @@ -125,4 +125,9 @@ public function getCountryId(): int { return (int) PrestashopContext::getContext()->country->id; } + + public function getShopGroupId(): int + { + return (int) PrestashopContext::getContext()->shop->id_shop_group; + } } diff --git a/src/Adapter/ToolsAdapter.php b/src/Adapter/ToolsAdapter.php index c091b043a..8730cf9c4 100644 --- a/src/Adapter/ToolsAdapter.php +++ b/src/Adapter/ToolsAdapter.php @@ -16,11 +16,6 @@ class ToolsAdapter { - public function strtoupper($str): string - { - return Tools::strtoupper($str); - } - public function strlen($str): string { return Tools::strlen($str); @@ -39,6 +34,13 @@ public function displayPrice($price, $currency): string public function getValue(string $key, string $defaultValue = null) { - return Tools::getValue($key, $defaultValue); + $result = Tools::getValue($key, $defaultValue); + + return !empty($result) ? $result : null; + } + + public function isSubmit(string $string): bool + { + return (bool) Tools::isSubmit($string); } } diff --git a/src/Service/CartLinesService.php b/src/Service/CartLinesService.php index 5ca553cc8..cbb6ef3ad 100644 --- a/src/Service/CartLinesService.php +++ b/src/Service/CartLinesService.php @@ -481,7 +481,7 @@ private function convertToLineArray(array $newItems, $currencyIsoCode, $apiRound $line->setQuantity((int) $item['quantity']); $line->setSku(isset($item['sku']) ? $item['sku'] : ''); - $currency = $this->tools->strtoupper($currencyIsoCode); + $currency = strtoupper(strtolower($currencyIsoCode)); if (isset($item['discount'])) { $line->setDiscountAmount(new Amount( diff --git a/src/Service/SettingsSaveService.php b/src/Service/SettingsSaveService.php index 8b7f9ca55..3b69b5c89 100644 --- a/src/Service/SettingsSaveService.php +++ b/src/Service/SettingsSaveService.php @@ -13,11 +13,11 @@ namespace Mollie\Service; use Carrier; -use Context; use Exception; use Mollie; use Mollie\Adapter\ConfigurationAdapter; -use Mollie\Adapter\Shop; +use Mollie\Adapter\Context; +use Mollie\Adapter\ToolsAdapter; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Types\PaymentStatus; use Mollie\Config\Config; @@ -26,13 +26,12 @@ use Mollie\Handler\Certificate\Exception\ApplePayDirectCertificateCreation; use Mollie\Handler\Settings\PaymentMethodPositionHandlerInterface; use Mollie\Repository\CountryRepository; -use Mollie\Repository\PaymentMethodRepository; +use Mollie\Repository\PaymentMethodRepositoryInterface; use Mollie\Utility\TagsUtility; use MolPaymentMethodIssuer; use OrderState; use PrestaShopDatabaseException; use PrestaShopException; -use Tools; class SettingsSaveService { @@ -49,7 +48,7 @@ class SettingsSaveService private $countryRepository; /** - * @var PaymentMethodRepository + * @var PaymentMethodRepositoryInterface */ private $paymentMethodRepository; @@ -83,22 +82,25 @@ class SettingsSaveService */ private $applePayDirectCertificateHandler; - /** @var Shop */ - private $shop; private $configurationAdapter; + /** @var Context */ + private $context; + /** @var ToolsAdapter */ + private $tools; public function __construct( Mollie $module, CountryRepository $countryRepository, - PaymentMethodRepository $paymentMethodRepository, + PaymentMethodRepositoryInterface $paymentMethodRepository, PaymentMethodService $paymentMethodService, ApiService $apiService, MolCarrierInformationService $carrierInformationService, PaymentMethodPositionHandlerInterface $paymentMethodPositionHandler, ApiKeyService $apiKeyService, CertificateHandlerInterface $applePayDirectCertificateHandler, - Shop $shop, - ConfigurationAdapter $configurationAdapter + ConfigurationAdapter $configurationAdapter, + Context $context, + ToolsAdapter $tools ) { $this->module = $module; $this->countryRepository = $countryRepository; @@ -109,8 +111,9 @@ public function __construct( $this->paymentMethodPositionHandler = $paymentMethodPositionHandler; $this->apiService = $apiService; $this->applePayDirectCertificateHandler = $applePayDirectCertificateHandler; - $this->shop = $shop; $this->configurationAdapter = $configurationAdapter; + $this->context = $context; + $this->tools = $tools; } /** @@ -125,10 +128,10 @@ public function __construct( public function saveSettings(&$errors = []) { $oldEnvironment = (int) $this->configurationAdapter->get(Config::MOLLIE_ENVIRONMENT); - $environment = (int) Tools::getValue(Config::MOLLIE_ENVIRONMENT); - $mollieApiKey = Tools::getValue(Config::MOLLIE_API_KEY); - $mollieApiKeyTest = Tools::getValue(Config::MOLLIE_API_KEY_TEST); - $paymentOptionPositions = Tools::getValue(Config::MOLLIE_FORM_PAYMENT_OPTION_POSITION); + $environment = (int) $this->tools->getValue(Config::MOLLIE_ENVIRONMENT); + $mollieApiKey = $this->tools->getValue(Config::MOLLIE_API_KEY); + $mollieApiKeyTest = $this->tools->getValue(Config::MOLLIE_API_KEY_TEST); + $paymentOptionPositions = $this->tools->getValue(Config::MOLLIE_FORM_PAYMENT_OPTION_POSITION); $apiKey = Config::ENVIRONMENT_LIVE === (int) $environment ? $mollieApiKey : $mollieApiKeyTest; $isApiKeyIncorrect = 0 !== strpos($apiKey, 'live') && 0 !== strpos($apiKey, 'test'); @@ -139,14 +142,14 @@ public function saveSettings(&$errors = []) return $errors; } - if (Tools::getValue(Config::METHODS_CONFIG) && json_decode(Tools::getValue(Config::METHODS_CONFIG))) { + if ($this->tools->getValue(Config::METHODS_CONFIG) && json_decode($this->tools->getValue(Config::METHODS_CONFIG))) { $this->configurationAdapter->updateValue( Config::METHODS_CONFIG, - json_encode(@json_decode(Tools::getValue(Config::METHODS_CONFIG))) + json_encode(@json_decode($this->tools->getValue(Config::METHODS_CONFIG))) ); } - if ((int) Tools::getValue(Config::MOLLIE_ENV_CHANGED) === 1) { + if ((int) $this->tools->getValue(Config::MOLLIE_ENV_CHANGED) === 1) { $this->configurationAdapter->updateValue(Config::MOLLIE_API_KEY, $mollieApiKey); $this->configurationAdapter->updateValue(Config::MOLLIE_API_KEY_TEST, $mollieApiKeyTest); $this->configurationAdapter->updateValue(Config::MOLLIE_ENVIRONMENT, $environment); @@ -194,28 +197,28 @@ public function saveSettings(&$errors = []) } } - $countries = Tools::getValue(Config::MOLLIE_METHOD_CERTAIN_COUNTRIES . $method['id']); - $excludedCountries = Tools::getValue( + $countries = $this->tools->getValue(Config::MOLLIE_METHOD_CERTAIN_COUNTRIES . $method['id']); + $excludedCountries = $this->tools->getValue( Config::MOLLIE_METHOD_EXCLUDE_CERTAIN_COUNTRIES . $method['id'] ); $this->countryRepository->updatePaymentMethodCountries($paymentMethodId, $countries); $this->countryRepository->updatePaymentMethodExcludedCountries($paymentMethodId, $excludedCountries); } - $this->paymentMethodRepository->deleteOldPaymentMethods($savedPaymentMethods, $environment, (int) $this->shop->getShop()->id); + $this->paymentMethodRepository->deleteOldPaymentMethods($savedPaymentMethods, $environment, $this->context->getShopId()); } if ($paymentOptionPositions) { $this->paymentMethodPositionHandler->savePositions($paymentOptionPositions); } - $useCustomLogo = Tools::getValue(Config::MOLLIE_SHOW_CUSTOM_LOGO); + $useCustomLogo = $this->tools->getValue(Config::MOLLIE_SHOW_CUSTOM_LOGO); $this->configurationAdapter->updateValue( Config::MOLLIE_SHOW_CUSTOM_LOGO, $useCustomLogo ); - $isApplePayDirectProductEnabled = (int) Tools::getValue('MOLLIE_APPLE_PAY_DIRECT_PRODUCT_ENABLED'); - $isApplePayDirectCartEnabled = (int) Tools::getValue('MOLLIE_APPLE_PAY_DIRECT_CART_ENABLED'); + $isApplePayDirectProductEnabled = (int) $this->tools->getValue('MOLLIE_APPLE_PAY_DIRECT_PRODUCT_ENABLED'); + $isApplePayDirectCartEnabled = (int) $this->tools->getValue('MOLLIE_APPLE_PAY_DIRECT_CART_ENABLED'); if ($isApplePayDirectProductEnabled || $isApplePayDirectCartEnabled) { try { @@ -232,29 +235,29 @@ public function saveSettings(&$errors = []) } } - $molliePaymentscreenLocale = Tools::getValue(Config::MOLLIE_PAYMENTSCREEN_LOCALE); - $mollieOrderConfirmationSand = Tools::getValue(Config::MOLLIE_SEND_ORDER_CONFIRMATION); - $mollieIFrameEnabled = Tools::getValue(Config::MOLLIE_IFRAME[$environment ? 'production' : 'sandbox']); - $mollieSingleClickPaymentEnabled = Tools::getValue(Config::MOLLIE_SINGLE_CLICK_PAYMENT[$environment ? 'production' : 'sandbox']); - $mollieImages = Tools::getValue(Config::MOLLIE_IMAGES); - $showResentPayment = Tools::getValue(Config::MOLLIE_SHOW_RESEND_PAYMENT_LINK); - $mollieIssuers = Tools::getValue(Config::MOLLIE_ISSUERS[$environment ? 'production' : 'sandbox']); - $mollieCss = Tools::getValue(Config::MOLLIE_CSS); + $molliePaymentscreenLocale = $this->tools->getValue(Config::MOLLIE_PAYMENTSCREEN_LOCALE); + $mollieOrderConfirmationSand = $this->tools->getValue(Config::MOLLIE_SEND_ORDER_CONFIRMATION); + $mollieIFrameEnabled = $this->tools->getValue(Config::MOLLIE_IFRAME[$environment ? 'production' : 'sandbox']); + $mollieSingleClickPaymentEnabled = $this->tools->getValue(Config::MOLLIE_SINGLE_CLICK_PAYMENT[$environment ? 'production' : 'sandbox']); + $mollieImages = $this->tools->getValue(Config::MOLLIE_IMAGES); + $showResentPayment = $this->tools->getValue(Config::MOLLIE_SHOW_RESEND_PAYMENT_LINK); + $mollieIssuers = $this->tools->getValue(Config::MOLLIE_ISSUERS[$environment ? 'production' : 'sandbox']); + $mollieCss = $this->tools->getValue(Config::MOLLIE_CSS); if (!isset($mollieCss)) { $mollieCss = ''; } - $mollieLogger = Tools::getValue(Config::MOLLIE_DEBUG_LOG); - $mollieApi = Tools::getValue(Config::MOLLIE_API); - $mollieMethodCountriesEnabled = (int) Tools::getValue(Config::MOLLIE_METHOD_COUNTRIES); - $mollieMethodCountriesDisplayEnabled = (int) Tools::getValue(Config::MOLLIE_METHOD_COUNTRIES_DISPLAY); - $mollieErrors = Tools::getValue(Config::MOLLIE_DISPLAY_ERRORS); - $voucherCategory = Tools::getValue(Config::MOLLIE_VOUCHER_CATEGORY); - $applePayDirectStyle = Tools::getValue(Config::MOLLIE_APPLE_PAY_DIRECT_STYLE); - $isBancontactQrCodeEnabled = Tools::getValue(Config::MOLLIE_BANCONTACT_QR_CODE_ENABLED); + $mollieLogger = $this->tools->getValue(Config::MOLLIE_DEBUG_LOG); + $mollieApi = $this->tools->getValue(Config::MOLLIE_API); + $mollieMethodCountriesEnabled = (int) $this->tools->getValue(Config::MOLLIE_METHOD_COUNTRIES); + $mollieMethodCountriesDisplayEnabled = (int) $this->tools->getValue(Config::MOLLIE_METHOD_COUNTRIES_DISPLAY); + $mollieErrors = $this->tools->getValue(Config::MOLLIE_DISPLAY_ERRORS); + $voucherCategory = $this->tools->getValue(Config::MOLLIE_VOUCHER_CATEGORY); + $applePayDirectStyle = $this->tools->getValue(Config::MOLLIE_APPLE_PAY_DIRECT_STYLE); + $isBancontactQrCodeEnabled = $this->tools->getValue(Config::MOLLIE_BANCONTACT_QR_CODE_ENABLED); - $mollieShipMain = Tools::getValue(Config::MOLLIE_AUTO_SHIP_MAIN); + $mollieShipMain = $this->tools->getValue(Config::MOLLIE_AUTO_SHIP_MAIN); if (!isset($mollieErrors)) { $mollieErrors = false; } else { @@ -315,10 +318,10 @@ public function saveSettings(&$errors = []) $this->configurationAdapter->updateValue(Config::MOLLIE_AUTO_SHIP_MAIN, (int) $mollieShipMain); $this->configurationAdapter->updateValue( Config::MOLLIE_TRACKING_URLS, - json_encode(@json_decode(Tools::getValue(Config::MOLLIE_TRACKING_URLS))) + json_encode(@json_decode($this->tools->getValue(Config::MOLLIE_TRACKING_URLS))) ); $carriers = Carrier::getCarriers( - Context::getContext()->language->id, + $this->context->getLanguageId(), false, false, false, @@ -326,24 +329,24 @@ public function saveSettings(&$errors = []) Carrier::ALL_CARRIERS ); foreach ($carriers as $carrier) { - $urlSource = Tools::getValue(Config::MOLLIE_CARRIER_URL_SOURCE . $carrier['id_carrier']); - $customUrl = Tools::getValue(Config::MOLLIE_CARRIER_CUSTOM_URL . $carrier['id_carrier']); + $urlSource = $this->tools->getValue(Config::MOLLIE_CARRIER_URL_SOURCE . $carrier['id_carrier']); + $customUrl = $this->tools->getValue(Config::MOLLIE_CARRIER_CUSTOM_URL . $carrier['id_carrier']); $this->carrierInformationService->saveMolCarrierInfo($carrier['id_carrier'], $urlSource, $customUrl); } foreach (array_keys(Config::getStatuses()) as $name) { - $name = Tools::strtoupper($name); - if (false === Tools::getValue("MOLLIE_STATUS_{$name}")) { + $name = strtoupper(strtolower($name)); + if (!$this->tools->getValue("MOLLIE_STATUS_{$name}")) { continue; } - $new = (int) Tools::getValue("MOLLIE_STATUS_{$name}"); + $new = (int) $this->tools->getValue("MOLLIE_STATUS_{$name}"); $this->configurationAdapter->updateValue("MOLLIE_STATUS_{$name}", $new); - Config::getStatuses()[Tools::strtolower($name)] = $new; + Config::getStatuses()[strtolower(strtoupper($name))] = $new; if (PaymentStatus::STATUS_OPEN != $name) { $this->configurationAdapter->updateValue( "MOLLIE_MAIL_WHEN_{$name}", - Tools::getValue("MOLLIE_MAIL_WHEN_{$name}") ? true : false + (bool) $this->tools->getValue("MOLLIE_MAIL_WHEN_{$name}") ); } } @@ -371,9 +374,9 @@ public function saveSettings(&$errors = []) private function getStatusesValue($key) { $statesEnabled = []; - $context = Context::getContext(); - foreach (OrderState::getOrderStates($context->language->id) as $state) { - if (Tools::isSubmit($key . '_' . $state['id_order_state'])) { + + foreach (OrderState::getOrderStates($this->context->getLanguageId()) as $state) { + if ($this->tools->isSubmit($key . '_' . $state['id_order_state'])) { $statesEnabled[] = $state['id_order_state']; } } @@ -383,7 +386,7 @@ private function getStatusesValue($key) private function handleAuthorizablePaymentInvoiceStatus(): void { - $authorizablePaymentInvoiceOnStatus = (string) Tools::getValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS); + $authorizablePaymentInvoiceOnStatus = $this->tools->getValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS); $this->configurationAdapter->updateValue(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS, $authorizablePaymentInvoiceOnStatus); diff --git a/subscription/Install/AttributeInstaller.php b/subscription/Install/AttributeInstaller.php index 3636418da..edaf8a244 100644 --- a/subscription/Install/AttributeInstaller.php +++ b/subscription/Install/AttributeInstaller.php @@ -73,7 +73,7 @@ public function install(): bool */ private function createAttributeGroup(array $languages): AttributeGroup { - $existingAttributeGroup = new AttributeGroup($this->configuration->get(Config::SUBSCRIPTION_ATTRIBUTE_GROUP)); + $existingAttributeGroup = new AttributeGroup((int) $this->configuration->get(Config::SUBSCRIPTION_ATTRIBUTE_GROUP)); if (Validate::isLoadedObject($existingAttributeGroup)) { return $existingAttributeGroup; } diff --git a/subscription/Install/AttributeUninstaller.php b/subscription/Install/AttributeUninstaller.php index 0788b58ba..8de11089b 100644 --- a/subscription/Install/AttributeUninstaller.php +++ b/subscription/Install/AttributeUninstaller.php @@ -47,7 +47,7 @@ public function uninstall(): bool $attribute->delete(); } - $attributeGroup = new \AttributeGroup($this->configuration->get(Config::SUBSCRIPTION_ATTRIBUTE_GROUP)); + $attributeGroup = new \AttributeGroup((int) $this->configuration->get(Config::SUBSCRIPTION_ATTRIBUTE_GROUP)); $attributeGroup->delete(); } catch (PrestaShopException $e) { $this->errors[] = $this->module->l('Failed to delete attributes', self::FILE_NAME); diff --git a/tests/Integration/BaseTestCase.php b/tests/Integration/BaseTestCase.php index 7a8b1bb7e..d5afe0150 100644 --- a/tests/Integration/BaseTestCase.php +++ b/tests/Integration/BaseTestCase.php @@ -43,7 +43,7 @@ protected function setUp() $this->contextBuilder = new ContextBuilder(); $this->contextBuilder->setDefaults(); - $this->configuration = new ConfigurationAdapter(); + $this->configuration = $this->getService(ConfigurationAdapter::class); } protected function tearDown() diff --git a/tests/Unit/Service/CartLinesServiceTest.php b/tests/Unit/Service/CartLinesServiceTest.php index 1d80eba79..3816e97f7 100644 --- a/tests/Unit/Service/CartLinesServiceTest.php +++ b/tests/Unit/Service/CartLinesServiceTest.php @@ -10,7 +10,7 @@ * @codingStandardsIgnoreStart */ -namespace Service; +namespace Mollie\Tests\Unit\Service; use Mollie\Adapter\ConfigurationAdapter; use Mollie\Adapter\Context; @@ -55,7 +55,7 @@ public function testGetCartLines( $mocks, $result ) { - $configurationAdapter = $this->getMockBuilder(ConfigurationAdapter::class)->getMock(); + $configurationAdapter = $this->createMock(ConfigurationAdapter::class); foreach ($mocks as $mock) { $configurationAdapter->expects(self::at($mock['at']))->method($mock['function'])->with($mock['expects'])->willReturn($mock['return']); @@ -165,12 +165,6 @@ public function cartLinesProvider() ], ], 'toolsMocks' => [ - 0 => [ - 'function' => 'strtoupper', - 'expects' => $currencyIsoCode, - 'return' => $currencyIsoCode, - 'at' => 0, - ], ], 'mocks' => [], 'result' => [ @@ -279,12 +273,6 @@ public function cartLinesProvider() ], ], 'toolsMocks' => [ - 0 => [ - 'function' => 'strtoupper', - 'expects' => $currencyIsoCode, - 'return' => $currencyIsoCode, - 'at' => 0, - ], ], 'mocks' => [], 'result' => [ @@ -370,12 +358,6 @@ public function cartLinesProvider() ], ], 'toolsMocks' => [ - 0 => [ - 'function' => 'strtoupper', - 'expects' => $currencyIsoCode, - 'return' => $currencyIsoCode, - 'at' => 0, - ], ], 'mocks' => [], 'result' => [ @@ -447,12 +429,6 @@ public function cartLinesProvider() ], ], 'toolsMocks' => [ - 0 => [ - 'function' => 'strtoupper', - 'expects' => $currencyIsoCode, - 'return' => $currencyIsoCode, - 'at' => 0, - ], ], 'mocks' => [], 'result' => [ diff --git a/tests/Unit/Validator/VoucherValidatorTest.php b/tests/Unit/Validator/VoucherValidatorTest.php index 911c3eeac..411a85dd5 100644 --- a/tests/Unit/Validator/VoucherValidatorTest.php +++ b/tests/Unit/Validator/VoucherValidatorTest.php @@ -10,7 +10,7 @@ * @codingStandardsIgnoreStart */ -namespace Validator; +namespace Mollie\Tests\Unit\Validator; use Mollie\Adapter\ConfigurationAdapter; use Mollie\Config\Config; @@ -31,7 +31,8 @@ class VoucherValidatorTest extends TestCase public function testValidate(array $products, $configurationMocks, $voucherServiceMocks, $result) { /** @var MockObject $configurationAdapter */ - $configurationAdapter = $this->getMockBuilder(ConfigurationAdapter::class)->getMock(); + $configurationAdapter = $this->createMock(ConfigurationAdapter::class); + foreach ($configurationMocks as $mock) { $configurationAdapter->expects(self::at($mock['at']))->method($mock['function'])->with($mock['expects'])->willReturn($mock['return']); }