mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-26 03:58:45 +02:00
N°8834 - Add compatibility with PHP 8.4 (#819)
* N°8834 - Add compatibility with PHP 8.4 * Rollback of scssphp/scssphp version upgrade due to compilation error
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;
|
||||
|
||||
@@ -45,6 +46,14 @@ abstract class KernelTestCase extends TestCase
|
||||
static::$booted = false;
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
static::ensureKernelShutdown();
|
||||
static::$class = null;
|
||||
static::$kernel = null;
|
||||
static::$booted = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \RuntimeException
|
||||
* @throws \LogicException
|
||||
@@ -52,11 +61,11 @@ abstract class KernelTestCase extends TestCase
|
||||
protected static function getKernelClass(): string
|
||||
{
|
||||
if (!isset($_SERVER['KERNEL_CLASS']) && !isset($_ENV['KERNEL_CLASS'])) {
|
||||
throw new \LogicException(sprintf('You must set the KERNEL_CLASS environment variable to the fully-qualified class name of your Kernel in phpunit.xml / phpunit.xml.dist or override the "%1$s::createKernel()" or "%1$s::getKernelClass()" method.', static::class));
|
||||
throw new \LogicException(\sprintf('You must set the KERNEL_CLASS environment variable to the fully-qualified class name of your Kernel in phpunit.xml / phpunit.xml.dist or override the "%1$s::createKernel()" or "%1$s::getKernelClass()" method.', static::class));
|
||||
}
|
||||
|
||||
if (!class_exists($class = $_ENV['KERNEL_CLASS'] ?? $_SERVER['KERNEL_CLASS'])) {
|
||||
throw new \RuntimeException(sprintf('Class "%s" doesn\'t exist or cannot be autoloaded. Check that the KERNEL_CLASS value in phpunit.xml matches the fully-qualified class name of your Kernel or override the "%s::createKernel()" method.', $class, static::class));
|
||||
throw new \RuntimeException(\sprintf('Class "%s" doesn\'t exist or cannot be autoloaded. Check that the KERNEL_CLASS value in phpunit.xml matches the fully-qualified class name of your Kernel or override the "%s::createKernel()" method.', $class, static::class));
|
||||
}
|
||||
|
||||
return $class;
|
||||
@@ -74,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;
|
||||
}
|
||||
|
||||
@@ -126,12 +147,27 @@ abstract class KernelTestCase extends TestCase
|
||||
if (null !== static::$kernel) {
|
||||
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');
|
||||
}
|
||||
|
||||
static::$kernel->shutdown();
|
||||
static::$booted = false;
|
||||
|
||||
if ($container instanceof ResetInterface) {
|
||||
$container->reset();
|
||||
}
|
||||
|
||||
if (null !== $httpCacheDir && is_dir($httpCacheDir)) {
|
||||
(new Filesystem())->remove($httpCacheDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user