engelsystem/tests/Unit/Models/Shifts/ScheduleTest.php

70 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace Engelsystem\Test\Unit\Models\Shifts;
use Engelsystem\Models\Shifts\Schedule;
use Engelsystem\Models\Shifts\ScheduleShift;
2023-01-03 22:19:03 +01:00
use Engelsystem\Models\Shifts\Shift;
use Engelsystem\Models\Shifts\ShiftType;
2020-05-11 19:57:25 +02:00
use Engelsystem\Test\Unit\Models\ModelTest;
2023-01-03 22:19:03 +01:00
use Illuminate\Database\Eloquent\Collection;
2020-05-11 19:57:25 +02:00
class ScheduleTest extends ModelTest
{
protected array $data = [
'url' => 'https://foo.bar/schedule.xml',
'name' => 'Testing',
'shift_type' => 1,
'minutes_before' => 10,
'minutes_after' => 10,
];
/**
* @covers \Engelsystem\Models\Shifts\Schedule::scheduleShifts
*/
public function testScheduleShifts(): void
{
$schedule = new Schedule($this->data);
$schedule->save();
(new ScheduleShift(['shift_id' => 1, 'schedule_id' => $schedule->id, 'guid' => 'a']))->save();
(new ScheduleShift(['shift_id' => 2, 'schedule_id' => $schedule->id, 'guid' => 'b']))->save();
(new ScheduleShift(['shift_id' => 3, 'schedule_id' => $schedule->id, 'guid' => 'c']))->save();
$this->assertCount(3, $schedule->scheduleShifts);
}
2023-01-03 22:19:03 +01:00
/**
* @covers \Engelsystem\Models\Shifts\Schedule::shifts
*/
public function testShifts(): void
{
$schedule = new Schedule($this->data);
$schedule->save();
/** @var Collection|Shift[] $shifts */
$shifts = Shift::factory(3)->create();
(new ScheduleShift(['shift_id' => $shifts[0]->id, 'schedule_id' => $schedule->id, 'guid' => 'a']))->save();
(new ScheduleShift(['shift_id' => $shifts[1]->id, 'schedule_id' => $schedule->id, 'guid' => 'b']))->save();
(new ScheduleShift(['shift_id' => $shifts[2]->id, 'schedule_id' => $schedule->id, 'guid' => 'c']))->save();
$this->assertCount(3, $schedule->shifts);
}
/**
* @covers \Engelsystem\Models\Shifts\Schedule::shiftType
*/
public function testShiftType(): void
{
$st = new ShiftType(['name' => 'Shift Type', 'description' => '']);
$st->save();
$schedule = new Schedule($this->data);
$schedule->shiftType()->associate($st);
2022-12-03 00:57:04 +01:00
$schedule->save();
$this->assertEquals('Shift Type', Schedule::find(1)->shiftType->name);
}
}