Skip to content

Commit

Permalink
orisai/installer support
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Jun 21, 2024
1 parent cacff3e commit 0ae9038
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"latte/latte": "^2.10.0",
"nette/http": "^3.0.0",
"orisai/coding-standard": "^3.0.0",
"orisai/installer": "^1.0.0",
"orisai/vfs": "^1.0.0",
"phpstan/extension-installer": "^1.0.0",
"phpstan/phpstan": "^1.0.0",
Expand Down Expand Up @@ -60,7 +61,7 @@
"dealerdirect/phpcodesniffer-composer-installer": true,
"infection/extension-installer": true,
"phpstan/extension-installer": true,
"orisai/installer": false
"orisai/installer": true
}
}
}
34 changes: 34 additions & 0 deletions src/Boot/AutomaticConfigurator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types = 1);

namespace OriNette\DI\Boot;

use Orisai\Installer\Loader\BaseLoader;

final class AutomaticConfigurator extends BaseConfigurator
{

private BaseLoader $loader;

public function __construct(string $rootDir, BaseLoader $loader)
{
parent::__construct($rootDir);
$this->loader = $loader;
$this->addStaticParameters([
'modules' => $this->loader->loadModulesMeta($rootDir),
]);
}

protected function loadConfigFiles(): array
{
return $this->loader->loadConfigFiles($this->rootDir);
}

public function loadContainer(): string
{
$this->loader->configureSwitch('consoleMode', $this->staticParameters['consoleMode']);

Check warning on line 28 in src/Boot/AutomaticConfigurator.php

View workflow job for this annotation

GitHub Actions / Test for mutants (ubuntu-latest, 8.3)

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ } public function loadContainer(): string { - $this->loader->configureSwitch('consoleMode', $this->staticParameters['consoleMode']); + $this->loader->configureSwitch('debugMode', $this->staticParameters['debugMode']); return parent::loadContainer(); } }
$this->loader->configureSwitch('debugMode', $this->staticParameters['debugMode']);

Check warning on line 29 in src/Boot/AutomaticConfigurator.php

View workflow job for this annotation

GitHub Actions / Test for mutants (ubuntu-latest, 8.3)

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ public function loadContainer(): string { $this->loader->configureSwitch('consoleMode', $this->staticParameters['consoleMode']); - $this->loader->configureSwitch('debugMode', $this->staticParameters['debugMode']); + return parent::loadContainer(); } }

return parent::loadContainer();
}

}
10 changes: 10 additions & 0 deletions src/Orisai.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types = 1);

use Orisai\Installer\Schema\ModuleSchema;

$schema = new ModuleSchema();

$schema->addSwitch('consoleMode', false);
$schema->addSwitch('debugMode', false);

return $schema;
50 changes: 50 additions & 0 deletions tests/Unit/Boot/AutomaticConfiguratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php declare(strict_types = 1);

namespace Tests\OriNette\DI\Unit\Boot;

use OriNette\DI\Boot\AutomaticConfigurator;
use Orisai\Installer\Loader\DefaultLoader;
use PHPUnit\Framework\TestCase;
use function dirname;
use function mkdir;
use const PHP_VERSION_ID;

final class AutomaticConfiguratorTest extends TestCase
{

private string $rootDir;

protected function setUp(): void
{
parent::setUp();

$this->rootDir = dirname(__DIR__, 3);
if (PHP_VERSION_ID < 8_01_00) {
@mkdir("$this->rootDir/var/build");
}
}

public function testModules(): void
{
$configurator = new AutomaticConfigurator($this->rootDir, new DefaultLoader());
$configurator->setForceReloadContainer();

$container = $configurator->createContainer();

$parameters = $container->getParameters();

self::assertArrayHasKey('modules', $parameters);
self::assertSame(
$parameters['modules'],
[
'orisai_nette-di' => [
'dir' => $this->rootDir,
],
'root' => [
'dir' => $this->rootDir,
],
],
);
}

}

0 comments on commit 0ae9038

Please sign in to comment.