Skip to content

Commit

Permalink
Add console Application to DI container exported types
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Červenka authored and f3l1x committed Mar 20, 2021
1 parent 859f08c commit 5498935
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/DI/ConsoleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public function loadConfiguration(): void

$applicationDef->addSetup('setCommandLoader', ['@' . $this->prefix('commandLoader')]);
}

// Export types
$this->compiler->addExportedType(Application::class);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions tests/cases/DI/ConsoleExtension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use Nette\Bridges\HttpDI\HttpExtension;
use Nette\DI\Compiler;
use Nette\DI\Container;
use Nette\DI\ContainerLoader;
use Nette\DI\Extensions\DIExtension;
use Nette\DI\MissingServiceException;
use Nette\DI\ServiceCreationException;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -166,3 +167,23 @@ test(function (): void {
}, [getmypid(), 7]);
}, ServiceCreationException::class, 'Command "Tests\Fixtures\NoNameCommand" missing tag "console.command[name]" or variable "$defaultName".');
});

// Always exported
test(function (): void {
$loader = new ContainerLoader(TEMP_DIR, true);
$class = $loader->load(function (Compiler $compiler): void {
$compiler->addExtension('console', new ConsoleExtension(true));
$compiler->addExtension('di', new DIExtension());
$compiler->loadConfig(FileMock::create('
di:
export:
types: null
', 'neon'));
}, [getmypid(), 8]);

/** @var Container $container */
$container = new $class();

$application = $container->getByType(Application::class);
Assert::type(Application::class, $application);
});

0 comments on commit 5498935

Please sign in to comment.