auditionadmin/tests/Feature/app/Observers/BonusScoreObserverTest.php

63 lines
1.6 KiB
PHP

<?php
/** @noinspection PhpPossiblePolymorphicInvocationInspection */
use App\Actions\Tabulation\TotalEntryScores;
use App\Models\BonusScore;
use App\Models\Entry;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->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();
});