fangx/testing-migration-command

v1.0.2 2020-09-08 03:10 UTC

This package is auto-updated.

Last update: 2024-09-08 12:22:26 UTC


README

Laravel 默认的迁移命令只能执行第一层目录下的迁移文件,本扩展支持多层目录。应用场景是在进行单元测试的时候,可以自动执行所有的迁移文件

安装

通过 Composer

composer require fangx/testing-migration-command --dev

使用方法

在所有的 migrate 命令前加上 testing- 即可调用本扩展改写的 migrate 命令,例如

php artisan testing-migrate
php artisan testing-migrate:rollback

在 tests/TestCase.php 中添加以下代码,自动替换单测中的 migrate 相关命令

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Str;

abstract class TestCase extends BaseTestCase
{
    // ...others

    public function artisan($command, $parameters = [])
    {
        if (Str::startsWith($command, ['migrate', 'migration'])) {
            $command = 'testing-' . $command;
        }

        return parent::artisan($command, $parameters);
    }
}