Skip to content

Commit

Permalink
Merge branch '1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Feb 12, 2021
2 parents eedf46b + 139715b commit 19f134e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ public function getRepositoryConfig()
// Takes configured repository as the reference, if it exists.
// If not, the first configured repository is considered instead.
$repositoryAlias = $this->configResolver->getParameter('repository');
if ($repositoryAlias === null) {
$aliases = array_keys($this->repositories);
$repositoryAlias = array_shift($aliases);
}
$repositoryAlias = $repositoryAlias ?: $this->getDefaultRepositoryAlias();

if (empty($repositoryAlias) || !isset($this->repositories[$repositoryAlias])) {
throw new InvalidRepositoryException(
Expand All @@ -54,6 +51,18 @@ public function getRepositoryConfig()
return ['alias' => $repositoryAlias] + $this->repositories[$repositoryAlias];
}

public function getCurrentRepositoryAlias(): string
{
return $this->getRepositoryConfig()['alias'];
}

public function getDefaultRepositoryAlias(): ?string
{
$aliases = array_keys($this->repositories);

return array_shift($aliases);
}

public function getStorageConnectionName(): string
{
$repositoryConfig = $this->getRepositoryConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,14 @@ public function testGetRepositoryConfigNotSpecifiedRepository()
);
}

public function testGetRepositoryConfigUndefinedRepository()
/**
* @dataProvider providerForRepositories
*/
public function testGetRepositoryConfigUndefinedRepository(array $repositories): void
{
$this->expectException(\eZ\Bundle\EzPublishCoreBundle\ApiLoader\Exception\InvalidRepositoryException::class);

$configResolver = $this->getConfigResolverMock();
$repositories = [
'main' => [
'engine' => 'foo',
],
'another' => [
'engine' => 'bar',
],
];

$configResolver
->expects($this->once())
Expand All @@ -92,6 +87,48 @@ public function testGetRepositoryConfigUndefinedRepository()
$provider->getRepositoryConfig();
}

/**
* @dataProvider providerForRepositories
*/
public function testGetDefaultRepositoryAlias(array $repositories): void
{
$configResolver = $this->getConfigResolverMock();

$provider = new RepositoryConfigurationProvider($configResolver, $repositories);
$provider->getRepositoryConfig();

self::assertSame('first', $provider->getDefaultRepositoryAlias());
}

/**
* @dataProvider providerForRepositories
*/
public function testGetCurrentRepositoryAlias(array $repositories): void
{
$configResolver = $this->getConfigResolverMock();

$provider = new RepositoryConfigurationProvider($configResolver, $repositories);
$provider->getRepositoryConfig();

self::assertSame('first', $provider->getCurrentRepositoryAlias());
}

public function providerForRepositories(): array
{
return [
[
[
'first' => [
'engine' => 'foo',
],
'second' => [
'engine' => 'bar',
],
],
],
];
}

/**
* @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\Core\MVC\ConfigResolverInterface
*/
Expand Down

0 comments on commit 19f134e

Please sign in to comment.