Skip to content

Default phpunit.xml configuration invalid for testing and does not match the documentation. #773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bredmor opened this issue Mar 7, 2025 · 3 comments

Comments

@bredmor
Copy link

bredmor commented Mar 7, 2025

Sail Version

1.41

Laravel Version

12.0

PHP Version

8.3.14

Operating System

Windows (WSL)

OS Version

10 (Build 19045.5371)

Description

After installing a new Laravel 12 project with PHPUnit as the testing framework and adding Laravel sail, configured with MariaDB as the database server, attempting to run sail artisan test or sail test results in 100% failure, as Laravel attempts to connect to MariaDB specifying a database named :memory:, instead of a named testing database or an in-memory database.

newproject-mariadb-1       | 2025-03-07  6:24:12 9 [Warning] Access denied for user 'sail'@'%' to database ':memory:'
(repeated 27x,)

The documentation for sail, in Laravel version 12 reads:

By default, Sail will create a dedicated testing database so that your tests do not interfere with the current state of your database. In a default Laravel installation, Sail will also configure your phpunit.xml file to use this database when executing your tests: <env name="DB_DATABASE" value="testing"/>

However, when inspecting the phpunit.xml file in the project after installing sail, the value for that env tag still reads :memory:, the default value from the Laravel installation.

After changing the value to testing and running sail artisan test, PHPUnit connects to MariaDB and uses the testing database as described, leading to no errors.

Steps To Reproduce

  1. Install a new Laravel 12 project (in this case, I used the composer installer, v 5.13.0, selecting Vue, Laravel's built-in authentication and PHPUnit at their respective prompts)
  2. Install Laravel Sail, (I chose MariaDB, Redis, Mailpit and Selenium at the services prompt).
  3. Run ./vendor/bin/sail up and wait for all services to be available.
  4. In another console window, run sail artisan test or sail test
  5. Observe the described failure.
@bredmor
Copy link
Author

bredmor commented Mar 7, 2025

I did not observe any errors from the InteractsWithDockerComposeServices.php method configurePhpUnit() when running php artisan sail:install, so I am at a loss as to why it didn't properly replace this value.

Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@ivan-odintsov
Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

There are at least 2 ways:

  • fix tests config :memory: => testing
  • fix tests to use correct db driver from config (currently - :memory:)

Who should make the decision?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants