Skip to content

Conversation

@seriquynh
Copy link
Contributor

@seriquynh seriquynh commented Nov 12, 2025

In the ConsoleApplicationTest class, there are a few things that should be cleaned up.

  • $app usually refers to an instance of the Laravel framework foundation application Illuminate\Foundation\Application. The term artisan is introduced as the console application Illuminate\Console\Application. E.g, the console kernel has artisan property or the Artisan facade represents the console application.
// before
$app = $this->getMockConsole(['addToParent']); // We may get confused at first sight.

// after
$artisan = $this->getMockConsole(['addToParent']); // It's exactly a console application.
  • The fire method was removed from the event dispatcher long time ago. We needn't and shouldn't mock it anymore.
// before
m::mock(Dispatcher::class, ['dispatch' => null, 'fire' => null]);

// after
m::mock(Dispatcher::class, ['dispatch' => null]);
  • The result returned by the call method of the console application should be an exit code (0-255), shouldn't it? Because status code is more relevant to HTTP.
// before
$statusCode = $app->call('fake-command-for-testing');

// after
$exitCode = $artisan->call('fake-command-for-testing');

Finally, let's look at the complete test below after cleanup:

  • $artisan is a console app. (We won't get confused by $app and $laravel)
  • $laravel is a Laravel foundation application.
  • $exitCode is an unsigned integer returned by the console call method (passed to the exit function in real a script).
    public function testCallMethodCanCallArtisanCommandUsingCommandClassObject()
    {
        $artisan = new Application(
            $laravel = new \Illuminate\Foundation\Application(__DIR__),
            m::mock(Dispatcher::class, ['dispatch' => null]),
            'testing'
        );

        $artisan->addCommands([$command = new FakeCommandWithInputPrompting()]);

        $command->setLaravel($laravel);

        $exitCode = $artisan->call($command);

        $this->assertTrue($command->prompted);
        $this->assertSame('foo', $command->argument('name'));
        $this->assertSame(0, $exitCode);
    }

@taylorotwell taylorotwell merged commit 3152112 into laravel:12.x Nov 12, 2025
68 checks passed
@seriquynh seriquynh deleted the clean-tests branch November 13, 2025 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants