DynamicIntervalTest.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of the Carbon package.
  5. *
  6. * (c) Brian Nesbitt <brian@nesbot.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Tests\CarbonPeriod;
  12. use Carbon\Carbon;
  13. use Tests\AbstractTestCase;
  14. class DynamicIntervalTest extends AbstractTestCase
  15. {
  16. public function testDynamicIntervalInPeriod()
  17. {
  18. $periodClass = $this->periodClass;
  19. $weekDayStep = function (Carbon $date, bool $negated = false): Carbon {
  20. if ($negated) {
  21. return $date->previousWeekDay();
  22. }
  23. return $date->nextWeekDay();
  24. };
  25. $period = $periodClass::create('2020-06-01', $weekDayStep, '2020-06-14');
  26. $dates = [];
  27. foreach ($period as $date) {
  28. $dates[] = $date->day;
  29. }
  30. $this->assertCount(10, $period);
  31. $this->assertSame(array_merge(range(1, 5), range(8, 12)), $dates);
  32. }
  33. }