Skip to content

PhpUnit tests: Application Differences in between tests, Artisan commands breaks mocking #55010

@growsphere

Description

@growsphere

Laravel Version

12.2.0

PHP Version

8.2.27

Database Driver & Version

sqlite3 3.37.2

Description

Since laravel11 (at least I couldn't reproduce the issue in L10), I have found some issues in phpunit tests with laravel.

There seem to be substantial differences in the application when the context is a single phpunit test (or the first test
of many when ran together) or a subsequent test. This is most likely due to the way the application is bootstrapped and/or reset between tests.

Tests that succeed in isolation then fail when run together with at least one other test, unless they happen to be the very first test that runs.

Examples:

  • testing how many events are set up in the application schedule only works in the first test that runs
  • mocking dependencies stops working after artisan commands are called from the test code.

In the linked repository (see steps to reproduce) I have provided examples and a more detailed description of the issue.

Steps To Reproduce

Demonstration: https://github.com/growsphere/laravel-bug-report-test-application
Edit: new repo following the requested requirements: https://github.com/growsphere/bug-report

All detailed steps are described in the readme of that repository.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions