Do you have Event::fake(); somewhere in your tests?
Dec 17, 2025
11
Level 3
Laravel 12 CommandFinished does not run for php artisan test
I would like to implement some logic after all tests in Laravel 12 application finished. I found this blog from 2024 https://laravel.com/docs/12.x/events#main-content which is based on CommandFinished native event. So I made a CommandFinishedListener. If I run php artisan event:list I see the lister in the list. So it is obviously registered. If I run any command it works BUT as I run php artisan test the listener does not run. All tests pass but the event does not trigger. Thanks for any help.
<?php
namespace App\Listeners;
use App\Services\BaseService;
use Illuminate\Console\Events\CommandFinished;
use Illuminate\Support\Facades\Log;
class CommandFinishedListener
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}
/**
* Handle the event.
*/
public function handle(CommandFinished $event)
{
Log::info('CommandFinishedListener: ' . $event->command); // Any other command log this line for example php artisan event:list
if ($event->command === 'test') {
// Do something...
}
}
}
Please or to participate in this conversation.