Skip to content

Commit

Permalink
Use and create extra temp dirs for CLI & tests
Browse files Browse the repository at this point in the history
Tests because they are also executed from CLI.
  • Loading branch information
spaze committed Jan 13, 2024
1 parent d210a92 commit f5551ef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
26 changes: 21 additions & 5 deletions site/app/Application/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

}
3 changes: 2 additions & 1 deletion site/tests/Application/BootstrapTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit f5551ef

Please sign in to comment.