我正在尝试在我的一个控制器上运行phpunit测试。我正在使用lalavel框架工作提供的一个函数叫做action()并且我一直得到一个1)ListTest :: testCreateList ErrorException:Array to string conversion。我已经被困在这几个小时,并且不知道为什么会发生这种情况。
1)ListTest :: testCreateList ErrorException:数组到字符串转换
ConsoleOutput/Users/jacobshafi/Desktop/Code/api/vendor/laravel/framework/src/Illuminate/Support/helpers.php:686
/Users/jacobshafi/Desktop/Code/api/bootstrap/compiled.php:3976
/Users/jacobshafi/Desktop/Code/api/bootstrap/compiled.php:3966
/Users/jacobshafi/Desktop/Code/api/bootstrap/compiled.php:3959
/Users/jacobshafi/Desktop/Code/api/bootstrap/compiled.php:4043
/Users/jacobshafi/Desktop/Code/api/vendor/laravel/framework/src/Illuminate/Foundation/Testing/ApplicationTrait.php:90
/Users/jacobshafi/Desktop/Code/api/app/tests/ListControllerTest.php:58
ApplicationTrait.php(在控制器中调用的操作方法)
public function action($method, $action, $wildcards = array(), $parameters = array(), $files = array(), $server = array(), $content = null, $changeHistory = true)
{
$uri = $this->app['url']->action($action, $wildcards, true);
return $this->call($method, $uri, $parameters, $files, $server, $content, $changeHistory);
}
ListController.php
class ListController extends BaseController
{
public function postCreate()
{
some code...
}
ListControllerTest.php
class ListTest extends TestCase {
public function testCreateList()
{
$response = $this->action(
'POST',
'App\Controllers\v2\ListController@postCreate',
[
'body' => array(
"name" => "open,shared",
"users" => array(array("user_id" => $user_id)),
"visibility" => "2",
"joinability" => "2",
"adminship" => "1",
"color" => "#2bc069"
),
'headers' => array('Auth' => getTestAuthSender())
]
);
}