master

laravel/framework

Last updated at: 29/12/2023 09:23

CanConfigureMigrationCommands.php

TLDR

The CanConfigureMigrationCommands.php file contains a trait called CanConfigureMigrationCommands. This trait provides methods for configuring migration commands in Laravel testing.

Methods

migrateFreshUsing

This method returns an array of parameters that should be used when running the migrate:fresh command. It includes options for dropping views and types, as well as an optional seeder option.

shouldDropViews

This method determines if views should be dropped when refreshing the database. It returns a boolean value.

shouldDropTypes

This method determines if types should be dropped when refreshing the database. It returns a boolean value.

shouldSeed

This method determines if the seed task should be run when refreshing the database. It returns a boolean value.

seeder

This method determines the specific seeder class that should be used when refreshing the database. It returns the seeder class if it exists, otherwise it returns false.

<?php

namespace Illuminate\Foundation\Testing\Traits;

trait CanConfigureMigrationCommands
{
    /**
     * The parameters that should be used when running "migrate:fresh".
     *
     * @return array
     */
    protected function migrateFreshUsing()
    {
        $seeder = $this->seeder();

        return array_merge(
            [
                '--drop-views' => $this->shouldDropViews(),
                '--drop-types' => $this->shouldDropTypes(),
            ],
            $seeder ? ['--seeder' => $seeder] : ['--seed' => $this->shouldSeed()]
        );
    }

    /**
     * Determine if views should be dropped when refreshing the database.
     *
     * @return bool
     */
    protected function shouldDropViews()
    {
        return property_exists($this, 'dropViews') ? $this->dropViews : false;
    }

    /**
     * Determine if types should be dropped when refreshing the database.
     *
     * @return bool
     */
    protected function shouldDropTypes()
    {
        return property_exists($this, 'dropTypes') ? $this->dropTypes : false;
    }

    /**
     * Determine if the seed task should be run when refreshing the database.
     *
     * @return bool
     */
    protected function shouldSeed()
    {
        return property_exists($this, 'seed') ? $this->seed : false;
    }

    /**
     * Determine the specific seeder class that should be used when refreshing the database.
     *
     * @return mixed
     */
    protected function seeder()
    {
        return property_exists($this, 'seeder') ? $this->seeder : false;
    }
}