illuminated/testing-tools
Composer 安装命令:
composer require --dev illuminated/testing-tools
包简介
Laravel-specific Testing Helpers and Assertions.
README 文档
README
Laravel Testing Tools
Laravel-specific Testing Helpers and Assertions.
| Laravel | Testing Tools |
|---|---|
| 12.x | 12.x |
| 11.x | 11.x |
| 10.x | 10.x |
| 9.x | 9.x |
| 8.x | 8.x |
| 7.x | 7.x |
| 6.x | 6.x |
| 5.8.* | 5.8.* |
| 5.7.* | 5.7.* |
| 5.6.* | 5.6.* |
| 5.5.* | 5.5.* |
| 5.4.* | 5.4.* |
| 5.3.* | 5.3.* |
| 5.2.* | 5.2.* |
| 5.1.* | 5.1.* |
Usage
-
Install the package via Composer:
composer require --dev illuminated/testing-tools
-
Use
Illuminated\Testing\TestingToolstrait:use Illuminated\Testing\TestingTools; abstract class TestCase extends Illuminate\Foundation\Testing\TestCase { use TestingTools; // ... }
-
Use any of the provided helpers and assertions in your tests:
class ExampleTest extends TestCase { #[Test] public function it_has_lots_of_useful_assertions() { $this->assertDatabaseHasMany('posts', [ ['title' => 'Awesome!'], ['title' => 'Check multiple rows'], ['title' => 'In one simple assertion 🤟'], ]); } }
Available helpers
Feel free to contribute.
Available assertions
Feel free to contribute.
Helpers
ApplicationHelpers
emulateLocal()
Emulate that application is running on the local environment:
$this->emulateLocal();
emulateProduction()
Emulate that application is running on the production environment:
$this->emulateProduction();
emulateEnvironment()
Emulate that application is running on the given environment:
$this->emulateEnvironment('demo');
Assertions
CollectionAsserts
assertCollectionsEqual()
Assert that the given collections are equal based on the specified key:
$this->assertCollectionsEqual($collection1, $collection2, 'id');
assertCollectionsNotEqual()
Assert that the given collections are not equal based on the specified key:
$this->assertCollectionsNotEqual($collection1, $collection2, 'id');
DatabaseAsserts
assertDatabaseHasTable()
Assert that the database has the given table:
$this->assertDatabaseHasTable('users');
assertDatabaseMissingTable()
Assert that the database doesn't have the given table:
$this->assertDatabaseMissingTable('unicorns');
assertDatabaseHasMany()
Assert that the database has all the given rows:
$this->assertDatabaseHasMany('posts', [ ['title' => 'First Post'], ['title' => 'Second Post'], ['title' => 'Third Post'], ]);
assertDatabaseMissingMany()
Assert that the database doesn't have all the given rows:
$this->assertDatabaseMissingMany('posts', [ ['title' => 'Fourth Post'], ['title' => 'Fifth Post'], ]);
FilesystemAsserts
assertDirectoryEmpty()
Assert that the given directory is empty:
$this->assertDirectoryEmpty('./my/dir/');
assertDirectoryNotEmpty()
Assert that the given directory is not empty:
$this->assertDirectoryNotEmpty('./my/dir/');
assertFilesCount()
Assert that directory has the given number of files:
$this->assertFilesCount('./my/dir/', 3);
assertNotFilesCount()
Assert that directory doesn't have the given number of files:
$this->assertNotFilesCount('./my/dir/', 5);
LogFileAsserts
seeLogFile()
Assert that the given log file exists.
The path is relative to the storage/logs folder:
$this->seeLogFile('example.log');
dontSeeLogFile()
Assert that the given log file doesn't exist.
The path is relative to the storage/logs folder:
$this->dontSeeLogFile('foo.log');
seeInLogFile()
Assert that the log file contains the given message.
The path is relative to the storage/logs folder:
$this->seeInLogFile('example.log', 'Sample log message!');
Also, you can specify an array of messages:
$this->seeInLogFile('example.log', [ 'Sample log message 1!', 'Sample log message 2!', 'Sample log message 3!', ]);
You can use these placeholders in messages:
%datetime%- any datetime string.
$this->seeInLogFile('example.log', '[%datetime%]: Sample log message!');
dontSeeInLogFile()
Assert that the log file doesn't contain the given message.
The path is relative to the storage/logs folder:
$this->dontSeeInLogFile('example.log', 'Non-existing log message!');
Also, you can specify an array of messages:
$this->dontSeeInLogFile('example.log', [ 'Non-existing log message 1!', 'Non-existing log message 2!', 'Non-existing log message 3!', ]);
ScheduleAsserts
seeScheduleCount()
Assert that schedule count equals to the given value:
$this->seeScheduleCount(3);
dontSeeScheduleCount()
Assert that schedule count doesn't equal to the given value:
$this->dontSeeScheduleCount(5);
seeInSchedule()
Assert that the given command is scheduled:
$this->seeInSchedule('foo', 'everyFiveMinutes'); $this->seeInSchedule('bar', 'hourly'); $this->seeInSchedule('baz', 'twiceDaily');
Also, you can use cron expressions:
$this->seeInSchedule('foo', '*/5 * * * * *'); $this->seeInSchedule('bar', '0 * * * * *'); $this->seeInSchedule('baz', '0 1,13 * * * *');
dontSeeInSchedule()
Assert that the given command is not scheduled:
$this->dontSeeInSchedule('foo');
Sponsors
License
Laravel Testing Tools is open-sourced software licensed under the MIT license.
illuminated/testing-tools 适用场景与选型建议
illuminated/testing-tools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.84k 次下载、GitHub Stars 达 54, 最近一次更新时间为 2016 年 12 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「helpers」 「testing」 「tools」 「laravel」 「assertions」 「assertion-methods」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 illuminated/testing-tools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 illuminated/testing-tools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 illuminated/testing-tools 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
A Laravel package to retrieve data from Google Search Console
Testing Suite For Lumen like Laravel does.
The PHP SDK for Checkmango
HTML and form generation
GHT D-Tools Bundle
统计信息
- 总下载量: 21.84k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 54
- 点击次数: 8
- 依赖项目数: 19
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-12-08



