Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/convergence-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/Illuminate/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}();
}

/**
Expand Down
31 changes: 31 additions & 0 deletions tests/Console/ConsoleApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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'; }
}
Loading