mnabialek/laravel-quick-migrations
Composer 安装命令:
composer require mnabialek/laravel-quick-migrations
包简介
Run Laravel tests quicker
关键字:
README 文档
README
This package is intended to improve speed of Laravel tests that needs to use migrations. In case you use Laravel's DatabaseMigrations trait (especially in Browser tests) you might be interested in using this package to save a lot of time.
Be aware this package doesn't improve speed of normal migrations you apply to database - it should be used only if have tests in your application and you want to improve their speed.
Installation
-
Run
composer require mnabialek/laravel-quick-migrations --devin console to install this module (Notice
--devflag - it's recommended to use this package only for development). -
Run:
php artisan vendor:publish
and choose the number matching
"Mnabialek\LaravelQuickMigrations\Providers\ServiceProvider"provider.By default you should not edit published file because all the settings are loaded from
.envfile by default.Depending on your needs you might add now into
.env(or other env files used for tests):QUICK_MIGRATIONS_ENABLED=true QUICK_MIGRATIONS_DUMP_FILE="/custom/directory/custom_filename.sql"
and customize it with your own values. Keep if mind if you set
QUICK_MIGRATIONS_ENABLEDyou will automatically use default Laravel migrations again. -
Update all your tests where you use
DatabaseMigrationstrait withQuickDatabaseMigrations. You should add import line into those files too:use Mnabialek\LaravelQuickMigrations\QuickDatabaseMigrations;
-
Run:
php artisan migrate:fresh --database=selected_sql_connection
into empty database. Of course as
selected_sql_connectionyou should use connection you really use in your app (usuallymysqlormysql_testing).Now you can manually dump structure of this database into single file (or use
mysqldump) and save file asstorage/tests/dump.sql(If you set custom value ofQUICK_MIGRATIONS_DUMP_FILEin your env file then you should of course put it into your custom location) -
Run your tests and enjoy!
Benchmarks
My test suite (real application) had 53 Laravel Dusk tests with 890 assertions running in Docker container. Database had 93 migrations.
| Run | DatabaseMigrations | QuickDatabaseMigrations | Difference |
|---|---|---|---|
| 1st | 24.7 min (28s/test) | 8.29 min (9.4s/test) | 16.41 min (2.98 times faster) |
| 2nd | 25.08 min (28.4s/test) | 9.23 min (10.45s/test) | 15.85 min (2.72 times faster) |
| 3rd | 24.37 min (27.57s/test) | 7.92 min (8.97s/test) | 16.45 min (3.08 times faster) |
As you see in real-application scenario difference is quite impressive. Using modified trait makes tests running almost 3 times faster comparing to original tests.
Of course in your case results might be different. A lot of depends on migrations you have in your app - how long they take by default. For example assuming you have 100 tests using migrations and applying your migrations takes 10 seconds (for each test) and using your dump would take 6 seconds (for each test) then you would save 100 * 4 seconds that gives 6.66 minutes each time you are running your tests. As you see in my scenario difference was much bigger.
Cons
- You need to manually update dump whenever you add/change migrations. But assuming you are using tests it might be really worth it to spend < 1 minute for dumping fresh migrations to save hundreds of minutes.
- After running tests in your database you have data you created during your tests. From my point of view, if you are using database for tests only you should not care much about it. But of course you can create command that will always remove everything from your database after completing tests if you really need it.
Authors
Author of this package is Marcin Nabiałek and Contributors
Changes
All changes are listed in Changelog
License
This package is licenced under the MIT license.
mnabialek/laravel-quick-migrations 适用场景与选型建议
mnabialek/laravel-quick-migrations 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.09k 次下载、GitHub Stars 达 22, 最近一次更新时间为 2018 年 07 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「laravel migrations」 「laravel dusk speed」 「laravel dusk performance」 「laravel migrations performance」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mnabialek/laravel-quick-migrations 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mnabialek/laravel-quick-migrations 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mnabialek/laravel-quick-migrations 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony ClickhouseMigrationsBundle
Very simple SQL-based database migrations tool - a heavily stripped down fork of robmorgan/phinx
Easily run Laravel Dusk tests on BrowserStack.
Laravel table comments loader (part of Diplodocker project)
Run Dusk tests in Opera
A lightweight, secure-by-default PHP microframework built on Slim – providing Laravel-like features (ORM, authentication, migrations, caching) without the bloat. Perfect for building REST APIs and small-to-medium PHP applications.
统计信息
- 总下载量: 11.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 22
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-07-22