I’m trying to test an endpoint which returns the user with the most tickets.
Its failing… always returning user 20 as the popular one? I’m not understanding how user 20 even exists if I’m only making 15 tickets? Laravel is clearly doing something behind the scenes like remembering live data.
Test:
class StatisticsTest extends TestCase
{
use RefreshDatabase;
public function test_most_popular_user(): void
{
Ticket::factory()
->count(15)
->create();
$userId = User::query()->max('id');
Ticket::query()
->update(['user_id' => $userId]);
$response = $this->get('/stats');
error_log('OUTPUT: ' . $response->getContent());
$response->assertStatus(200);
$response->assertJsonIsArray('popularUser');
$this->assertEquals($userId, $response['popularUser']['id']);
}
}