大佬教程收集整理的这篇文章主要介绍了php – 在Laravel 5.5中测试授权策略时遇到问题,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
PHPUnit 6.5.13 by Sebastian Bergmann and contributors. R. 2 / 2 (100%) Time: 99 ms,Memory: 16.00MB There was 1 risky test: 1) Tests\Feature\ExampleTest::testBasicTest Test code or tested code did not (only) close its own output buffers OK,but incomplete,skipped,or risky tests! Tests: 2,Assertions: 2,Risky: 1.
这是我的测试代码:
public function testBasicTest() { $this->get('/home') ->assertStatus(403); }
当我使用dd($this-> get(‘/ home’) – > getContent());时,我收到类似这样的错误.
file_get_contents([internal]): failed to open stream: No such file or directory in Frame.php line 122
这是我的家庭控制器
<?php namespace App\Http\Controllers; use App\User; use Illuminate\Http\Request; class HomeController extends Controller { /** * Show the application dashboard. * * @return \Illuminate\Http\Response */ public function index() { $this->authorize('create',User::class); return view('home'); } }
这是我的UserPolicy.php
<?php namespace App\Policies; use App\User; use Illuminate\Auth\Access\HandlesAuthorization; class UserPolicy { use HandlesAuthorization; /** * Create a new policy instance. * * @return void */ public function __construct() { // } public function create(User $user) { return true; } }
这是我的AuthServiceProvider.php
<?php namespace App\Providers; use Illuminate\Support\Facades\Gate; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use App\User; use App\Policies\UserPolicy; class AuthServiceProvider extends ServiceProvider { /** * The policy mappings for the application. * * @var array */ protected $policies = [ User::class => UserPolicy::class,]; /** * Register any authentication / authorization services. * * @return void */ public function boot() { $this->registerPolicies(); // } }
额外:
我看到了这个:https://phpunit.readthedocs.io/en/7.4/risky-tests.html
我尝试将所有这些设置为错误,但风险仍在显现.
似乎问题出在包filp / whoops v2.3.0中,这导致异常.他们设法在v2.3.1中解决了这个问题.
以上是大佬教程为你收集整理的php – 在Laravel 5.5中测试授权策略时遇到问题全部内容,希望文章能够帮你解决php – 在Laravel 5.5中测试授权策略时遇到问题所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。