Ich versuche, meine api zu testen, die mit JWT_auth gemacht hat: https://github.com/tymondesigns/jwt-authLaravel Tests mit JWT-Auth
class UpdateTest extends TestCase
{
use DatabaseTransactions;
public $token;
public function signIn($data = ['email'=>'[email protected]', 'password'=>'secret'])
{
$this->post('api/login', $data);
$content = json_decode($this->response->getContent());
$this->assertObjectHasAttribute('token', $content);
$this->token = $content->token;
return $this;
}
/** @test */
public function a_user_updates_his_account()
{
factory(User::class)->create([
'name' => 'Test',
'last_name' => 'Test',
'email' => '[email protected]',
'mobile' => '062348383',
'function' => 'ceo',
'about' => 'About me.....',
'corporation_id' => 1
]);
$user = User::first();
$user->active = 2;
$user->save();
$this->signIn();
$url = '/api/user/' . $user->slug . '?token=' . $this->token;
$result = $this->json('GET', $url);
dd($result);
}
}
Ergebnis ist immer:
The token could not be parsed from the request
Wie bekomme ich diese T Arbeit !?
Quelle (https://github.com/tymondesigns/jwt-auth/issues/206)
Wahrscheinlich, weil die die Middleware die Token von Authorization-Header liest, nicht indem er sie als Abfrageparameter anhängt:
Und wird wie folgt verwendet. – JofryHS
Ja, aber wie bekomme ich das zum Laufen? – Jamie