Un alternativa è di autenticare la richiesta durante l'esecuzione del test di superamento di un particolare utente. Ecco come lo ha fatto:
# tests/TestCase.php
/**
* Return request headers needed to interact with the API.
*
* @return Array array of headers.
*/
protected function headers($user = null)
{
$headers = ['Accept' => 'application/json'];
if (!is_null($user)) {
$token = JWTAuth::fromUser($user);
JWTAuth::setToken($token);
$headers['Authorization'] = 'Bearer '.$token;
}
return $headers;
}
Poi nel mio test ho usare in questo modo:
# tests/StuffTest.php
/**
* Test: GET /api/stuff.
*/
public function testIndex()
{
$url = '/api/stuff';
// Test unauthenticated access.
$this->get($url, $this->headers())
->assertResponseStatus(400);
// Test authenticated access.
$this->get($url, $this->headers(User::first()))
->seeJson()
->assertResponseOk();
}
Spero che questo aiuto a tutti voi. Buona programmazione!
fonte
2015-12-18 09:11:58
Avete trovato una soluzione per questo? –
Ho letto l'intero codice sorgente e preso in giro ogni chiamata di metodo da jwtauth. Ma sembra che Laravel 5.1 abbia un tratto per aggirare i middleware, potresti voler dare un'occhiata a –
Sono anche molto interessato a una soluzione per questo. Ho provato a disattivare il middleware ma non riesco a farlo funzionare. Hai risolto questo? @ChristopherFrancisco – Mattias