Skip to content

Instantly share code, notes, and snippets.

@aarondfrancis
Created January 10, 2022 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarondfrancis/fd9244cdf2848d0bba07c14bed5a3f56 to your computer and use it in GitHub Desktop.
Save aarondfrancis/fd9244cdf2848d0bba07c14bed5a3f56 to your computer and use it in GitHub Desktop.
<?php
namespace Tests\Unit\Style;
use Illuminate\Database\Migrations\Migrator;
use Illuminate\Foundation\Testing\RefreshDatabase;
use ReflectionClass;
use Tests\TestCase;
class NoDownMigrationsTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function there_are_no_down_migrations()
{
/** @var Migrator $migrator */
$migrator = app('migrator');
$files = $migrator->getMigrationFiles([
$this->app->databasePath() . DIRECTORY_SEPARATOR . 'migrations'
]);
$migrator->requireFiles($files);
foreach ($files as $file) {
$class = $migrator->resolve($migrator->getMigrationName($file));
$reflector = new ReflectionClass($class);
// We don't use down migrations because we don't want to ever run
// `down` in prod, it's too dangerous. If anything from an old
// migration needs to be undone, create a new migration for it.
$this->assertFalse($reflector->hasMethod('down'), get_class($class) . ' migration has a down method. Please remove it.');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment