endeavour-agency/laravel-migration-tests
Composer 安装命令:
composer require endeavour-agency/laravel-migration-tests
包简介
Provides tools for integration testing Laravel migrations.
README 文档
README
This package provides a trait that can be used to test migrations. It allows you to specify which migration you wish to test. It will then create a fresh database, run any migrations up until the specified migration, let you do setup work, run the migration under test, and then let you do your assertions.
Example
<?php declare(strict_types=1); namespace Tests\Migrations; use EndeavourAgency\LaravelMigrationTests\Traits\TestsLaravelMigrationsTrait; use Illuminate\Foundation\Testing\TestCase; use PHPUnit\Framework\Attributes\Test; class ExampleMigrationTest extends TestCase { use TestsLaravelMigrationsTrait; #[Test] public function it_tests_a_migration_using_the_test_migration_method(): void { $this->testMigration( '2024_05_29_083854_rename_birth_day_column_to_date_of_birth_on_users_table', setup: function () { // Setup DB::table('users')->insert([ 'id' => 15, 'email' => 'foo@bar.com', 'birth_day' => '1990-02-01', ]); }, tests: function () { // Tests static::assertDatabaseHas('users', [ 'id' => 15, 'date_of_birth' => '1990-02-01', ]); } ); } #[Test] public function it_tests_a_migration_using_convenience_methods(): void { $this->runMigrationsBefore('2024_05_29_083854_rename_birth_day_column_to_date_of_birth_on_users_table'); // Setup DB::table('users')->insert([ 'id' => 15, 'email' => 'foo@bar.com', 'birth_day' => '1990-02-01', ]); $this->runNextMigration(); // Tests static::assertDatabaseHas('users', [ 'id' => 15, 'date_of_birth' => '1990-02-01', ]); } }
Getting started
To get started, simply install the package.
composer require --dev endeavour-agency/laravel-migration-tests
Then use EndeavourAgency\LaravelMigrationTests\Traits\TestsLaravelMigrationsTrait in your test class.
Important notes
Testing migrations can be extremely helpful when you are doing complicated database data or structure mutations. It also makes it possible to write your migrations in a test-driven way. However, it is advisable to delete migration tests from your test suite after the migrations have run on production, as these tests are slow of nature. This is because they need to tear down your entire database before it can run its assertions.
endeavour-agency/laravel-migration-tests 适用场景与选型建议
endeavour-agency/laravel-migration-tests 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.7k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2024 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「migrations」 「test」 「query」 「migration」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 endeavour-agency/laravel-migration-tests 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 endeavour-agency/laravel-migration-tests 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 endeavour-agency/laravel-migration-tests 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Testing Suite For Lumen like Laravel does.
Store your language lines in the database, yaml or other sources
Symfony ClickhouseMigrationsBundle
Very simple SQL-based database migrations tool - a heavily stripped down fork of robmorgan/phinx
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
统计信息
- 总下载量: 3.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-21