From 0e364cd888069b9fd65e9b0273c04bc9be2b61d0 Mon Sep 17 00:00:00 2001 From: marcelmanzel Date: Mon, 5 Aug 2024 16:10:27 +0200 Subject: [PATCH] OXDEV-8215: Fix integration test for ModuleListInfrastructure --- .../Exception/ModulesNotFoundException.php | 2 +- .../ModuleListInfrastructure.php | 2 +- .../ModuleListInfrastructureInterface.php | 3 +- .../ModuleListInfrastructureTest.php | 59 +++++++++---------- .../ModulesNotFoundExceptionTest.php | 2 +- .../ModuleListInfrastructureTest.php | 1 - 6 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/Module/Exception/ModulesNotFoundException.php b/src/Module/Exception/ModulesNotFoundException.php index f8b66a7..2fbe755 100644 --- a/src/Module/Exception/ModulesNotFoundException.php +++ b/src/Module/Exception/ModulesNotFoundException.php @@ -15,6 +15,6 @@ final class ModulesNotFoundException extends NotFound { public function __construct() { - parent::__construct('Modules was not found.'); + parent::__construct('Modules were not found.'); } } diff --git a/src/Module/Infrastructure/ModuleListInfrastructure.php b/src/Module/Infrastructure/ModuleListInfrastructure.php index 448d640..a2be64e 100644 --- a/src/Module/Infrastructure/ModuleListInfrastructure.php +++ b/src/Module/Infrastructure/ModuleListInfrastructure.php @@ -9,7 +9,7 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure; -use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeFactoryInterface; +use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridgeInterface; use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModulesNotFoundException; diff --git a/src/Module/Infrastructure/ModuleListInfrastructureInterface.php b/src/Module/Infrastructure/ModuleListInfrastructureInterface.php index ede16fa..3eef730 100644 --- a/src/Module/Infrastructure/ModuleListInfrastructureInterface.php +++ b/src/Module/Infrastructure/ModuleListInfrastructureInterface.php @@ -8,14 +8,13 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure; use OxidEsales\GraphQL\ConfigurationAccess\Module\Exception\ModulesNotFoundException; -use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataType; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration; interface ModuleListInfrastructureInterface { /** * @return array - *@throws ModulesNotFoundException + * @throws ModulesNotFoundException */ public function getModuleList(): array; } diff --git a/tests/Integration/Infrastructure/ModuleListInfrastructureTest.php b/tests/Integration/Infrastructure/ModuleListInfrastructureTest.php index dae1f36..b4c5e35 100644 --- a/tests/Integration/Infrastructure/ModuleListInfrastructureTest.php +++ b/tests/Integration/Infrastructure/ModuleListInfrastructureTest.php @@ -11,49 +11,44 @@ use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridgeInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration; -use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ShopConfiguration; use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase; -use OxidEsales\GraphQL\ConfigurationAccess\Module\DataType\ModuleDataTypeFactoryInterface; use OxidEsales\GraphQL\ConfigurationAccess\Module\Infrastructure\ModuleListInfrastructure; class ModuleListInfrastructureTest extends IntegrationTestCase { public function testGetModuleList() { - $moduleConfigId = 'awesomeModuleId'; - $moduleConfigMock = $this->createMock(ModuleConfiguration::class); - $moduleConfigMock - ->method('getId') - ->willReturn($moduleConfigId); - $moduleConfigMock - ->method('isActivated') - ->willReturn(true); - - $shopConfigurationMock = $this->createMock(ShopConfiguration::class); - $shopConfigurationMock - ->method('getModuleConfigurations') - ->willReturn([$moduleConfigMock]); - - $shopConfigurationDaoBridgeMock = $this->createMock(ShopConfigurationDaoBridgeInterface::class); - $shopConfigurationDaoBridgeMock - ->method('get') - ->willReturn($shopConfigurationMock); - - $sut = $this->getSut(shopConfigurationDaoBridge: $shopConfigurationDaoBridgeMock); - $modulesList = $sut->getModuleList(); + /** @var ShopConfigurationDaoBridgeInterface $shopConfigurationDaoBridge */ + $shopConfigurationDaoBridge = $this->get(ShopConfigurationDaoBridgeInterface::class); + $shopConfiguration = $shopConfigurationDaoBridge->get(); + + $moduleConfiguration1 = new ModuleConfiguration(); + $moduleConfiguration1->setId('firstModule'); + $moduleConfiguration1->setModuleSource('test'); + + $moduleConfiguration2 = new ModuleConfiguration(); + $moduleConfiguration2->setId('secondModule'); + $moduleConfiguration2->setModuleSource('test1'); + + $shopConfiguration + ->addModuleConfiguration($moduleConfiguration1) + ->addModuleConfiguration($moduleConfiguration2); + $shopConfigurationDaoBridge->save($shopConfiguration); - $this->assertIsArray($modulesList); - $this->assertSame($moduleConfigId, $modulesList[0]->getId()); - $this->assertTrue($modulesList[0]->isActive()); + $sut = new ModuleListInfrastructure( + $shopConfigurationDaoBridge + ); + $modulesList = $sut->getModuleList(); + $this->assertEquals([ + $moduleConfiguration1->getId() => $moduleConfiguration1, + $moduleConfiguration2->getId() => $moduleConfiguration2 + ], $modulesList); } - public function getSut( - ?ModuleDataTypeFactoryInterface $moduleDataTypeFactory = null, - ?ShopConfigurationDaoBridgeInterface $shopConfigurationDaoBridge = null - ): ModuleListInfrastructure { + public function getSut(): ModuleListInfrastructure + { return new ModuleListInfrastructure( - $moduleDataTypeFactory ?? $this->get(ModuleDataTypeFactoryInterface::class), - $shopConfigurationDaoBridge ?? $this->get(ShopConfigurationDaoBridgeInterface::class) + $this->get(ShopConfigurationDaoBridgeInterface::class) ); } } diff --git a/tests/Unit/Module/Exception/ModulesNotFoundExceptionTest.php b/tests/Unit/Module/Exception/ModulesNotFoundExceptionTest.php index 1b12527..1d8ca9e 100644 --- a/tests/Unit/Module/Exception/ModulesNotFoundExceptionTest.php +++ b/tests/Unit/Module/Exception/ModulesNotFoundExceptionTest.php @@ -22,6 +22,6 @@ public function testModulesNotFoundException() $exception = new ModulesNotFoundException(); $this->assertInstanceOf(ModulesNotFoundException::class, $exception); - $this->assertSame('Modules was not found.', $exception->getMessage()); + $this->assertSame('Modules were not found.', $exception->getMessage()); } } diff --git a/tests/Unit/Module/Infrastructure/ModuleListInfrastructureTest.php b/tests/Unit/Module/Infrastructure/ModuleListInfrastructureTest.php index e2013f7..5f3d6e6 100644 --- a/tests/Unit/Module/Infrastructure/ModuleListInfrastructureTest.php +++ b/tests/Unit/Module/Infrastructure/ModuleListInfrastructureTest.php @@ -43,7 +43,6 @@ public function testGetModuleList() $result = $sut->getModuleList(); - $this->assertCount(1, $result); $this->assertSame([$moduleConfigurationMock], $result); }