illuminated / testing-tools
Laravel 特定的测试辅助工具和断言。
10.0.0
2024-03-06 15:32 UTC
Requires
- php: ^8.1
- illuminate/database: ^10.0
- illuminate/support: ^10.0
- mockery/mockery: ^1.5.1
Requires (Dev)
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^10.5
- dev-master
- 10.x-dev
- 10.0.0
- 9.x-dev
- 9.6.0
- 9.5.0
- 9.4.0
- 9.3.0
- 9.2.0
- 9.1.0
- 9.0.0
- 8.x-dev
- 8.1.0
- 8.0.0
- 7.x-dev
- 7.1.0
- 7.0.0
- 6.x-dev
- 6.2.0
- 6.1.0
- 6.0.0
- 5.8.x-dev
- 5.8.0
- 5.7.x-dev
- 5.7.4
- 5.7.3
- 5.7.2
- 5.7.1
- 5.7.0
- 5.6.x-dev
- 5.6.4
- 5.6.3
- 5.6.2
- 5.6.1
- 5.6.0
- 5.5.x-dev
- 5.5.5
- 5.5.4
- 5.5.3
- 5.5.2
- 5.5.1
- 5.5.0
- 5.4.x-dev
- 5.4.2
- 5.4.1
- 5.4.0
- 5.3.x-dev
- 5.3.2
- 5.3.1
- 5.3.0
- 5.2.x-dev
- 5.2.2
- 5.2.1
- 5.2.0
- 5.1.x-dev
- 5.1.2
- 5.1.1
- 5.1.0
- 0.6.6
- 0.6.5
- 0.6.4
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.11
- 0.5.10
- 0.5.9
- 0.5.8
- 0.5.7
- 0.5.6
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.5
- 0.4.4
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
This package is auto-updated.
Last update: 2024-09-06 16:40:37 UTC
README
Laravel 测试工具
Laravel 特定的测试辅助工具和断言。
用法
-
使用 Composer 安装包
composer require --dev illuminated/testing-tools
-
使用
Illuminated\Testing\TestingTools
特性use Illuminated\Testing\TestingTools; abstract class TestCase extends Illuminate\Foundation\Testing\TestCase { use TestingTools; // ... }
-
在测试中使用提供的辅助工具和断言
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 🤟'], ]); } }
可用辅助工具
欢迎贡献力量。
可用断言
欢迎贡献力量。
辅助工具
应用程序辅助工具
emulateLocal()
模拟应用程序在 local
环境上运行
$this->emulateLocal();
emulateProduction()
模拟应用程序在 production
环境上运行
$this->emulateProduction();
emulateEnvironment()
模拟应用程序在给定环境中运行
$this->emulateEnvironment('demo');
断言
集合断言
assertCollectionsEqual()
断言基于指定键的给定集合是否相等
$this->assertCollectionsEqual($collection1, $collection2, 'id');
assertCollectionsNotEqual()
断言基于指定键的给定集合是否不相等
$this->assertCollectionsNotEqual($collection1, $collection2, 'id');
数据库断言
assertDatabaseHasTable()
断言数据库包含给定的表
$this->assertDatabaseHasTable('users');
assertDatabaseMissingTable()
断言数据库不包含给定的表
$this->assertDatabaseMissingTable('unicorns');
assertDatabaseHasMany()
断言数据库包含所有给定的行
$this->assertDatabaseHasMany('posts', [ ['title' => 'First Post'], ['title' => 'Second Post'], ['title' => 'Third Post'], ]);
assertDatabaseMissingMany()
断言数据库不包含所有给定的行
$this->assertDatabaseMissingMany('posts', [ ['title' => 'Fourth Post'], ['title' => 'Fifth Post'], ]);
文件系统断言
assertDirectoryEmpty()
断言给定的目录为空
$this->assertDirectoryEmpty('./my/dir/');
assertDirectoryNotEmpty()
断言给定的目录不为空
$this->assertDirectoryNotEmpty('./my/dir/');
assertFilesCount()
断言目录包含给定数量的文件
$this->assertFilesCount('./my/dir/', 3);
assertNotFilesCount()
断言目录不包含给定数量的文件
$this->assertNotFilesCount('./my/dir/', 5);
日志文件断言
seeLogFile()
断言给定的日志文件存在。
路径相对于 storage/logs
文件夹
$this->seeLogFile('example.log');
dontSeeLogFile()
断言给定的日志文件不存在。
路径相对于 storage/logs
文件夹
$this->dontSeeLogFile('foobarbaz.log');
seeInLogFile()
断言日志文件包含给定的消息。
路径相对于 storage/logs
文件夹
$this->seeInLogFile('example.log', 'Sample log message!');
您还可以指定消息数组
$this->seeInLogFile('example.log', [ 'Sample log message 1!', 'Sample log message 2!', 'Sample log message 3!', ]);
您可以在消息中使用以下占位符
%datetime%
- 任何日期时间字符串。
$this->seeInLogFile('example.log', '[%datetime%]: Sample log message!');
dontSeeInLogFile()
断言日志文件不包含给定的消息。
路径相对于 storage/logs
文件夹
$this->dontSeeInLogFile('example.log', 'Non-existing log message!');
您还可以指定消息数组
$this->dontSeeInLogFile('example.log', [ 'Non-existing log message 1!', 'Non-existing log message 2!', 'Non-existing log message 3!', ]);
调度断言
seeScheduleCount()
断言调度计数等于给定的值
$this->seeScheduleCount(3);
dontSeeScheduleCount()
断言调度计数不等于给定的值
$this->dontSeeScheduleCount(5);
seeInSchedule()
断言给定的命令已调度
$this->seeInSchedule('foo', 'everyFiveMinutes'); $this->seeInSchedule('bar', 'hourly'); $this->seeInSchedule('baz', 'twiceDaily');
您还可以使用 cron 表达式
$this->seeInSchedule('foo', '*/5 * * * * *'); $this->seeInSchedule('bar', '0 * * * * *'); $this->seeInSchedule('baz', '0 1,13 * * * *');
dontSeeInSchedule()
断言给定的命令未调度
$this->dontSeeInSchedule('foobarbaz');
赞助商
许可证
Laravel 测试工具是开源软件,许可协议为 MIT 协议。