运行PHPunit后,我在
收到错误$this->assertRedirectedToRoute('posts.index'); // line 50
$this->assertRedirectedToRoute('posts.index', ['flash']); //line 84
1)
PostsControllerTest::testStore
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
/usr/share/nginx/www/laravelphpunitest/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:245
/usr/share/nginx/www/laravelphpunitest/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:260
/usr/share/nginx/www/laravelphpunitest/app/tests/controllers/PostsControllerTest.php:50
2)
PostsControllerTest::testStoreSuccess
Failed asserting that two strings are equal.
-- Expected
+++ Actual
@@ @@
/usr/share/nginx/www/laravelphpunitest/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:245
/usr/share/nginx/www/laravelphpunitest/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:260
/usr/share/nginx/www/laravelphpunitest/app/tests/controllers/PostsControllerTest.php:84
答案 0 :(得分:1)
如果你看到文档
public void assertRedirectedToRoute(string $ name,array $ parameters = array(),array $ with = array())
断言客户端是否被重定向到给定路由。
参数
string $ name
数组$参数
array $ with
所以你应该在assertRedirectedToRoute第三个参数中传递“with”,如:
$this->assertRedirectedToRoute('posts.index', [] ,['flash']);
希望它有所帮助。