SprintControllerTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * Copyright 2026 Alessandro Chiapparini <sprint_planer_web@chiapparini.org>
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * See the LICENSE file in the project root for the full license text.
  9. */
  10. declare(strict_types=1);
  11. namespace App\Tests\Controllers;
  12. use App\Controllers\SprintController;
  13. use App\Tests\TestCase;
  14. use ReflectionMethod;
  15. /**
  16. * Pure-static guards on SprintController. Mirrors ImportControllerTest:
  17. * exercise the bits that do not need PDO or session wiring.
  18. */
  19. final class SprintControllerTest extends TestCase
  20. {
  21. public function testWeeksBetweenInclusiveSameDayIsOneWeek(): void
  22. {
  23. $this->assertSame(1, self::call('weeksBetween', '2026-01-05', '2026-01-05'));
  24. }
  25. public function testWeeksBetweenSpansFullCalendarWeeks(): void
  26. {
  27. // Mon → Fri of the same week → 1 week.
  28. $this->assertSame(1, self::call('weeksBetween', '2026-01-05', '2026-01-09'));
  29. // Mon → Sun (end of the same week, +6 days) → 1 week.
  30. $this->assertSame(1, self::call('weeksBetween', '2026-01-05', '2026-01-11'));
  31. // Mon → Mon next week (+7 days) flips to 2 weeks.
  32. $this->assertSame(2, self::call('weeksBetween', '2026-01-05', '2026-01-12'));
  33. // Mon → Fri three weeks later → 3 weeks.
  34. $this->assertSame(3, self::call('weeksBetween', '2026-01-05', '2026-01-23'));
  35. }
  36. public function testWeeksBetweenClampsToOneWhenDatesAreReversed(): void
  37. {
  38. $this->assertSame(1, self::call('weeksBetween', '2026-01-12', '2026-01-05'));
  39. }
  40. private static function call(string $method, mixed ...$args): mixed
  41. {
  42. $r = new ReflectionMethod(SprintController::class, $method);
  43. $r->setAccessible(true);
  44. return $r->invoke(null, ...$args);
  45. }
  46. /**
  47. * R01-N24: the per-batch list cap is a drift-sensitive number — bumping
  48. * it has security implications (memory + DB pressure under attacker
  49. * load) and operator implications (existing tooling that batches near
  50. * the cap may break). A future refactor that tweaks it must update
  51. * REVIEW_01.md §R01-N24 in the same commit.
  52. */
  53. public function testMaxBatchItemsConstant(): void
  54. {
  55. $this->assertSame(5000, SprintController::MAX_BATCH_ITEMS);
  56. }
  57. }