[Bug]: extend(RefreshDatabase::class) refreshes local database
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 11.7k
- Forks
- 538
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 8
Description
What Happened
When i use pest()->extend(Tests\TestCaseUnit::class)->in('Unit'); in my Pest.php when i run my tests it refreshes my database that i have configured in .env, even when my test database i have theses environment variables inside my phpunit.xml
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
How to Reproduce
On a Laravel application using Pest, add the following to your Pest.php
pest()->extend(Tests\TestCaseUnit::class)->extend(RefreshDatabase::class);
Set the values in phpunit.xml
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
or .env.testing should have
DB_CONNECTION=sqlite
DB_DATABASE=:memory:
Then when running tests, it should refresh the database used in your .env
Sample Repository
No response
Pest Version
4.4.2
PHP Version
8.4
Operation System
macOS
Notes
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Pest.php extension using Tests\TestCaseUnit and RefreshDatabase, then inspect how environment values from phpunit.xml or .env.testing are applied during the test run. Reproduce with SQLite :memory: settings and verify that RefreshDatabase does not refresh the database configured in .env.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- laravel, php
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100