File tree Expand file tree Collapse file tree 4 files changed +46
-5
lines changed
Expand file tree Collapse file tree 4 files changed +46
-5
lines changed Original file line number Diff line number Diff line change @@ -185,10 +185,14 @@ function command(string $command)
185185 $ params [$ arg ] = $ value ;
186186 }
187187
188- ob_start ();
189- service ('commands ' )->run ($ command , $ params );
188+ try {
189+ ob_start ();
190+ service ('commands ' )->run ($ command , $ params );
190191
191- return ob_get_clean ();
192+ return ob_get_contents ();
193+ } finally {
194+ ob_end_clean ();
195+ }
192196 }
193197}
194198
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ /**
6+ * This file is part of CodeIgniter 4 framework.
7+ *
8+ * (c) CodeIgniter Foundation <admin@codeigniter.com>
9+ *
10+ * For the full copyright and license information, please view
11+ * the LICENSE file that was distributed with this source code.
12+ */
13+
14+ namespace Tests \Support \Commands ;
15+
16+ use RuntimeException ;
17+
18+ /**
19+ * @internal
20+ */
21+ final class DestructiveCommand extends AbstractInfo
22+ {
23+ protected $ group = 'demo ' ;
24+ protected $ name = 'app:destructive ' ;
25+ protected $ description = 'This command is destructive. ' ;
26+
27+ public function run (array $ params ): never
28+ {
29+ throw new RuntimeException ('This command is destructive and should not be run. ' );
30+ }
31+ }
Original file line number Diff line number Diff line change 1919use CodeIgniter \Test \StreamFilterTrait ;
2020use PHPUnit \Framework \Attributes \DataProvider ;
2121use PHPUnit \Framework \Attributes \Group ;
22+ use RuntimeException ;
2223use Tests \Support \Commands \AppInfo ;
2324use Tests \Support \Commands \ParamsReveal ;
2425
@@ -136,6 +137,13 @@ public function testInexistentCommandsButWithManyAlternatives(): void
136137 $ this ->assertStringContainsString (':clear ' , $ this ->getBuffer ());
137138 }
138139
140+ public function testDestructiveCommandIsNotRisky (): void
141+ {
142+ $ this ->expectException (RuntimeException::class);
143+
144+ command ('app:destructive ' );
145+ }
146+
139147 /**
140148 * @param list<string> $expected
141149 */
Original file line number Diff line number Diff line change @@ -171,7 +171,6 @@ public function testSyncWithNullableOriginalLangValue(): void
171171 TEXT_WRAP;
172172
173173 file_put_contents (self ::$ languageTestPath . self ::$ locale . '/SyncInvalid.php ' , $ langWithNullValue );
174- ob_get_flush ();
175174
176175 $ this ->expectException (LogicException::class);
177176 $ this ->expectExceptionMessageMatches ('/Only "array" or "string" is allowed/ ' );
@@ -192,7 +191,6 @@ public function testSyncWithIntegerOriginalLangValue(): void
192191 TEXT_WRAP;
193192
194193 file_put_contents (self ::$ languageTestPath . self ::$ locale . '/SyncInvalid.php ' , $ langWithIntegerValue );
195- ob_get_flush ();
196194
197195 $ this ->expectException (LogicException::class);
198196 $ this ->expectExceptionMessageMatches ('/Only "array" or "string" is allowed/ ' );
You can’t perform that action at this time.
0 commit comments