@bwrigley you should probably mock the method and return the static value. This would also make your test less brittle, because you're not relying on the value which is generated in the database:
use Illuminate\Support\Str;
//...
public function store(Profile $profile)
{
$profile->fill([
'first_name' => $request->first_name,
'last_name' => $request->last_name,
'long_title' => $request->first_name . ' ' . $request->last_name . ' ' . $profile->getNextId(),
'slug' => Str::slug($profile->long_title),
]);
Auth::user()->profile()->save($profile);
}
Test:
$this->mock(Profile::class, function ($mock) {
$mock->makePartial();
$mock->shouldReceive('newInstance')->andReturn($mock);
$mock->shouldReceive('getNextId')->andReturn(1);
});
$this->post('/profiles', [
'first_name' => 'Joe',
'last_name' => 'Doe',
]);
//...
$this->assertEquals('Joe Doe 1', Auth::user()->profile->long_title);
Mocking Eloquent model is quite tricky, I've already wrote a detailed guide in this thread: https://laracasts.com/discuss/channels/testing/spying-method-inside-of-if-condition