ProductionCalendarServiceTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. namespace Tests\Unit\Services;
  4. use App\Models\ProductionCalendarDay;
  5. use App\Services\ProductionCalendarService;
  6. use Illuminate\Foundation\Testing\RefreshDatabase;
  7. use InvalidArgumentException;
  8. use Tests\TestCase;
  9. class ProductionCalendarServiceTest extends TestCase
  10. {
  11. use RefreshDatabase;
  12. public function test_it_skips_weekends_by_default(): void
  13. {
  14. $result = app(ProductionCalendarService::class)->addWorkingDays('2024-01-05', 1);
  15. $this->assertSame('2024-01-08', $result->toDateString());
  16. }
  17. public function test_calendar_override_can_mark_a_weekday_as_non_working(): void
  18. {
  19. ProductionCalendarDay::factory()->create([
  20. 'date' => '2024-01-08',
  21. 'is_working_day' => false,
  22. 'name' => 'Праздник',
  23. ]);
  24. $result = app(ProductionCalendarService::class)->addWorkingDays('2024-01-05', 1);
  25. $this->assertSame('2024-01-09', $result->toDateString());
  26. }
  27. public function test_calendar_override_can_mark_a_weekend_as_working(): void
  28. {
  29. ProductionCalendarDay::factory()->create([
  30. 'date' => '2024-01-06',
  31. 'is_working_day' => true,
  32. 'name' => 'Рабочая суббота',
  33. ]);
  34. $result = app(ProductionCalendarService::class)->addWorkingDays('2024-01-05', 1);
  35. $this->assertSame('2024-01-06', $result->toDateString());
  36. }
  37. public function test_negative_working_days_are_rejected(): void
  38. {
  39. $this->expectException(InvalidArgumentException::class);
  40. app(ProductionCalendarService::class)->addWorkingDays('2024-01-05', -1);
  41. }
  42. }