ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
Laravel 附带几个 assert 方法,让测试更简单一点: ### Assert 响应为 OK ~~~ ~~~ public function testMethod() { $this->call('GET', '/'); $this->assertResponseOk(); } ~~~ ~~~ ### Assert 响应的状态码 ~~~ ~~~ $this->assertResponseStatus(403); ~~~ ~~~ ### Assert 响应为重定向 ~~~ ~~~ $this->assertRedirectedTo('foo'); $this->assertRedirectedToRoute('route.name'); $this->assertRedirectedToAction('Controller@method'); ~~~ ~~~ ### Assert 响应的视图包含一些数据 ~~~ ~~~ public function testMethod() { $this->call('GET', '/'); $this->assertViewHas('name'); $this->assertViewHas('age', $value); } ~~~ ~~~ ### Assert Session 包含一些数据 ~~~ ~~~ public function testMethod() { $this->call('GET', '/'); $this->assertSessionHas('name'); $this->assertSessionHas('age', $value); } ~~~ ~~~ ### Assert Session 有错误信息 ~~~ ~~~ public function testMethod() { $this->call('GET', '/'); $this->assertSessionHasErrors(); // Asserting the session has errors for a given key... $this->assertSessionHasErrors('name'); // Asserting the session has errors for several keys... $this->assertSessionHasErrors(['name', 'age']); } ~~~ ~~~ ### Assert 旧输入内容有一些数据 ~~~ ~~~ public function testMethod() { $this->call('GET', '/'); $this->assertHasOldInput(); } ~~~ ~~~