Package Data | |
---|---|
Maintainer Username: | AndrewGatenby |
Maintainer Contact: | andrew.gatenby@gmail.com (Andy Gatenby) |
Package Create Date: | 2019-05-23 |
Package Last Update: | 2023-09-13 |
Home Page: | |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2024-11-23 03:23:45 |
Package Statistics | |
---|---|
Total Downloads: | 7,328 |
Monthly Downloads: | 41 |
Daily Downloads: | 1 |
Total Stars: | 1 |
Total Watchers: | 2 |
Total Forks: | 3 |
Total Open Issues: | 0 |
This package is designed to be used within your TestCase class and allows for Lumen applications to create a static SQL dump of a migrated (and seeded) database. It will automatically do this on the first Test run from a TestCase that uses this Trait. Each subsequent Test run will then use the SQL dumped copy of the database.
Install the package via Composer:
composer require --dev andrewgatenby\snapmigrations
After a successful installation, you can add SnapMigration
to your Test classes (potentially a parent class). This
package is designed to replace the regular DatabaseMigrations
class that you might use:
<?php
namespace Tests;
use AndrewGatenby\SnapMigrations\SnapMigrations;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class MyAmazingTestCase extends BaseTestCase
{
use SnapMigrations;
}
The Snap Migration SQL dump itself will be stored in storage/snap_migration.sql
by default, but this can be modified
by use of an environment variable called SNAP_MIGRATION_SQL_FILE
. Note that it would still be within storage/
.
If there is a new database migration created in database/migrations
then Snap Migrations will burst its own cached
copy and generate a new snapshot.
If the Snap Migration gets stuck or out of sync, you can manually delete the file and it will be built afresh.
The SnapMigrations
Trait has its own setUp
method as the main entry point. If your Test classes have their own
setUp
method, then you can alias the SnapMigrations::setUp
method, similar to this:
<?php
namespace Tests;
use AndrewGatenby\SnapMigrations\SnapMigrations;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class MyAmazingTestCase extends BaseTestCase
{
use SnapMigrations {
setUp as setUpSnapMigrations;
}
public function setUp()
{
// run setUp for Snap Migrations, which also calls parent::setUp()
$this->setUpSnapMigrations();
// my regular setUp tasks for MyAmazingTestCase
}
}
This package was inspired by the awesome looking Snipe Migrations that I'd tried to make use of first, but needed a Lumen-friendly implementation. It also uses the excellent MySQL Dump package.