60 - Make schedule test assertion counts deterministic
This commit is contained in:
parent
7f7a9450bf
commit
c3a5532028
3 changed files with 25 additions and 27 deletions
|
|
@ -1662,12 +1662,6 @@ parameters:
|
|||
count: 2
|
||||
path: tests/Unit/Schedule/ScheduleGeneratorTest.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$callback of method Illuminate\\Support\\Collection\<int,Carbon\\Carbon\>\:\:reduce\(\) expects callable\(Illuminate\\Support\\Carbon\|null, Carbon\\Carbon, int\)\: Illuminate\\Support\\Carbon, Closure\(Illuminate\\Support\\Carbon\|null, Illuminate\\Support\\Carbon\)\: Illuminate\\Support\\Carbon given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: tests/Unit/Schedule/ScheduleGeneratorTest.php
|
||||
|
||||
-
|
||||
message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$id\.$#'
|
||||
identifier: property.notFound
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
use App\WeekdaysEnum;
|
||||
use DishPlanner\Schedule\Services\ScheduleGenerator;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\HasPlanner;
|
||||
|
||||
|
|
@ -128,19 +127,23 @@ public function test_it_takes_minimum_recurrences_into_account(): void
|
|||
|
||||
$this->assertTrue(Schedule::all()->isNotEmpty());
|
||||
|
||||
Schedule::all()
|
||||
->filter(fn (Schedule $schedule) => $schedule->scheduledUserDishes()->first()->userDish->dish->id === $dishRecurring->id)
|
||||
$recurringDates = Schedule::all()
|
||||
->filter(fn (Schedule $schedule) => $schedule->scheduledUserDishes
|
||||
->contains(fn ($scheduledUserDish) => $scheduledUserDish->userDish->dish->id === $dishRecurring->id)
|
||||
)
|
||||
->map(fn (Schedule $schedule) => $schedule->date)
|
||||
->reduce(function (?Carbon $previousDate, Carbon $currentDate) use ($recurringMinimum) {
|
||||
if (! is_null($previousDate)) {
|
||||
$this->assertGreaterThanOrEqual(
|
||||
$recurringMinimum,
|
||||
$previousDate->diffInDays($currentDate),
|
||||
->sort()
|
||||
->values();
|
||||
|
||||
$this->assertGreaterThan(1, $recurringDates->count(), 'Recurring dish was not scheduled often enough to verify spacing');
|
||||
|
||||
$gaps = $recurringDates
|
||||
->sliding(2)
|
||||
->map(fn ($pair) => (int) $pair->first()->diffInDays($pair->last()));
|
||||
|
||||
$this->assertEmpty(
|
||||
$gaps->reject(fn (int $gap) => $gap >= $recurringMinimum)->all(),
|
||||
'Dates are not spaced properly'
|
||||
);
|
||||
}
|
||||
|
||||
return $currentDate;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,19 +55,20 @@ public function test_includes_correct_day_numbers(): void
|
|||
|
||||
public function test_marks_today_correctly(): void
|
||||
{
|
||||
$this->travelTo(Carbon::createFromDate(2026, 3, 15)->startOfDay());
|
||||
|
||||
$planner = $this->planner;
|
||||
$today = now();
|
||||
|
||||
$calendarDays = $this->service->getCalendarDays($planner, $today->month, $today->year);
|
||||
$calendarDays = $this->service->getCalendarDays($planner, 3, 2026);
|
||||
|
||||
$todayIndex = $today->day - 1;
|
||||
$todayIndex = 14;
|
||||
$this->assertTrue($calendarDays[$todayIndex]['isToday']);
|
||||
|
||||
foreach ($calendarDays as $index => $day) {
|
||||
if ($index !== $todayIndex && $day['day'] !== null) {
|
||||
$this->assertFalse($day['isToday']);
|
||||
}
|
||||
}
|
||||
$otherDaysMarkedToday = collect($calendarDays)
|
||||
->filter(fn (array $day, int $index) => $index !== $todayIndex && $day['day'] !== null)
|
||||
->filter(fn (array $day) => $day['isToday']);
|
||||
|
||||
$this->assertCount(0, $otherDaysMarkedToday);
|
||||
}
|
||||
|
||||
public function test_includes_scheduled_dishes(): void
|
||||
|
|
|
|||
Loading…
Reference in a new issue