mock = Mockery::mock(TotalEntryScores::class); app()->instance(TotalEntryScores::class, $this->mock); }); it('recalculates total scores when bonus score is created', function () { $entry = Entry::factory()->create(); $this->mock->shouldReceive('__invoke') ->once() ->withAnyArgs() ->andReturn(null); BonusScore::factory() ->forEntry($entry) ->create(); }); it('recalculates total scores when bonus score is updated', function () { $this->mock->shouldReceive('__invoke') ->once() ->withAnyArgs() ->andReturn(null); $bonusScore = BonusScore::factory()->create(); $this->mock->shouldReceive('__invoke') ->once() ->withAnyArgs() ->andReturn(null); $bonusScore->update(['score' => 95]); }); it('recalculates total scores when bonus score is deleted', function () { DB::table('bonus_scores')->insert([ 'entry_id' => Entry::factory()->create()->id, 'user_id' => User::factory()->create()->id, 'originally_scored_entry' => Entry::factory()->create()->id, 'score' => 28, ]); $bonusScore = BonusScore::first(); $this->mock->shouldReceive('__invoke') ->once() ->withAnyArgs() ->andReturn(null); $bonusScore->delete(); });