An alternatywnego jest do uwierzytelnienia żądania podczas wykonywania testu przechodzącą konkretnego użytkownika. To jak to zrobił:
# 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;
}
Następnie w moich testów używam go tak:
# 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();
}
Nadzieja to pomóc wszystkim. Szczęśliwe kodowanie!
Znalazłeś rozwiązanie dla tego? –
Przeczytałem cały kod źródłowy i wyśmiałem każde wywołanie metody z jwtauth. Ale wygląda na to, że Laravel 5.1 ma cechę, która ominęła middleware, możesz to sprawdzić –
Jestem również bardzo zainteresowany rozwiązaniem tego problemu. Próbowałem wyłączyć oprogramowanie pośrednie, ale nie mogę go uruchomić. Rozwiązałeś to? @ ChristopherFrancisco – Mattias