File tree 3 files changed +44
-1
lines changed
Bundle/FrameworkBundle/Tests/Kernel
Component/Console/DependencyInjection
3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Bundle \FrameworkBundle \Tests \Kernel ;
13
+
14
+ use Symfony \Component \Console \Attribute \AsCommand ;
15
+ use Symfony \Component \Console \Output \OutputInterface ;
16
+
17
+ #[AsCommand(name: 'kernel:hello ' )]
18
+ final class KernelCommand extends MinimalKernel
19
+ {
20
+ public function __invoke (OutputInterface $ output ): int
21
+ {
22
+ $ output ->write ('Hello Kernel! ' );
23
+
24
+ return 0 ;
25
+ }
26
+ }
Original file line number Diff line number Diff line change 13
13
14
14
use PHPUnit \Framework \TestCase ;
15
15
use Psr \Log \NullLogger ;
16
+ use Symfony \Bundle \FrameworkBundle \Console \Application ;
16
17
use Symfony \Bundle \FrameworkBundle \Kernel \MicroKernelTrait ;
18
+ use Symfony \Component \Console \Input \ArrayInput ;
19
+ use Symfony \Component \Console \Output \BufferedOutput ;
17
20
use Symfony \Component \DependencyInjection \ContainerBuilder ;
18
21
use Symfony \Component \DependencyInjection \Extension \ExtensionInterface ;
19
22
use Symfony \Component \DependencyInjection \Loader \ClosureLoader ;
@@ -152,6 +155,19 @@ public function testSimpleKernel()
152
155
$ this ->assertSame ('Hello World! ' , $ response ->getContent ());
153
156
}
154
157
158
+ public function testKernelCommand ()
159
+ {
160
+ $ kernel = $ this ->kernel = new KernelCommand ('kernel_command ' );
161
+ $ application = new Application ($ kernel );
162
+
163
+ $ input = new ArrayInput (['command ' => 'kernel:hello ' ]);
164
+ $ output = new BufferedOutput ();
165
+
166
+ $ this ->assertTrue ($ application ->has ('kernel:hello ' ));
167
+ $ this ->assertSame (0 , $ application ->doRun ($ input , $ output ));
168
+ $ this ->assertSame ('Hello Kernel! ' , $ output ->fetch ());
169
+ }
170
+
155
171
public function testDefaultKernel ()
156
172
{
157
173
$ kernel = $ this ->kernel = new DefaultKernel ('test ' , false );
Original file line number Diff line number Diff line change @@ -39,7 +39,6 @@ public function process(ContainerBuilder $container): void
39
39
40
40
foreach ($ commandServices as $ id => $ tags ) {
41
41
$ definition = $ container ->getDefinition ($ id );
42
- $ definition ->addTag ('container.no_preload ' );
43
42
$ class = $ container ->getParameterBag ()->resolveValue ($ definition ->getClass ());
44
43
45
44
if (!$ r = $ container ->getReflectionClass ($ class )) {
@@ -58,6 +57,8 @@ public function process(ContainerBuilder $container): void
58
57
$ invokableRef = null ;
59
58
}
60
59
60
+ $ definition ->addTag ('container.no_preload ' );
61
+
61
62
/** @var AsCommand|null $attribute */
62
63
$ attribute = ($ r ->getAttributes (AsCommand::class)[0 ] ?? null )?->newInstance();
63
64
You can’t perform that action at this time.
0 commit comments