Čamo wrote a reply+100 XP
4mos ago
No I do not see the event if the command is test. What version of Laravel do you have? Any other command works as expected but not php artisan test.
Čamo wrote a reply+100 XP
4mos ago
This is not true it is related only to commands tests - when test testing some command
Čamo wrote a reply+100 XP
4mos ago
As I found out the CommandFinished is not allowed by default in Laravel 12 in tests https://laravel.com/docs/12.x/console-tests#console-events It has to be allowed by adding trait use WithConsoleEvents. But it does not work although I add the trait to the script.
Čamo wrote a reply+100 XP
4mos ago
No success. This implementation behave the same way. As I run any command like cache:clear it works but as I run test it does not log anything.
Čamo wrote a reply+100 XP
4mos ago
Did you try also the Listener class? Do you have the same behaviours with test command?
Čamo wrote a reply+100 XP
4mos ago
Thank you very much, i will check it as soon as possible.
Čamo wrote a reply+100 XP
5mos ago
No Event::fake() is not in any of tests
Čamo started a new conversation+100 XP
5mos ago
Hi I tried to create new discussion here and made some mistakes so the submit returns an errors. I forget to choose channel or title second time... But if any error occures second submit returns error with recaptcha so it is impossible to submit the form. Secondly I do not see any recaptcha here.
Čamo started a new conversation+100 XP
5mos ago
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...
}
}
}
Čamo liked a comment+100 XP
5mos ago
Do not use the assertStatus method, instead use a generic assertion where you can specify the failure message:
foreach ($this->main_pages as $page) {
$response = $this->get($page);
\PHPUnit\Framework\Assert::assertTrue(
$response->getStatusCode() === 200,
"Unable to reach page: {$page}"
);
}
Čamo wrote a reply+100 XP
6mos ago
I am facing the same problem right now. It seems there is still no solution on framework level. What I found it this blog. did not test it yet but hope it will help https://sarahjting.com/blog/laravel-paratest-multiple-db-connections