mohamadtsn/laravel-fast-refresh-database 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mohamadtsn/laravel-fast-refresh-database

最新稳定版本:1.0.2

Composer 安装命令:

composer require mohamadtsn/laravel-fast-refresh-database

包简介

Quickly refresh your large database in tests.

关键字:

README 文档

README

For large databases with more than 100 tables, it is very slow to drop all the tables and migrate again. It is also still very slow to run the truncate query against all the tables. The idea of this package is to truncate only the tables that are involved in that particular test and ignore the rest. This way, only 5 to 6 tables need to be truncated after each test and not 200 tables.

Note that no table gets dropped or migrated. It only runs the truncate table_name query.

Install:

composer require mohamadtsn/laravel-fast-refresh-database --dev

How to Use:

Add the trait to your test class. The package automatically starts watching insert queries before each test (via a PHPUnit @before hook) and truncates only the tables that were touched after each test:

use MohamadTsn\DatabaseFresh\FastRefreshDatabase;

class MyTest extends TestCase
{
    use FastRefreshDatabase;

    public function test_user_can_run()
    {
        // ... your test code
    }
}

Tip: Put the trait on your base Tests\\TestCase to enable it for all tests.

Manual setup (legacy PHPUnit):

If your PHPUnit version does not support @before, you can still invoke the setup helper in setUp():

protected function setUp(): void
{
    parent::setUp();

    // Manually start watching inserts for this test process
    $this->setupDatabaseAndStartWatchingTables();
}

You may also check my other package as well:

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-08