@jrdavidson This is where mocking would come in. You’d mock the repository call to return a set of known users, and test that those users’ details end up in the page using assertSeeText or something. But I don’t really understand how your repository works when it’s just horrible static methods, and not being resolved by the container.
Ideally, your test should look something like this:
$dummyUsers = [
new User(['name' => 'Available User 1']),
new User(['name' => 'Available User 2']),
new User(['name' => 'Available User 3']),
];
$this->mock(UserRepository::class, function (MockInterface $mock) use ($dummyUsers) {
$mock->shouldReceive('getAvailableUsersForNewTeam')->andReturn($dummyUsers);
});
$this
->actingAs($this->admin)
->get('/teams/create')
->assertOk()
->assertViewIs('teams.create')
->assertViewHas('users', $dummyUsers)
->assertSeeText('Available User 1')
->assertSeeText('Available User 2')
->assertSeeText('Available User 3');
This assumes the repository method returns an array of User models. If it returns a collection, return a collection instance instead.
This way, you’re testing exactly what you want to test: whether some users end up in the view, and not concerned about other parts (the repository, which should have its own tests).