I am trying to test several endpoints in my API. Authentication is provided via laravel/passport's Password Grant Token.
What I have right now is a TestCase class with this:
public function setUp()
$clientRepository = new ClientRepository();
$this->client = $clientRepository->createPasswordGrantClient(
null, 'Test Personal Access Client', ''
$this->user = create(User::class, [
'password' => bcrypt('secret')
$response = parent::postJson('/oauth/token', [
'client_secret' => $this->client->secret,
'client_id' => $this->client->id,
'grant_type' => 'password',
'username' => $this->user->email,
'password' => 'secret',
$this->token = $response->json()['access_token'];
This works without a problem, the only thing is it takes a lot of performance, 20 tests take about 10 seconds to execute since this is happening for every test.
I was thinking of creating a helper class and using PHPUnit's static method
setUpBeforeClass, but if I do that,
$clientRepository is missing context and everything fails.