gregdmat / laravel-test-utilities
此包已被废弃,不再维护。未建议替代包。
v0.3-beta
2020-01-23 20:59 UTC
Requires
- laravel/framework: ^6.0
This package is auto-updated.
Last update: 2021-07-21 21:34:44 UTC
README
composer require gregdmat/laravel-test-utilities
php artisan ltu:intall
断言结构和值
- 基本用法
- 使用ValidatorAsserts特性;
- 调用 $this->assertStructureAndValue($rules, $data);
- 规则类似于Validator,请参阅 https://laravel.net.cn/docs/6.x/validation#manually-creating-validators;
数据案例
This feature provides several scenarios for a data type.
-
修改dataCases配置以删除某些数据案例。
-
可用数据类型。
- 字符串
- 整数
-
基本用法
$teste = new DataCases();
$teste->get([
'attribute' => 'type',
'name' => 'string'
]);
-
可用方法
- get: 返回一个案例数组
$teste->get([ 'attribute' => 'type', 'name' => 'string' ]);
- make: 返回一个模型数组(需要Factory模型,请参阅:https://laravel.net.cn/docs/6.x/database-testing)
$teste->make( [ 'attribute' => 'type', 'name' => 'string' ], Model::class );
- create: 返回一个模型数组并创建在数据库中(需要Factory模型,请参阅:https://laravel.net.cn/docs/6.x/database-testing)
$teste->create( [ 'attribute' => 'type', 'name' => 'string' ], Model::class );
-
选项
在实例化DataCases类时,可以向构造函数传递一个选项数组。
$teste = new DataCases([
'integer' => [
'except' => ['negative', 'positive'],
'positive.min' => 1,
'positive.max' => 3,
]
]);
- 可用选项
- except (array of name cases);
- small.size;
- normal.size;
- long.size;
- negative.min;
- negative.max;
- positive.min
- positive.max
- 可用案例(请参阅配置文件)。