一、为什么会学习这章内容呢,因为遇到这个语句,我应该怎么测试才能报该错误呢
'logo' => 'required|url|max:255'
二、max:value的作用
验证字段必须小于等于value。字符串、数字、数组或是文件大小的计算方式都是用size方式进行估算的
'logo' => $this->faker->url.Str::random(255),
三、补充数据回滚
protected $faker;
public function setUp(): void
{
parent::setUp(); // TODO: Change the autogenerated stub
$this->faker = app(Generator::class); //获取Faker\Generator实例 用于数生成据填充
DB::beginTransaction();
}
protected function tearDown(): void
{
#rollback回滚数据,但是索引不会被删除
DB::rollBack();
parent::tearDown(); // TODO: Change the autogenerated stub
}
/**
* FunctionName:testResetAutoIncrement
* Description: 重置自增索引(保留数据库中原有的数据,重置索引到原始位置)
* CreateTime:2020/9/10 17:14
* UpdateTime:2020/9/10 17:14
* Author: weixin
*/
public function testResetAutoIncrement()
{
$table = 'life_car_brands';
#id倒序
$autoIncrement = DB::table($table)->orderBy('id','desc')->value('id');
#指定索引位置进行索引重置,如数据表中有599条数据,索引值每次重置创建都是从600开始
DB::select('ALTER TABLE `'.$table.'` AUTO_INCREMENT='.($autoIncrement+1));
$this->assertTrue(true);
}