Skip to content

Commit

Permalink
Merge pull request #1000 from oat-sa/release-15.19.1
Browse files Browse the repository at this point in the history
Release 15.19.1
  • Loading branch information
jalizada87 authored Mar 16, 2022
2 parents 4adebfb + 347b1f1 commit 1cfd3d1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
17 changes: 15 additions & 2 deletions core/DependencyInjection/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use common_ext_ExtensionsManager;
use InvalidArgumentException;
use oat\generis\model\Middleware\MiddlewareExtensionsMapper;
use oat\tao\model\Middleware\Contract\MiddlewareMapInterface;
use Psr\Container\ContainerInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder as SymfonyContainerBuilder;
Expand All @@ -53,12 +52,16 @@ class ContainerBuilder extends SymfonyContainerBuilder
/** @var MiddlewareExtensionsMapper|null */
private $middlewareExtensionsMapper;

/** @var string|null */
private $configPath;

public function __construct(
string $cachePath,
ContainerInterface $legacyContainer,
bool $isDebugEnabled = null,
ContainerCache $cache = null,
MiddlewareExtensionsMapper $middlewareExtensionsMapper = null
MiddlewareExtensionsMapper $middlewareExtensionsMapper = null,
string $configPath = null
) {
$this->cachePath = $cachePath;
$this->legacyContainer = $legacyContainer;
Expand All @@ -72,6 +75,7 @@ public function __construct(

parent::__construct();
$this->middlewareExtensionsMapper = $middlewareExtensionsMapper ?? new MiddlewareExtensionsMapper();
$this->configPath = $configPath ?? (defined('CONFIG_PATH') ? CONFIG_PATH : null);
}

public function build(): ContainerInterface
Expand All @@ -85,6 +89,10 @@ public function build(): ContainerInterface

public function forceBuild(): ContainerInterface
{
if (!$this->isApplicationInstalled()) {
return $this->legacyContainer;
}

if (!is_writable($this->cachePath)) {
throw new InvalidArgumentException(
sprintf(
Expand Down Expand Up @@ -198,4 +206,9 @@ private function getExtensionsManager(): common_ext_ExtensionsManager
{
return $this->legacyContainer->get(common_ext_ExtensionsManager::SERVICE_ID);
}

private function isApplicationInstalled(): bool
{
return file_exists(rtrim((string)$this->configPath, '/') . '/generis/installation.conf.php');
}
}
24 changes: 19 additions & 5 deletions test/unit/core/DependencyInjection/ContainerBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
use oat\generis\model\DependencyInjection\ContainerCache;
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use oat\generis\model\Middleware\MiddlewareExtensionsMapper;
use oat\generis\test\TestCase;
use oat\oatbox\extension\Manifest;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;

class ContainerBuilderTest extends TestCase
Expand All @@ -52,26 +52,40 @@ class ContainerBuilderTest extends TestCase
/** @var MiddlewareExtensionsMapper|MockObject */
private $middlewareExtensionsMapper;

/** @var MockObject|ContainerInterface */
private $legacyContainer;

public function setUp(): void
{
$this->extensionManager = $this->createMock(common_ext_ExtensionsManager::class);
$this->middlewareExtensionsMapper = $this->createMock(MiddlewareExtensionsMapper::class);

$legacyContainer = $this->createMock(ContainerInterface::class);
$legacyContainer->method('get')
$this->legacyContainer = $this->createMock(ContainerInterface::class);
$this->legacyContainer->method('get')
->willReturn($this->extensionManager);

$this->tempDir = sys_get_temp_dir();

touch($this->tempDir . '/generis/installation.conf.php');

$this->cache = $this->createMock(ContainerCache::class);
$this->subject = new ContainerBuilder(
$this->tempDir,
$legacyContainer,
$this->legacyContainer,
true,
$this->cache,
$this->middlewareExtensionsMapper
$this->middlewareExtensionsMapper,
$this->tempDir
);
}

public function testDoNotBuildIfApplicationIsNotInstalled(): void
{
unlink($this->tempDir . '/generis/installation.conf.php');

$this->assertSame($this->legacyContainer, $this->subject->build());
}

public function testBuildFromCache(): void
{
$container = $this->createMock(ContainerInterface::class);
Expand Down

0 comments on commit 1cfd3d1

Please sign in to comment.