为什么我会收到错误 Failed asserting that Response Object (...) is an instance of class "RedirectResponse"?
Why do I get the error Failed asserting that Response Object (...) is an instance of class "RedirectResponse"?
问题
PHPUnit 断言 $this->assertRedirectedToAction('CatsController@index')
失败。
路线
Route::get('/','CatsController@index');
测试用例
class CatTest extends TestCase {
/**
* A basic functional test example.
*
* @return void
*/
public function testHomePageRedirection()
{
$this->call('GET','/');
$this->assertRedirectedToAction('CatsController@index');
}
错误
Failed asserting that Illuminate\Http\Response Object (...) is an instance of class "Illuminate\Http\RedirectResponse".
/Applications/MAMP/htdocs/crudapp/vendor/laravel/framework/src/Illuminate/Foundation/Testing/AssertionsTrait.php:110
/Applications/MAMP/htdocs/crudapp/vendor/laravel/framework/src/Illuminate/Foundation/Testing/AssertionsTrait.php:140
/Applications/MAMP/htdocs/crudapp/app/tests/CatTest.php:13
有人可以帮我确定为什么我会遇到这个错误吗?
因为你不是 redirected
到 CatsController@index
- 这就是你所在的页面。
Route::get('/','CatsController@index')
Route::get('/redirect', function () {
return Redirect::action('CatsController@index');
});
public function testHomePageOk()
{
$this->call('GET','/');
$this->assertResponseOk();
}
public function testRedirectToHomePage()
{
$this->call('GET','/redirect');
$this->assertRedirectedToAction('CatsController@index');
}
问题
PHPUnit 断言 $this->assertRedirectedToAction('CatsController@index')
失败。
路线
Route::get('/','CatsController@index');
测试用例
class CatTest extends TestCase {
/**
* A basic functional test example.
*
* @return void
*/
public function testHomePageRedirection()
{
$this->call('GET','/');
$this->assertRedirectedToAction('CatsController@index');
}
错误
Failed asserting that Illuminate\Http\Response Object (...) is an instance of class "Illuminate\Http\RedirectResponse".
/Applications/MAMP/htdocs/crudapp/vendor/laravel/framework/src/Illuminate/Foundation/Testing/AssertionsTrait.php:110
/Applications/MAMP/htdocs/crudapp/vendor/laravel/framework/src/Illuminate/Foundation/Testing/AssertionsTrait.php:140
/Applications/MAMP/htdocs/crudapp/app/tests/CatTest.php:13
有人可以帮我确定为什么我会遇到这个错误吗?
因为你不是 redirected
到 CatsController@index
- 这就是你所在的页面。
Route::get('/','CatsController@index')
Route::get('/redirect', function () {
return Redirect::action('CatsController@index');
});
public function testHomePageOk()
{
$this->call('GET','/');
$this->assertResponseOk();
}
public function testRedirectToHomePage()
{
$this->call('GET','/redirect');
$this->assertRedirectedToAction('CatsController@index');
}