承接 plannr/laravel-fast-refresh-database 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

plannr/laravel-fast-refresh-database

Composer 安装命令:

composer require plannr/laravel-fast-refresh-database

包简介

Refresh your database faster than you've ever seen before 🚀

README 文档

README

Have you ever come across an issue where the traditional RefreshDatabase trait takes ages to run tests when you have lots of migrations? If so, you may be after this package!

The Problem

Traditionally, the RefreshDatabase trait will run php artisan migrate:fresh every time you run tests. After the first test, it will use transactions to roll back the data and run the next one, so subsequent tests are fast, but the initial test is slow. This can be really annoying if you are used to running a single test, as it could take seconds to run a single test.

The Solution

You don't need to run php artisan migrate:fresh every time you run tests, only when you add a new migration or change an old one. The FastRefreshDatabase trait will create a checksum of your migrations folder as well as your current Git branch. It will then create a checksum file in your application's storage/app directory. When your migrations change or your branch changes, the checksum won't match the cached one and php artisan migrate:fresh is run.

When you don't make any changes, it will continue to use the same database without refreshing, which can speed up the test time by 100x!

Benchmarks

Running a single test, with about 400 migrations.

Processor Before After
Intel Core i5 30 seconds 100 milliseconds
Apple M1 Pro 5 seconds 100 milliseconds

Installation

Install the package with Composer

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

Adding to your TestCase

Next, just replace the existing RefreshDatabase trait you are using in your TestCase file with the FastRefreshDatabase trait

<?php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
-use Illuminate\Foundation\Testing\RefreshDatabase;
+use Plannr\Laravel\FastRefreshDatabase\Traits\FastRefreshDatabase;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;
-   use RefreshDatabase;
+   use FastRefreshDatabase;
}

Using Pest

Just replace the uses line in your Pest.php file

-use Illuminate\Foundation\Testing\RefreshDatabase;
+use Plannr\Laravel\FastRefreshDatabase\Traits\FastRefreshDatabase;

-uses(RefreshDatabase::class)->in(__DIR__);
uses(FastRefreshDatabase::class)->in('Feature');

Deleting The Migration Checksum

Sometimes you may wish to force-update database migrations, to do this, locate the migration-checksum_{Database Name Slug}.txt file within storage/app.

Customising the checksum file location

You may customise the migration checksum file location and name by extending the trait and overwriting the getMigrationChecksumFile() method.

protected function getMigrationChecksumFile(): string
{
    return storage_path('custom/some-other-file.txt');
}

ParaTest Databases

Parallel testing databases contain tokens that serve as unique identifiers for each test runner. This makes the trait inherently able to support parallel testing without any extra effort, because the database name is stored in the checksum file name.

plannr/laravel-fast-refresh-database 适用场景与选型建议

plannr/laravel-fast-refresh-database 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.57M 次下载、GitHub Stars 达 436, 最近一次更新时间为 2022 年 12 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 plannr/laravel-fast-refresh-database 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 plannr/laravel-fast-refresh-database 我们能提供哪些服务?
定制开发 / 二次开发

基于 plannr/laravel-fast-refresh-database 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.57M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 436
  • 点击次数: 24
  • 依赖项目数: 7
  • 推荐数: 0

GitHub 信息

  • Stars: 436
  • Watchers: 4
  • Forks: 21
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-23