diff --git a/ci/convergence-baseline.txt b/ci/convergence-baseline.txt index cb12348ec..f1bb9a32d 100644 --- a/ci/convergence-baseline.txt +++ b/ci/convergence-baseline.txt @@ -2,7 +2,7 @@ # regenerate: ci/convergence-ratchet.sh --init src (hanya setelah count TURUN) array_first_last=0 route_uses_string=5 -event_fire=4 +event_fire=3 config_getEnvironment=3 where_raw=1 eloquent_lists=6 diff --git a/src/Illuminate/Console/Command.php b/src/Illuminate/Console/Command.php index 97276ac9f..feba65d28 100755 --- a/src/Illuminate/Console/Command.php +++ b/src/Illuminate/Console/Command.php @@ -110,10 +110,14 @@ public function run(InputInterface $input, OutputInterface $output): int */ protected function execute(InputInterface $input, OutputInterface $output): mixed { + // Prefer handle() (L13 idiom); fire() is the L4.2 fallback that dies at the Console swap. + // ponytail: fork mirror of stock Command's handle-or-__invoke resolution; app-side is grep-guarded. + $method = method_exists($this, 'handle') ? 'handle' : 'fire'; + // Symfony 5 removed support of returning null, so we cast the returned value as integer. - // In this case, void-returned fire() method will be casted to 0. + // A void-returned handle()/fire() is casted to 0. // @see https://github.com/symfony/console/blob/6.3/CHANGELOG.md#500 - return (int) $this->fire(); + return (int) $this->{$method}(); } /** diff --git a/tests/Console/ConsoleApplicationTest.php b/tests/Console/ConsoleApplicationTest.php index 71c494bb9..6a5813adb 100755 --- a/tests/Console/ConsoleApplicationTest.php +++ b/tests/Console/ConsoleApplicationTest.php @@ -3,6 +3,8 @@ use L4\Tests\BackwardCompatibleTestCase; use Mockery as m; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Output\NullOutput; class ConsoleApplicationTest extends BackwardCompatibleTestCase { @@ -66,4 +68,33 @@ public function testResolveCommandsCallsResolveForAllCommandsItsGivenViaArray() $app->resolveCommands(['foo', 'foo']); } + + public function testExecuteResolvesHandleThenFallsBackToFire() + { + $execute = new \ReflectionMethod(\Illuminate\Console\Command::class, 'execute'); + $execute->setAccessible(true); + $input = new ArrayInput([]); + $output = new NullOutput; + + // handle() is preferred (L13 idiom) + $this->assertSame(0, $execute->invoke(new ConsoleHandleStub, $input, $output)); + $this->assertEquals('handle', $_SERVER['__console.ran']); + + // fire() still runs as the L4.2 fallback when no handle() exists + $execute->invoke(new ConsoleFireStub, $input, $output); + $this->assertEquals('fire', $_SERVER['__console.ran']); + } + +} + +class ConsoleHandleStub extends \Illuminate\Console\Command +{ + protected $name = 'stub:handle'; + public function handle() { $_SERVER['__console.ran'] = 'handle'; } +} + +class ConsoleFireStub extends \Illuminate\Console\Command +{ + protected $name = 'stub:fire'; + public function fire() { $_SERVER['__console.ran'] = 'fire'; } }