Is there a check to skip a specific migration for unit tests in a migration class?

Published 3 months ago by Roni

For example

 public function up()
    {
        If ( ! <test indicator>){
            // migrate stuff here
        }
    } 


Best Answer (As Selected By Roni)
bobbybouwmann

You can check on environment or check if you currently run the tests

public function up()
{
    if (app()->environment() === 'testing') {
        // Do your thing
    }

    // An alternative would be this
    if (app()->runningUnitTests()) {
        // Do your thing
    }
}
bobbybouwmann

You can check on environment or check if you currently run the tests

public function up()
{
    if (app()->environment() === 'testing') {
        // Do your thing
    }

    // An alternative would be this
    if (app()->runningUnitTests()) {
        // Do your thing
    }
}
Roni
Roni
3 months ago (62,060 XP)

Thanks @bobbybouwmann ! That's perfect!

Please sign in or create an account to participate in this conversation.