48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
<?php
|
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */
|
|
|
|
use App\Actions\Entries\CreateEntry;
|
|
use App\Actions\Tabulation\DoublerSync;
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use App\Models\Event;
|
|
use App\Models\Student;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->mock = Mockery::mock(DoublerSync::class);
|
|
app()->instance(DoublerSync::class, $this->mock);
|
|
});
|
|
|
|
afterEach(function () {
|
|
Mockery::close();
|
|
});
|
|
|
|
it('syncs doublers if an entry is created that makes or adds to a doubler', function () {
|
|
$event = Event::factory()->create();
|
|
$student = Student::factory()->create();
|
|
$audition1 = Audition::factory()->forEvent($event)->create();
|
|
$audition2 = Audition::factory()->forEvent($event)->create();
|
|
$audition3 = Audition::factory()->forEvent($event)->create();
|
|
$entryMaker = app(CreateEntry::class);
|
|
$this->mock->shouldReceive('__invoke')->twice();
|
|
$entryMaker($student, $audition1);
|
|
$entryMaker($student, $audition2);
|
|
$entryMaker($student, $audition3);
|
|
});
|
|
|
|
it('syncs doublers when an entry is updated', function () {
|
|
$this->mock->shouldReceive('__invoke')->once();
|
|
$entry = Entry::factory()->create();
|
|
$entry->update(['audition_id' => Audition::factory()->create()->id]);
|
|
});
|
|
|
|
it('syncs doublers when an entry is deleted', function () {
|
|
$this->mock->shouldReceive('__invoke')->once();
|
|
$entry = Entry::factory()->create();
|
|
$entry->delete();
|
|
});
|