Skip to content

Commit

Permalink
OXDEV-8215: Fix integration test for ModuleListInfrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelOxid committed Aug 5, 2024
1 parent 870c550 commit 0e364cd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/Module/Exception/ModulesNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ final class ModulesNotFoundException extends NotFound
{
public function __construct()
{
parent::__construct('Modules was not found.');
parent::__construct('Modules were not found.');
}
}
2 changes: 1 addition & 1 deletion src/Module/Infrastructure/ModuleListInfrastructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModuleConfiguration>
*@throws ModulesNotFoundException
* @throws ModulesNotFoundException
*/
public function getModuleList(): array;
}
59 changes: 27 additions & 32 deletions tests/Integration/Infrastructure/ModuleListInfrastructureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function testGetModuleList()

$result = $sut->getModuleList();

$this->assertCount(1, $result);
$this->assertSame([$moduleConfigurationMock], $result);
}

Expand Down

0 comments on commit 0e364cd

Please sign in to comment.