Čamo's avatar

Čamo wrote a reply+100 XP

3mos 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's avatar

Č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's avatar

Č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's avatar

Č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's avatar

Č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's avatar

Čamo wrote a reply+100 XP

4mos ago

Thank you very much, i will check it as soon as possible.

Čamo's avatar

Čamo wrote a reply+100 XP

4mos ago

No Event::fake() is not in any of tests

Čamo's avatar

Čamo started a new conversation+100 XP

4mos 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's avatar

Čamo started a new conversation+100 XP

4mos 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.

Čamo's avatar

Č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's avatar

Čamo wrote a reply+100 XP

5mos 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

Čamo's avatar

Čamo wrote a reply+100 XP

5mos ago

Did you solve this problem? I have the same problem. Only default database connection separate databases. I tried to solve it in config/database.php but can not access the parallel test token.

Čamo's avatar

Čamo liked a comment+100 XP

5mos ago

I've had the same issue in the past, check out the Parallel Testing Hooks---specifically setUpTestDatabase().

Note that the hooks will be called for every process, so if you only want to run something once then you'll need to do something like:

        // Executed when a test database is created...
        ParallelTesting::setUpTestDatabase(function ($database, $token) {
            if ($token === 1) {
                // create databases
            }
        });
Čamo's avatar

Čamo liked a comment+100 XP

5mos ago

Hi !

I'm currently working on an API that needs to have multiple database connections. At the moment it uses : 1 MySQL + 1 PostgreSQL + 1 MongoDB. MySQL and PostgreSQL may be merged in the future, but it will at least keep a MongoDB in parallel of the PostgreSQL. Connection to MongoDB is handled by the jenssegers/mongodb package

This API is tested with Pest, but the current ~90 tests take around 2 minutes to run, and this is about 5% of the total features that will be added. So I wanted to setup parallel testing, but only the MySQL (main database connection) has the testing_X databases created.

Does anyone know what I can override to handle the other connections so that it also creates the testing_X databases on PostgreSQL and MongoDB ?

I've already altered the default TestCase to call a custom migrate:fresh when using the DatabaseMigrations trait, so that it can reset the databases for all three connections (which I know is the main performance issue at the moment in my tests), but I have not been able to find how to intercept the parallel testing setup procedure.