Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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'
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