mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-30 14:08:46 +02:00
N°8910 - Upgrade Symfony packages (#811)
This commit is contained in:
@@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Contracts\Service\ResetInterface;
|
||||
|
||||
@@ -82,6 +83,18 @@ abstract class KernelTestCase extends TestCase
|
||||
static::$kernel = $kernel;
|
||||
static::$booted = true;
|
||||
|
||||
// If the cache warmer is registered, it means that the cache has been
|
||||
// warmed up, so the current container is not fresh anymore. Let's
|
||||
// reboot a fresh one.
|
||||
if (self::getContainer()->initialized('cache_warmer')) {
|
||||
static::ensureKernelShutdown();
|
||||
|
||||
$kernel = static::createKernel($options);
|
||||
$kernel->boot();
|
||||
static::$kernel = $kernel;
|
||||
static::$booted = true;
|
||||
}
|
||||
|
||||
return static::$kernel;
|
||||
}
|
||||
|
||||
@@ -135,6 +148,11 @@ abstract class KernelTestCase extends TestCase
|
||||
static::$kernel->boot();
|
||||
$container = static::$kernel->getContainer();
|
||||
|
||||
$httpCacheDir = null;
|
||||
if ($container->has('http_cache')) {
|
||||
$httpCacheDir = static::$kernel->getCacheDir().'/http_cache';
|
||||
}
|
||||
|
||||
if ($container->has('services_resetter')) {
|
||||
// Instantiate the service because Container::reset() only resets services that have been used
|
||||
$container->get('services_resetter');
|
||||
@@ -146,6 +164,10 @@ abstract class KernelTestCase extends TestCase
|
||||
if ($container instanceof ResetInterface) {
|
||||
$container->reset();
|
||||
}
|
||||
|
||||
if (null !== $httpCacheDir && is_dir($httpCacheDir)) {
|
||||
(new Filesystem())->remove($httpCacheDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,15 +71,11 @@ class TestContainer extends Container
|
||||
$container = $this->getPublicContainer();
|
||||
$renamedId = $this->renamedIds[$id] ?? $id;
|
||||
|
||||
try {
|
||||
if (!$this->getPrivateContainer()->has($renamedId)) {
|
||||
$container->set($renamedId, $service);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
if (!str_starts_with($e->getMessage(), "The \"$renamedId\" service is private")) {
|
||||
throw $e;
|
||||
}
|
||||
if (isset($container->privates[$renamedId])) {
|
||||
throw new InvalidArgumentException(\sprintf('The "%s" service is already initialized, you cannot replace it.', $id));
|
||||
}
|
||||
} elseif (isset($container->privates[$renamedId])) {
|
||||
throw new InvalidArgumentException(\sprintf('The "%s" service is already initialized, you cannot replace it.', $id));
|
||||
} else {
|
||||
$container->privates[$renamedId] = $service;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user