我正在尝试通过在单元测试中调用控制器操作来内部测试API。由于某种原因,我得到InvalidArgumentException:Route [ListController @ create]未定义。有人可以帮忙吗?
ListControllerTest.phpuse Guzzle\Tests\GuzzleTestCase,
Guzzle\Plugin\Mock\MockPlugin,
Guzzle\Http\Message\Response,
Guzzle\Http\Client,
Guzzle\Service\Client as ServiceClient,
Guzzle\Http\EntityBody;
class ListTest extends TestCase {
public function testCreateList()
{
$user_id = getTestReceiverUserId();
$response = $this->action(
'POST',
'ListController@create',
[
'body' => array(
"name" => "open,shared",
"users" => array(array("user_id" => $user_id)),
"visibility" => "2",
"joinability" => "2",
"adminship" => "1",
"color" => "#2bc069"
),
'headers' => array('Auth' => getTestAuthSender())
]
);
}
routes.php文件
Route::group(array('namespace' => 'App\Controllers\v2', 'prefix' => '2.0'), function()
{
Route::controller('user', 'UserController');
Route::controller('invite', 'InviteController');
Route::controller('list', 'ListController');
Route::post('/login','AuthController@login');
Route::any('/logout','AuthController@logout');
});
ListController.php
namespace App\Controllers\v1;
use BaseController;
use Timothylhuillier\LaravelMixpanel\Facades\LaravelMixpanel;
class ListController extends BaseController
{
public function postCreate()
{
Some Code
}
答案 0 :(得分:0)
我想这是因为你的ListController
命名空间内有v2
。
尝试更改:
'ListController@create',
为:
'v2\ListController@postCreate',
希望这有帮助!