我正在尝试执行测试来检查是否
1 - 用户已通过身份验证
2 - 有权查看请求的页面
每次我运行测试时都会收到此错误
预期状态代码200但收到302。
namespace Tests\Feature\Category;
class CategoryTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function it_can_see_all_categories()
{
$user = $this->signedIn();
$permission = Permission::create(['group' => 'categories' , 'name' => 'view categories' , 'label' => 'view categories']);
$role = Role::find($user->role_id);
$role->givePermissionTo($permission);
$response = $this->get('/categories');
$response->assertStatus(200 , $response->getStatusCode());
}
}
我的控制器
<?php
namespace App\Http\Controllers\Category;
class CategoriesController extends Controller
{
protected $categRepo;
/**
* Initializing Categories Repository
*/
public function __construct(CategoryRepository $categRepo)
{
$this->categRepo = $categRepo;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(ManageCategoryRequest $request)
{
$categories = $this->categRepo->getPaginated(25);
return view('categories.index' , compact('categories'));
}
}
这是我的请求授权请求
<?php
class ManageCategoryRequest extends FormRequest
{
public function authorize()
{
return $this->user()->can('view categories');
}
}
答案 0 :(得分:0)
可能未登录!看着signedIn