Skip to content

Commit

Permalink
OXDEV-7325: Resolve more merge problems
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelOxid committed Nov 13, 2023
1 parent 18c956e commit 9c1d9dc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
abstract class AbstractDatabaseSettingRepository
{
private QueryBuilder $queryBuilder;

public function __construct(
private BasicContextInterface $basicContext,
private EventDispatcherInterface $eventDispatcher,
Expand Down Expand Up @@ -69,7 +67,8 @@ protected function getSettingTypes(string $theme = ''): array
$themeCondition = (!empty($theme)) ? 'theme:'.$theme : '';
$shopId = $this->basicContext->getCurrentShopId();

$this->queryBuilder->select('c.oxvarname')
$queryBuilder = $this->queryBuilderFactory->create();
$queryBuilder->select('c.oxvarname')
->addSelect('c.oxvartype')
->from('oxconfig', 'c')
->where('c.oxmodule = :module')
Expand All @@ -78,7 +77,7 @@ protected function getSettingTypes(string $theme = ''): array
':module' => $themeCondition,
':shopId' => $shopId
]);
$result = $this->queryBuilder->execute();
$result = $queryBuilder->execute();
$value = $result->fetchAllKeyValue();

$notFoundLocation = (!empty($theme)) ? 'theme: "'.$theme.'"' : 'shopID: "'.$shopId.'"';
Expand Down
57 changes: 20 additions & 37 deletions tests/Unit/Infrastructure/ShopSettingRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testGetShopSettingInteger(): void
$nameID = new ID('integerSetting');


$repository = $this->getShopSettingRepoInstance('123');
$repository = $this->getFetchOneShopSettingRepoInstance('123');

$integer = $repository->getInteger($nameID);

Expand All @@ -33,7 +33,7 @@ public function testGetNoShopSettingInteger(): void
{
$nameID = new ID('NotExistingSetting');

$repository = $this->getShopSettingRepoInstance(False);
$repository = $this->getFetchOneShopSettingRepoInstance(False);

$this->expectException(NotFound::class);
$this->expectExceptionMessage('The queried name couldn\'t be found as an integer configuration');
Expand All @@ -44,7 +44,7 @@ public function testGetShopSettingInvalidInteger(): void
{
$nameID = new ID('floatSetting');

$repository = $this->getShopSettingRepoInstance('1.23');
$repository = $this->getFetchOneShopSettingRepoInstance('1.23');

$this->expectException(UnexpectedValueException::class);
$this->expectExceptionMessage('The queried configuration was found as a float, not an integer');
Expand All @@ -56,7 +56,7 @@ public function testGetShopSettingFloat(): void
$nameID = new ID('floatSetting');


$repository = $this->getShopSettingRepoInstance('1.23');
$repository = $this->getFetchOneShopSettingRepoInstance('1.23');

$float = $repository->getFloat($nameID);

Expand All @@ -67,7 +67,7 @@ public function testGetNoShopSettingFloat(): void
{
$nameID = new ID('NotExistingSetting');

$repository = $this->getShopSettingRepoInstance(False);
$repository = $this->getFetchOneShopSettingRepoInstance(False);

$this->expectException(NotFound::class);
$this->expectExceptionMessage('The queried name couldn\'t be found as a float configuration');
Expand All @@ -78,7 +78,7 @@ public function testGetShopSettingInvalidFloat(): void
{
$nameID = new ID('intSetting');

$repository = $this->getShopSettingRepoInstance('123');
$repository = $this->getFetchOneShopSettingRepoInstance('123');

$this->expectException(UnexpectedValueException::class);
$this->expectExceptionMessage('The queried configuration was found as an integer, not a float');
Expand All @@ -90,7 +90,7 @@ public function testGetShopSettingBooleanNegativ(): void
$nameID = new ID('booleanSetting');


$repository = $this->getShopSettingRepoInstance('');
$repository = $this->getFetchOneShopSettingRepoInstance('');

$boolean = $repository->getBoolean($nameID);

Expand All @@ -102,7 +102,7 @@ public function testGetShopSettingBooleanPositiv(): void
$nameID = new ID('booleanSetting');


$repository = $this->getShopSettingRepoInstance('1');
$repository = $this->getFetchOneShopSettingRepoInstance('1');

$boolean = $repository->getBoolean($nameID);

Expand All @@ -113,7 +113,7 @@ public function testGetNoShopSettingBoolean(): void
{
$nameID = new ID('NotExistingSetting');

$repository = $this->getShopSettingRepoInstance(False);
$repository = $this->getFetchOneShopSettingRepoInstance(False);

$this->expectException(NotFound::class);
$this->expectExceptionMessage('The queried name couldn\'t be found as a boolean configuration');
Expand All @@ -125,7 +125,7 @@ public function testGetShopSettingString(): void
$nameID = new ID('stringSetting');


$repository = $this->getShopSettingRepoInstance('default');
$repository = $this->getFetchOneShopSettingRepoInstance('default');

$string = $repository->getString($nameID);

Expand All @@ -136,7 +136,7 @@ public function testGetNoShopSettingString(): void
{
$nameID = new ID('NotExistingSetting');

$repository = $this->getShopSettingRepoInstance(False);
$repository = $this->getFetchOneShopSettingRepoInstance(False);

$this->expectException(NotFound::class);
$this->expectExceptionMessage('The queried name couldn\'t be found as a string configuration');
Expand All @@ -148,7 +148,7 @@ public function testGetShopSettingSelect(): void
$nameID = new ID('selectSetting');


$repository = $this->getShopSettingRepoInstance('select');
$repository = $this->getFetchOneShopSettingRepoInstance('select');

$select = $repository->getSelect($nameID);

Expand All @@ -159,7 +159,7 @@ public function testGetNoShopSettingSelect(): void
{
$nameID = new ID('NotExistingSetting');

$repository = $this->getShopSettingRepoInstance(False);
$repository = $this->getFetchOneShopSettingRepoInstance(False);

$this->expectException(NotFound::class);
$this->expectExceptionMessage('The queried name couldn\'t be found as a select configuration');
Expand All @@ -171,7 +171,7 @@ public function testGetShopSettingCollection(): void
$nameID = new ID('arraySetting');


$repository = $this->getShopSettingRepoInstance('a:2:{i:0;s:4:"nice";i:1;s:6:"values";}', 1);
$repository = $this->getFetchOneShopSettingRepoInstance('a:2:{i:0;s:4:"nice";i:1;s:6:"values";}', 1);

$collection = $repository->getCollection($nameID);

Expand All @@ -182,7 +182,7 @@ public function testGetNoShopSettingCollection(): void
{
$nameID = new ID('NotExistingSetting');

$repository = $this->getShopSettingRepoInstance(False);
$repository = $this->getFetchOneShopSettingRepoInstance(False);

$this->expectException(NotFound::class);
$this->expectExceptionMessage('The queried name couldn\'t be found as a collection configuration');
Expand All @@ -195,7 +195,7 @@ public function testGetShopSettingAssocCollection(): void

$serializeArrayString = 'a:3:{s:5:"first";s:2:"10";s:6:"second";s:2:"20";s:5:"third";s:2:"50";}';

$repository = $this->getShopSettingRepoInstance($serializeArrayString);
$repository = $this->getFetchOneShopSettingRepoInstance($serializeArrayString);

$assocCollection = $repository->getAssocCollection($nameID);

Expand All @@ -206,7 +206,7 @@ public function testGetNoShopSettingAssocCollection(): void
{
$nameID = new ID('NotExistingSetting');

$repository = $this->getShopSettingRepoInstance(False);
$repository = $this->getFetchOneShopSettingRepoInstance(False);

$this->expectException(NotFound::class);
$this->expectExceptionMessage('The queried name couldn\'t be found as an associative collection configuration');
Expand Down Expand Up @@ -256,27 +256,10 @@ public function getQueryBuilderFactoryMock(Result|MockObject $result): QueryBuil
return $queryBuilderFactory;
}

public function getBasicContextMock(int $shopId = 1): BasicContextInterface|MockObject
private function getFetchOneShopSettingRepoInstance(string|bool $qbReturnValue): ShopSettingRepositoryInterface
{
$basicContext = $this->createMock(BasicContextInterface::class);
$basicContext->expects($this->once())
->method('getCurrentShopId')
->willReturn($shopId);

return $basicContext;
}

private function getShopSettingRepoInstance(string|bool $qbReturnValue, int $shopId = 1): ShopSettingRepositoryInterface
{
$queryBuilderFactory = $this->getQueryBuilderFactoryMock($qbReturnValue);
$eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$basicContext = $this->getBasicContextMock($shopId);

return new ShopSettingRepository(
$basicContext,
$eventDispatcher,
$queryBuilderFactory
);
$queryBuilderFactory = $this->getFetchOneQueryBuilderFactoryMock($qbReturnValue);
return $this->getShopSettingRepository($queryBuilderFactory);
}

/**
Expand Down
Loading

0 comments on commit 9c1d9dc

Please sign in to comment.