PHPackages                             michaeljennings/refresh-database - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. michaeljennings/refresh-database

ActiveLibrary[Testing &amp; Quality](/categories/testing)

michaeljennings/refresh-database
================================

A package to speed up your laravel database tests by only running the migrations once

v2.1.1(1y ago)31.9k2[1 issues](https://github.com/michaeljennings/refresh-database/issues)MITPHPPHP ^7.2 || ^8.0

Since Oct 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/michaeljennings/refresh-database)[ Packagist](https://packagist.org/packages/michaeljennings/refresh-database)[ RSS](/packages/michaeljennings-refresh-database/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (16)Used By (0)

Refresh Database [![Build Status](https://camo.githubusercontent.com/f633b62fc11ee1564a48009dbe412bdf55bb7335ba0c1320e7d96569270262c8/68747470733a2f2f7472617669732d63692e6f72672f6d69636861656c6a656e6e696e67732f726566726573682d64617461626173652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/michaeljennings/refresh-database) [![Latest Stable Version](https://camo.githubusercontent.com/bcbbc7b2037ae6a7f397a5031df0f9d14a950880009b12f504c564a2743bfedf/68747470733a2f2f706f7365722e707567782e6f72672f6d69636861656c6a656e6e696e67732f726566726573682d64617461626173652f762f737461626c65)](https://packagist.org/packages/michaeljennings/refresh-database) [![Coverage Status](https://camo.githubusercontent.com/f6a9f6f27b831dcb04aadceb8d48066d4019794c6757b9fe0d42abf555d8cf97/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d69636861656c6a656e6e696e67732f726566726573682d64617461626173652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/michaeljennings/refresh-database?branch=master)
=============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#refresh-database---)

When running database tests in laravel one of the biggest overheads is running all of your migrations, the bigger your application gets the longer it takes.

This package speeds up your tests by running the migrations once into an sqlite file, then before each test rather than running migrations it loads the database structure from a database dump.

At the minute this package only works with phpunit and sqlite.

- [Version Compatibility](#version-compatibility)
- [Installation](#installation)
- [Usage](#usage)
    - [Multiple Connections](#multiple-connections)
    - [Service Providers](#service-providers)
- [Environments](#environments)
- [Migration Cache](#migration-cache)

Version Compatibility
---------------------

[](#version-compatibility)

LaravelRefresh Database5.x1.x6.x1.x7.x2.xInstallation
------------

[](#installation)

To install the package run:

```
composer require michaeljennings/refresh-database --dev

```

Or add `michaeljennings/refresh-database` to the require-dev section of your `composer.json`.

```
...
"require-dev": {
  "michaeljennings/refresh-database": "^2.0"
},
...
```

Then run `composer update` to install the package.

Usage
-----

[](#usage)

Firstly we need to tell phpunit to bootstrap from the package `bootstrap.php` file.

```

      tests

```

By default the bootstrapper will look for a config file called `.refresh-database.yml` at the same level as your vendor directory.

So your project may looks something like this:

```
tests/
vendor/
.refresh-database.yml

```

In the `.refresh-database.yml` you can define the directories we should load migrations from and where the directory to store the database dump in.

A simple config file will look like the following:

```
migrations:
  - database/migrations
  - vendor/other/package/database/migrations

output: tests
```

When you run your tests we will create a `.database` directory in the output directory. All of the migrations will be run into a sqlite database and then a database dump will be taken for the database structure.

Once you have your config setup you then just need to use the `MichaelJennings\RefreshDatabase\RefreshDatabase` trait in your test or test case.

```
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use MichaelJennings\RefreshDatabase\RefreshDatabase;

class TestCase extends BaseTestCase
{
    use RefreshDatabase;
}
```

### Multiple Connections

[](#multiple-connections)

Some systems require you to run migrations into multiple databases, e.g. a multi-tenanted system.

To migrate to multiple database connections you can set the connections property in your `.refresh-database.yml` file.

Below is a config file with two database connections; shared, and tenant.

```
connections:
  shared:
    migrations:
      - database/migrations
      - vendor/other/package/database/migrations
  tenant:
    migrations:
      - database/migrations/tenant

output: tests
```

The connection key must be the name of a database connection in your laravel app.

For the config file above you would have to set two database connections; one called shared, and another called tenant.

```
return [
  ...
  'connections' => [
    'shared' => [
      'driver' => 'sqlite',
        'database' => ':memory:',
        'prefix' => '',
      ],
      'tenant' => [
        'driver' => 'sqlite',
        'database' => ':memory:',
        'prefix' => '',
      ],
  ]
  ...
]
```

### Service Providers

[](#service-providers)

In your application you may have migrations that rely on a service provider being registered, because this package creates it's own application instance you will need to tell it which service providers to register.

To register your service providers you set the providers property in your `.refresh-database.yml` file.

Below is an example config file where we are loading a utility service provider.

```
migrations:
  - database/migrations
  - vendor/other/package/database/migrations

providers:
  - Database\UtilityServiceProvider

output: tests
```

Environments
------------

[](#environments)

Occasionally you might find you to want to disable the database dump in certain environments.

To disable the database dump you can set a `DUMP_DATABASE` environment variable and set it to false.

```

      tests

```

Migration Cache
---------------

[](#migration-cache)

By default this package will cache the contents of your migrations so that it only rebuilds the database if it needs to.

If you want to rebuild the database each time you run your tests you set the `cache_migrations` property to false in your .refresh-database.yml file.

```
migrations:
  - database/migrations
  - vendor/other/package/database/migrations

output: tests
cache_migrations: false
```

If you have setup multiple database connections you only need to specify the `cache_migrations` property once.

```
connections:
  shared:
    migrations:
      - database/migrations
      - vendor/other/package/database/migrations
  tenant:
    migrations:
      - database/migrations/tenant

output: tests
cache_migrations: false
```

If you find the package is not rebuilding the database when you think it should be delete the .database directory from your output directory.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~172 days

Recently: every ~429 days

Total

14

Last Release

545d ago

Major Versions

v1.5.1 → v2.0.02020-03-10

PHP version history (4 changes)v1.0.0PHP &gt;=7.0

v1.0.3PHP &gt;=7.1

v2.0.0PHP &gt;=7.2

v2.1.0PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/df807d0371b1b265ea1becedfa4001428f278e7632c6d175e2afb2921f5788a3?d=identicon)[michaeljennings](/maintainers/michaeljennings)

---

Top Contributors

[![michaeljennings](https://avatars.githubusercontent.com/u/5189701?v=4)](https://github.com/michaeljennings "michaeljennings (51 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/michaeljennings-refresh-database/health.svg)

```
[![Health](https://phpackages.com/badges/michaeljennings-refresh-database/health.svg)](https://phpackages.com/packages/michaeljennings-refresh-database)
```

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[behat/behat

Scenario-oriented BDD framework for PHP

4.0k96.8M2.0k](/packages/behat-behat)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k438.5k29](/packages/tightenco-jigsaw)[laravel/vapor-cli

The Laravel Vapor CLI

31310.7M8](/packages/laravel-vapor-cli)[orchestra/workbench

Workbench Companion for Laravel Packages Development

8217.0M43](/packages/orchestra-workbench)[acquia/orca

A tool for testing a company's software packages together in the context of a realistic, functioning, best practices Drupal build

32902.4k](/packages/acquia-orca)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
