PHPackages                             jhwelch/pest-plugin-laravel-migrations - 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. jhwelch/pest-plugin-laravel-migrations

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

jhwelch/pest-plugin-laravel-migrations
======================================

A Pest PHP plugin that lets you test Laravel migrations with a simple and straight forward syntax.

02PHP

Since Sep 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/JHWelch/pest-plugin-laravel-migrations)[ Packagist](https://packagist.org/packages/jhwelch/pest-plugin-laravel-migrations)[ RSS](/packages/jhwelch-pest-plugin-laravel-migrations/feed)WikiDiscussions main Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Pest Plugin for Laravel Migrations
==================================

[](#pest-plugin-for-laravel-migrations)

A Pest PHP plugin that lets you test Laravel migrations with a simple and straight forward syntax.

```
migration('2024_09_12_000000_update_users_table_combine_names', function ($up, $down) {
    $user = User::create([
        'first_name' => 'John',
        'last_name' => 'Doe',
    ]);

    $up();

    expect($user->fresh())
        ->full_name->toEqual('John Doe');

    $down();

    expect($user->fresh())
        ->first_name->toEqual('John')
        ->last_name->toEqual('Doe');
});
```

With Pest and other modern tooling, it is easy to test almost every aspect of a Laravel application. However, one of the places with the greatest permanent data implications remains untested.

*Database migrations.*

Any given test is run against the latest state of a database. This makes it difficult to test any migration that is doing any sort of complicated data migration.

This package seeks to fill that gap.

This package is a **Work In Progress**
--------------------------------------

[](#this-package-is-a-work-in-progress)

Once the package is marked stable it will abide by [Semver](https://semver.org/), however in this period the API is not guaranteed to maintain consistent.

Usage
-----

[](#usage)

This package consists of two Pest functions: `migration` and `migrationFunctions`.

### `migration`

[](#migration)

`migration` is the most straight forward way to write a migration test.

All migrations are run up until the target. The target is then migrated on `$up()` and rolled back with `$down()`, allowing for setup and assertions at each step.

```
use function JHWelch\PestLaravelMigrations\migration;

migration('2024_09_12_000000_migration_name', function ($up, $down) {
    // Setup test Data
    // All migrations up until target have been run

    $up();

    // Run Assertions after migration "up"

    $down();

    // Run Assertions after migration "down"
});
```

If you are only testing the `up()` part of the migration, you can simply exclude the `$down` parameter entirely.

```
migration('2024_09_12_000000_migration_name', function ($up) {
    // Setup test Data
    // All migrations up until target have been run

    $up();

    // Run Assertions after migration "up"
});
```

### `migrationFunctions`

[](#migrationfunctions)

This function is the core of the functionality that `migration` is wrapping, but allows for more customizability.

It returns a two item array with an `$up` and `$down` `Closure`s that trigger each half of the migration.

The easiest way to use this is to destructure the array.

```
use function JHWelch\PestLaravelMigrations\migrationFunctions;

it('tests migrations', () {
    # Test only "up"
    [$up] = migrationFunctions('2024_09_12_000000_migration_name');

    # Test both "up" and "down"
    [$up, $down] = migrationFunctions('2024_09_12_000000_migration_name');
});
```

### More Examples

[](#more-examples)

For more realistic examples see [ExampleUsageTest.php](tests/ExampleUsageTest.php).

###  Health Score

14

—

LowBetter than 1% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4480375?v=4)[Jordan Welch](/maintainers/JHWelch)[@JHWelch](https://github.com/JHWelch)

---

Top Contributors

[![JHWelch](https://avatars.githubusercontent.com/u/4480375?v=4)](https://github.com/JHWelch "JHWelch (87 commits)")

---

Tags

laravel

### Embed Badge

![Health badge](/badges/jhwelch-pest-plugin-laravel-migrations/health.svg)

```
[![Health](https://phpackages.com/badges/jhwelch-pest-plugin-laravel-migrations/health.svg)](https://phpackages.com/packages/jhwelch-pest-plugin-laravel-migrations)
```

###  Alternatives

[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14429.2M360](/packages/dms-phpunit-arraysubset-asserts)

PHPackages © 2026

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