pestphp / pestphp/pest

[Bug]: extend(RefreshDatabase::class) refreshes local database

Open
#1,663 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.