Laravel unit test : 模擬認(rèn)證的用戶
<?php use AppUser; class ExampleTest extends TestCase { public function testApplication() { $user = factory(User::class)->create(); $response = $this->actingAs($user) ->withSession(['foo' => 'bar']) ->get('/'); } }
use IlluminateFoundationAuthUser as Authenticatable; class User extends Authenticatable { protected $fillable = [ 'id', 'name', 'email', 'password', ]; }
$user = new User([ 'id' => 1, 'name' => 'ibrand' ]); $this->be($user,'api');
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載。
THE END