This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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