From 549893573ba3cb81f476785763f48178b5166322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8Cervenka?= Date: Thu, 18 Feb 2021 10:53:29 +0100 Subject: [PATCH] Add console Application to DI container exported types --- src/DI/ConsoleExtension.php | 3 +++ tests/cases/DI/ConsoleExtension.phpt | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/DI/ConsoleExtension.php b/src/DI/ConsoleExtension.php index 1a0b78c..025d2d9 100644 --- a/src/DI/ConsoleExtension.php +++ b/src/DI/ConsoleExtension.php @@ -123,6 +123,9 @@ public function loadConfiguration(): void $applicationDef->addSetup('setCommandLoader', ['@' . $this->prefix('commandLoader')]); } + + // Export types + $this->compiler->addExportedType(Application::class); } /** diff --git a/tests/cases/DI/ConsoleExtension.phpt b/tests/cases/DI/ConsoleExtension.phpt index a7acb70..9cd86c8 100644 --- a/tests/cases/DI/ConsoleExtension.phpt +++ b/tests/cases/DI/ConsoleExtension.phpt @@ -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; @@ -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); +});