srlabs/laravel-testing-utilities
Composer 安装命令:
composer require --dev srlabs/laravel-testing-utilities
包简介
Helper utilities for testing Laravel Applications
README 文档
README
This package is intended to be a collection of helpful utilities to assist with the development and maintenance of Laravel Applications.
| Laravel Version | Package Version | Packagist Branch |
|---|---|---|
| 7.* | 10.* | "srlabs/laravel-testing-utilities": "~10" |
| 8.* | 11.* | "srlabs/laravel-testing-utilities": "~11" |
| 9.* | 12.* | "srlabs/laravel-testing-utilities": "~12" |
To install this package, run
$ composer require srlabs/laravel-testing-utilities
and then add the service provider to your service providers listing in app/config/app.php
'providers' => [ // ... 'SRLabs\Utilities\UtilitiesServiceProvider' // ... ],
Testing Assistant
This utility makes it easy to implement the testing stratgey described by Chris Duell in his blog post Speeding up PHP unit tests 15 times. When running tests that require the use of a database persistence layer, running migrations and seeding the database for each test can take a very long time. Chris instead suggests creating a sqlite database file ahead of time, and making a new copy of that file for each test instead.
This package provides an artisan command ('utility:testdb') that will run your migrations and seeds and save them to a pre-defined sqlite file. Once that is complete, there is a companion trait that you add to your tests which will copy the staging database file to the testing database location when running tests.
You need to define a sqlite database connection in your config/database.php file. The connection name can be whatever you would like, but the package will assume a name of 'staging' if you don't provide one.
Default 'staging' connection:
$ php artisan utility:testdb
Custom 'sqlite_testing' connection:
$ php artisan utility:testdb sqlite_testing
You can also specify a Database Seeder class:
$ php artisan utility:testdb sqlite_testing --class="SentinelDatabaseSeeder"
This command will migrate and seed the sqlite database you have specified.
When you are ready to use this new sqlite file in your tests, add the TestingDatabase trait to your test class, and use it as such:
use SRLabs\Utilities\Traits\TestingDatabaseTrait; class FooTest extends TestCase { use TestingDatabaseTrait; public function setUp() { parent::setUp(); $this->prepareDatabase('staging', 'testing'); } public function testSomethingIsTrue() { $this->assertTrue(true); } }
In this example "staging" is the Database connection that represents the pre-compiled sqlite file, and "testing" is a separate connection that represents the database that will be used by the tests. Each time the setUp() method is called, the testing sqlite file will be replaced by the staging sqlite file, effectively resetting your database to a clean starting point.
You may need to do some extra configuration to have phpunit use your "testing" database.
(Optional) Run Automatically When Running PHPUnit
Using this method will have artisan utility:testdb execute before any tests are ran only if there are new migration changes.
1. Create file bootstrap/testing.php:
<?php define('ARTISAN_PATH', realpath(__DIR__ . '/../artisan')); /* |-------------------------------------------------------------------------- | Check for new migrations and reseed if necessary |-------------------------------------------------------------------------- | */ passthru('(php '.ARTISAN_PATH.' migrate:status --database='.(getenv('DB_CONNECTION') ?: 'testing').' | grep -q "| N |") && php '.ARTISAN_PATH.' utility:testdb'); /* |-------------------------------------------------------------------------- | Include Standard Autoload File |-------------------------------------------------------------------------- | */ require __DIR__ . '/autoload.php';
2. Update phpunit.xml
<phpunit ... bootstrap="bootstrap/testing.php" ... > ... <php> ... <!-- Change this to your connection name (if customized) --> <env name="DB_CONNECTION" value="testing"/> </php> </phpunit>
srlabs/laravel-testing-utilities 适用场景与选型建议
srlabs/laravel-testing-utilities 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.92k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2015 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「testing」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 srlabs/laravel-testing-utilities 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 srlabs/laravel-testing-utilities 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 srlabs/laravel-testing-utilities 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing Suite For Lumen like Laravel does.
The PHP SDK for Checkmango
Alfabank REST API integration
The testing extension of TYPO3voilà.
Auto-generate dummy data with realistic relationships per Model-like config classes
Dusk extensions for testing
统计信息
- 总下载量: 11.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-11