From f5551efd7ec7d6946623e0c062b38407d9f8d3ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=A0pa=C4=8Dek?= Date: Sat, 13 Jan 2024 19:37:34 +0100 Subject: [PATCH] Use and create extra temp dirs for CLI & tests Tests because they are also executed from CLI. --- site/app/Application/Bootstrap.php | 26 ++++++++++++++++++----- site/tests/Application/BootstrapTest.phpt | 3 ++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/site/app/Application/Bootstrap.php b/site/app/Application/Bootstrap.php index b159c5f58..fc04a8401 100644 --- a/site/app/Application/Bootstrap.php +++ b/site/app/Application/Bootstrap.php @@ -9,7 +9,9 @@ use Nette\Bootstrap\Configurator; use Nette\CommandLine\Parser; use Nette\DI\Container; +use Nette\Utils\FileSystem; use PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor; +use Spaze\SubresourceIntegrity\Config; use Tester\Environment; class Bootstrap @@ -38,10 +40,8 @@ public static function bootCli(string $argsProvider): Container ServerEnv::setString('HTTPS', 'on'); $cliArgs = self::getCliArgs($argsProvider); $debugMode = ServerEnv::tryGetString('PHP_CLI_ENVIRONMENT') === self::MODE_DEVELOPMENT || $cliArgs->getFlag(self::DEBUG); - $container = self::createConfigurator( - $debugMode, - self::SITE_DIR . '/config/' . ($debugMode ? 'extra-cli-debug.neon' : 'extra-cli.neon'), - )->createContainer(); + $configurator = self::createConfigurator($debugMode, self::SITE_DIR . '/config/' . ($debugMode ? 'extra-cli-debug.neon' : 'extra-cli.neon')); + $container = self::createCliContainer($configurator); if ($cliArgs->getFlag(self::COLORS)) { $container->getByType(ConsoleColor::class)->setForceStyle(true); } @@ -56,7 +56,7 @@ public static function bootTest(): Container $configurator->addStaticParameters([ 'wwwDir' => self::SITE_DIR . '/tests', ]); - $container = $configurator->createContainer(); + $container = self::createCliContainer($configurator); Environment::setup(); return $container; } @@ -120,4 +120,20 @@ private static function getCliArgs(string $argsProvider): CliArgs return new CliArgs($cliArgsParsed ?? [], $cliArgsError ?? null); } + + private static function createCliContainer(Configurator $configurator): Container + { + $tempDir = self::SITE_DIR . '/temp/cli'; + $configurator->setTempDirectory($tempDir); + FileSystem::createDir($tempDir); + + $container = $configurator->createContainer(); + + $sriConfig = $container->getByType(Config::class); + $sriConfig->setLocalBuildPrefix('/i/build/cli'); + FileSystem::createDir($sriConfig->getLocalPathBuildPrefix()); + + return $container; + } + } diff --git a/site/tests/Application/BootstrapTest.phpt b/site/tests/Application/BootstrapTest.phpt index c3088138a..f660624b8 100644 --- a/site/tests/Application/BootstrapTest.phpt +++ b/site/tests/Application/BootstrapTest.phpt @@ -4,6 +4,7 @@ declare(strict_types = 1); namespace MichalSpacekCz\Application; +use MichalSpacekCz\Application\Cli\NoCliArgs; use MichalSpacekCz\ShouldNotHappenException; use MichalSpacekCz\Test\TestCaseRunner; use Nette\DI\Container; @@ -74,7 +75,7 @@ class BootstrapTest extends TestCase } $container = null; Assert::noError(function () use (&$container): void { - $container = Bootstrap::boot(); + $container = Bootstrap::bootCli(NoCliArgs::class); }); Assert::type(Container::class, $container); }