The reason I was getting a 404 when I tried to use the WithoutMiddleware is because the dingo api package uses middleware to capture requests that target the API and handles them appropriately.
So in order to test the auth:api middleware just make sure to send this as the header in your requests:
/**
* 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 = $user->createToken('Token Name')->accessToken;
$headers['Authorization'] = 'Bearer ' . $token;
}
return $headers;
}
/** @test */
public function itTestsSomething()
{
$user = factory(User::class)->create();
$this->post('/url', $data, $this->headers($user));
// your assertions
}
Also if you are using database migrations, make sure you initialize a passport client before the test.