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

45 lines
1.5 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
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;
2020-05-11 19:57:25 +02:00
use Engelsystem\Test\Unit\Models\ModelTest;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
2020-05-11 19:57:25 +02:00
class ScheduleShiftTest extends ModelTest
{
/**
* @covers \Engelsystem\Models\Shifts\ScheduleShift::schedule
2023-01-03 22:19:03 +01:00
* @covers \Engelsystem\Models\Shifts\ScheduleShift::shift
*/
public function testScheduleShifts(): void
{
2020-11-21 20:54:04 +01:00
$schedule = new Schedule([
'url' => 'https://lorem.ipsum/schedule.xml',
'name' => 'Test',
'shift_type' => 0,
'minutes_before' => 15,
'minutes_after' => 15,
]);
$schedule->save();
2023-01-03 22:19:03 +01:00
/** @var Shift $shift */
$shift = Shift::factory()->create();
2023-01-03 22:19:03 +01:00
$scheduleShift = new ScheduleShift(['guid' => 'a']);
$scheduleShift->schedule()->associate($schedule);
2023-01-03 22:19:03 +01:00
$scheduleShift->shift()->associate($shift);
$scheduleShift->save();
/** @var ScheduleShift $scheduleShift */
$scheduleShift = (new ScheduleShift())->find(1);
$this->assertInstanceOf(BelongsTo::class, $scheduleShift->schedule());
$this->assertEquals($schedule->id, $scheduleShift->schedule->id);
2023-01-03 22:19:03 +01:00
$this->assertInstanceOf(BelongsTo::class, $scheduleShift->shift());
$this->assertEquals($shift->id, $scheduleShift->shift->id);
}
}