Skip to content

Quick tutorial on how to set up a testing environment in Laravel.

License

Notifications You must be signed in to change notification settings

bartekgdev/test-db-in-laravel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

To ensure that your tests don't interfere with your production database, you can easily switch to a testing database for PHPUnit. Here's a step-by-step guide:

Step 1: Create a Testing Database

Copy and paste your database.sqlite file and rename it to testing.sqlite (or any other name you prefer).

Step 2: Open phpunit.xml

Locate and open the phpunit.xml file in your project.

Step 3: Configure Environment Variable

Add the following environment variable to phpunit.xml:

<env name="DB_DATABASE" value="database/testing.sqlite"/>

This tells PHPUnit to use the testing.sqlite database for testing purposes.

Step 4: Run Your Tests

Run your tests as you normally would. From now on, PHPUnit will use the testing.sqlite database, leaving your production database intact.

By following these simple steps, you can ensure that your tests don't interfere with your production database, and you can test your application with confidence!

About

Quick tutorial on how to set up a testing environment in Laravel.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published