From 11e6f49e8324d50b73cfd760129c80a52ff7d09b Mon Sep 17 00:00:00 2001 From: Marjan Petkovski <72909665+pmarjan-onestic@users.noreply.github.com> Date: Fri, 8 Nov 2024 09:19:52 +0100 Subject: [PATCH] Issue Preventing Checkout with Configurable Products in Low Stock (#62) * #59 Configuration provider * Formatting * Write unit tests * Fix unit tests --------- Co-authored-by: Sushmita Thakur Co-authored-by: Khushboo Co-authored-by: Can Demiralp Co-authored-by: Can Demiralp --- Model/CompositeConfigProvider.php | 30 +++++++++ Model/Configuration.php | 5 +- .../Model/CompositeConfigProviderTest.php | 65 +++++++++++++++++++ Test/Unit/Model/ConfigurationTest.php | 19 +++--- etc/di.xml | 17 +++++ 5 files changed, 122 insertions(+), 14 deletions(-) create mode 100644 Model/CompositeConfigProvider.php create mode 100644 Test/Unit/Model/CompositeConfigProviderTest.php diff --git a/Model/CompositeConfigProvider.php b/Model/CompositeConfigProvider.php new file mode 100644 index 00000000..18361795 --- /dev/null +++ b/Model/CompositeConfigProvider.php @@ -0,0 +1,30 @@ +configProviders as $configProvider) { + $config = array_merge_recursive($config, $configProvider->getConfig()); + } + + return $config; + } +} diff --git a/Model/Configuration.php b/Model/Configuration.php index fd77cb68..e1f5e982 100644 --- a/Model/Configuration.php +++ b/Model/Configuration.php @@ -5,7 +5,6 @@ namespace Adyen\Hyva\Model; use Exception; -use Magento\Checkout\Model\CompositeConfigProvider; use Magento\Framework\DataObject; use Magento\Framework\DataObjectFactory; use Psr\Log\LoggerInterface; @@ -16,8 +15,8 @@ class Configuration public function __construct( CompositeConfigProvider $configProvider, - DataObjectFactory $dataObjectFactory, - LoggerInterface $logger + DataObjectFactory $dataObjectFactory, + LoggerInterface $logger ) { try { if (isset($configProvider->getConfig()['payment'])) { diff --git a/Test/Unit/Model/CompositeConfigProviderTest.php b/Test/Unit/Model/CompositeConfigProviderTest.php new file mode 100644 index 00000000..4c60429d --- /dev/null +++ b/Test/Unit/Model/CompositeConfigProviderTest.php @@ -0,0 +1,65 @@ + + */ + +namespace Adyen\Hyva\Test\Unit\Model; + +use Adyen\Hyva\Model\CompositeConfigProvider; +use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; +use Magento\Checkout\Model\ConfigProviderInterface; +use PHPUnit\Framework\MockObject\MockObject; + +class CompositeConfigProviderTest extends AbstractAdyenTestCase +{ + protected ?CompositeConfigProvider $compositeConfigProvider; + protected MockObject|array $configProvidersMock; + protected MockObject|ConfigProviderInterface $singleConfigProviderMock; + + /** + * @return void + */ + public function setUp(): void + { + parent::setUp(); + + $this->singleConfigProviderMock = $this->createMock(ConfigProviderInterface::class); + $this->configProvidersMock[] = $this->singleConfigProviderMock; + + $this->compositeConfigProvider = new CompositeConfigProvider($this->configProvidersMock); + } + + /** + * @return void + */ + public function tearDown(): void + { + $this->compositeConfigProvider = null; + } + + /** + * Test case to assert all available config values provided through di.xml + * + * @return void + */ + public function testGetConfig() + { + $configMock = [ + 'config1' => 'value1', + 'config2' => 'value2' + ]; + + $this->singleConfigProviderMock->expects($this->once()) + ->method('getConfig') + ->willReturn($configMock); + + $result = $this->compositeConfigProvider->getConfig(); + $this->assertEquals($configMock, $result); + } +} diff --git a/Test/Unit/Model/ConfigurationTest.php b/Test/Unit/Model/ConfigurationTest.php index 74a0a15d..c38fab02 100644 --- a/Test/Unit/Model/ConfigurationTest.php +++ b/Test/Unit/Model/ConfigurationTest.php @@ -2,19 +2,19 @@ namespace Adyen\Hyva\Test\Unit\Model; +use Adyen\Hyva\Model\CompositeConfigProvider; use Adyen\Hyva\Model\Configuration; use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; -use Magento\Checkout\Model\CompositeConfigProvider; use Magento\Framework\DataObjectFactory; use Psr\Log\LoggerInterface; use PHPUnit\Framework\MockObject\MockObject; class ConfigurationTest extends AbstractAdyenTestCase { - private Configuration $configuration; - private CompositeConfigProvider|MockObject $configProvider; - private DataObjectFactory|MockObject $dataObjectFactory; - private LoggerInterface|MockObject $logger; + protected Configuration $configuration; + protected CompositeConfigProvider|MockObject $configProvider; + protected DataObjectFactory|MockObject $dataObjectFactory; + protected LoggerInterface|MockObject $logger; protected function setUp(): void { @@ -26,13 +26,9 @@ protected function setUp(): void ] ]; - $this->configProvider = $this->getMockBuilder(CompositeConfigProvider::class) - ->disableOriginalConstructor() - ->getMock(); + $this->configProvider = $this->createMock(CompositeConfigProvider::class); $this->dataObjectFactory = $this->createGeneratedMock(DataObjectFactory::class, ['create']); - $this->logger = $this->getMockBuilder(LoggerInterface::class) - ->disableOriginalConstructor() - ->getMock(); + $this->logger = $this->createMock(LoggerInterface::class); $this->configProvider->expects($this->exactly(2)) ->method('getConfig') @@ -74,6 +70,7 @@ public function testGetJsonValue(): void $jsonValue = $this->configuration->getJsonValue('nonexistent/path'); $this->assertSame('null', $jsonValue); } + public function testIsCCEnableStoreDetails(): void { $result = $this->configuration->isCCEnableStoreDetails(false); diff --git a/etc/di.xml b/etc/di.xml index ebec49a0..54bbc24b 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -42,4 +42,21 @@ + + + + + Magento\Payment\Model\CcGenericConfigProvider + Magento\Payment\Model\CcConfigProvider + Magento\Tax\Model\TaxConfigProvider + Magento\Vault\Model\Ui\VaultConfigProvider + Magento\Vault\Model\Ui\TokensConfigProvider + Adyen\Payment\Model\Ui\AdyenGenericConfigProvider + Adyen\Payment\Model\Ui\AdyenCcConfigProvider + Adyen\Payment\Model\Ui\AdyenPmConfigProvider + Adyen\Payment\Model\Ui\AdyenPosCloudConfigProvider + Adyen\Payment\Model\Ui\AdyenGiftcardConfigProvider + + +