Skip to content

Commit

Permalink
OXDEV-7573 Inject ShopConfigurationSettingDaoInterface to Repository
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Nov 16, 2023
1 parent f3f3083 commit 8cf49da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/Setting/Infrastructure/ShopSettingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure;

use Doctrine\DBAL\Result;
use OxidEsales\EshopCommunity\Internal\Framework\Config\Dao\ShopConfigurationSettingDaoInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Config\Utility\ShopSettingEncoderInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Theme\Event\ThemeSettingChangedEvent;
Expand All @@ -26,7 +27,8 @@ public function __construct(
private BasicContextInterface $basicContext,
private EventDispatcherInterface $eventDispatcher,
private QueryBuilderFactoryInterface $queryBuilderFactory,
protected ShopSettingEncoderInterface $shopSettingEncoder
protected ShopSettingEncoderInterface $shopSettingEncoder,
protected ShopConfigurationSettingDaoInterface $configurationSettingDao,
) {
}

Expand Down
29 changes: 12 additions & 17 deletions tests/Unit/Infrastructure/ShopSettingRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\DBAL\ForwardCompatibility\Result;
use Doctrine\DBAL\Query\QueryBuilder;
use OxidEsales\EshopCommunity\Internal\Framework\Config\Dao\ShopConfigurationSettingDaoInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Config\Utility\ShopSettingEncoder;
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
use OxidEsales\GraphQL\Base\Exception\NotFound;
Expand Down Expand Up @@ -227,20 +228,6 @@ public function testGetNoSettingsList(): void
$repository->getSettingsList();
}

/**
* @param string|bool $returnedValue
* @return QueryBuilderFactoryInterface|(QueryBuilderFactoryInterface&MockObject)|MockObject
*/
private function getFetchOneQueryBuilderFactoryMock(
string|bool $returnedValue
): QueryBuilderFactoryInterface|MockObject {
$result = $this->createMock(Result::class);
$result->expects($this->once())
->method('fetchOne')
->willReturn($returnedValue);
return $this->getQueryBuilderFactoryMock($result);
}

/**
* @param Result|MockObject|(Result&MockObject) $result
* @return QueryBuilderFactoryInterface|(QueryBuilderFactoryInterface&MockObject)|MockObject
Expand All @@ -260,8 +247,15 @@ public function getQueryBuilderFactoryMock(Result|MockObject $result): QueryBuil

private function getFetchOneShopSettingRepoInstance(string|bool $qbReturnValue): ShopSettingRepositoryInterface
{
$queryBuilderFactory = $this->getFetchOneQueryBuilderFactoryMock($qbReturnValue);
return $this->getShopSettingRepository($queryBuilderFactory);
$result = $this->createMock(Result::class);
$result->expects($this->once())
->method('fetchOne')
->willReturn($qbReturnValue);
$queryBuilderFactory = $this->getQueryBuilderFactoryMock($result);

return $this->getShopSettingRepository(
$queryBuilderFactory
);
}

private function getShopSettingRepository(
Expand All @@ -274,7 +268,8 @@ private function getShopSettingRepository(
$basicContextMock,
$eventDispatcher,
$queryBuilderFactory,
$shopSettingEncoder
$shopSettingEncoder,
$this->createStub(ShopConfigurationSettingDaoInterface::class)
);
}
}

0 comments on commit 8cf49da

Please sign in to comment.