diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0672436..f969475 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -38,9 +38,7 @@ jobs: - name: Install dependencies if: steps.composer-cache.outputs.cache-hit != 'true' - run: | - ${{ matrix.php >= 8.1 && 'composer require --no-update phpunit/phpunit:^8.5.14 --no-interaction;' || '' }} - composer update --prefer-dist --no-progress --no-suggest --prefer-${{ matrix.setup || 'stable' }} ${{ matrix.php >= 8 && '--ignore-platform-req=php' || '' }} + run: composer update --prefer-dist --no-progress --no-suggest --prefer-${{ matrix.setup || 'stable' }} ${{ matrix.php >= 8 && '--ignore-platform-req=php' || '' }} - name: Run test suite run: vendor/bin/phpunit --no-coverage diff --git a/composer.json b/composer.json index d694712..fb01e55 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ }, "require-dev": { "kylekatarnls/multi-tester": "^2.5", - "phpunit/phpunit": "^10.4.2" + "phpunit/phpunit": "^11.2" }, "autoload": { "psr-4": { diff --git a/tests/ArrTest.php b/tests/ArrTest.php index 7207cdf..523802c 100644 --- a/tests/ArrTest.php +++ b/tests/ArrTest.php @@ -2,12 +2,13 @@ namespace Spatie\OpeningHours\Test; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\OpeningHours\Helpers\Arr; class ArrTest extends TestCase { - /** @test */ + #[Test] public function it_can_flat_and_map_array() { $this->assertSame([-1, 2, [3, 4], -5, 6], Arr::flatMap([1, [2, [3, 4]], 5, [6]], function ($value) { diff --git a/tests/OpeningHoursCustomClassTest.php b/tests/OpeningHoursCustomClassTest.php index 30439dd..38e36df 100644 --- a/tests/OpeningHoursCustomClassTest.php +++ b/tests/OpeningHoursCustomClassTest.php @@ -4,13 +4,14 @@ use DateTimeImmutable; use DateTimeZone; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\OpeningHours\Exceptions\InvalidDateTimeClass; use Spatie\OpeningHours\OpeningHours; class OpeningHoursCustomClassTest extends TestCase { - /** @test */ + #[Test] public function it_can_use_immutable_date_time() { $openingHours = OpeningHours::create([ @@ -24,7 +25,7 @@ public function it_can_use_immutable_date_time() $this->assertSame('2021-10-11 09:00:00', $date->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_can_use_timezones() { $openingHours = OpeningHours::create([ @@ -103,7 +104,7 @@ public function it_can_use_timezones() $this->assertSame('2022-08-01 03:00:00 America/New_York', $date->format('Y-m-d H:i:s e')); } - /** @test */ + #[Test] public function it_can_use_mocked_time() { $mock1 = new class extends DateTimeImmutable @@ -136,7 +137,7 @@ public function __construct($datetime = 'now', DateTimeZone $timezone = null) $this->assertTrue($openingHours->isOpen()); } - /** @test */ + #[Test] public function it_should_refuse_invalid_date_time_class() { $this->expectException(InvalidDateTimeClass::class); diff --git a/tests/OpeningHoursFillTest.php b/tests/OpeningHoursFillTest.php index d45214c..b7f062c 100644 --- a/tests/OpeningHoursFillTest.php +++ b/tests/OpeningHoursFillTest.php @@ -4,6 +4,7 @@ use DateTime; use DateTimeImmutable; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\OpeningHours\Day; use Spatie\OpeningHours\Exceptions\InvalidDate; @@ -14,7 +15,7 @@ class OpeningHoursFillTest extends TestCase { - /** @test */ + #[Test] public function it_fills_opening_hours() { $openingHours = OpeningHours::create([ @@ -49,7 +50,7 @@ public function it_fills_opening_hours() $this->assertCount(0, $openingHours->forDate(new DateTimeImmutable('2016-09-26 11:00:00'))); } - /** @test */ + #[Test] public function it_can_map_week_with_a_callback() { $openingHours = OpeningHours::create([ @@ -76,7 +77,7 @@ public function it_can_map_week_with_a_callback() })); } - /** @test */ + #[Test] public function it_can_map_exceptions_with_a_callback() { $openingHours = OpeningHours::create([ @@ -99,7 +100,7 @@ public function it_can_map_exceptions_with_a_callback() })); } - /** @test */ + #[Test] public function it_can_handle_empty_input() { $openingHours = OpeningHours::create([]); @@ -109,7 +110,7 @@ public function it_can_handle_empty_input() } } - /** @test */ + #[Test] public function it_handles_day_names_in_a_case_insensitive_manner() { $openingHours = OpeningHours::create([ @@ -125,7 +126,7 @@ public function it_handles_day_names_in_a_case_insensitive_manner() $this->assertSame((string) $openingHours->forDay('Monday')[0], '09:00-18:00'); } - /** @test */ + #[Test] public function it_will_throw_an_exception_when_using_an_invalid_day_name() { $this->expectExceptionObject(InvalidDayName::invalidDayName('mmmmonday')); @@ -133,7 +134,7 @@ public function it_will_throw_an_exception_when_using_an_invalid_day_name() OpeningHours::create(['mmmmonday' => ['09:00-18:00']]); } - /** @test */ + #[Test] public function it_will_throw_an_exception_when_using_an_invalid_exception_date() { $this->expectException(InvalidDate::class); @@ -145,7 +146,7 @@ public function it_will_throw_an_exception_when_using_an_invalid_exception_date( ]); } - /** @test */ + #[Test] public function it_store_meta_data() { $hours = OpeningHours::create([ @@ -223,7 +224,7 @@ public function it_store_meta_data() $this->assertSame('Extra on Tuesday evening', $hours->forDay('tuesday')[2]->data); } - /** @test */ + #[Test] public function it_handle_filters() { $typicalDay = [ @@ -276,7 +277,7 @@ function (DateTimeImmutable $date) use ($typicalDay) { $this->assertSame('Month equals day', $hours->forDate(new DateTimeImmutable('2018-12-12'))->data); } - /** @test */ + #[Test] public function it_should_merge_ranges_on_explicitly_create_from_overlapping_ranges() { $hours = OpeningHours::createAndMergeOverlappingRanges([ @@ -313,7 +314,7 @@ public function it_should_merge_ranges_on_explicitly_create_from_overlapping_ran ], $dump['tuesday']); } - /** @test */ + #[Test] public function it_should_merge_ranges_including_explicit_24_00() { $hours = OpeningHours::createAndMergeOverlappingRanges([ @@ -332,7 +333,7 @@ public function it_should_merge_ranges_including_explicit_24_00() ], $dump); } - /** @test */ + #[Test] public function it_should_reorder_ranges() { $hours = OpeningHours::createAndMergeOverlappingRanges([ diff --git a/tests/OpeningHoursForDayTest.php b/tests/OpeningHoursForDayTest.php index 34d05ff..7c46370 100644 --- a/tests/OpeningHoursForDayTest.php +++ b/tests/OpeningHoursForDayTest.php @@ -2,6 +2,7 @@ namespace Spatie\OpeningHours\Test; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\OpeningHours\Exceptions\NonMutableOffsets; use Spatie\OpeningHours\Exceptions\OverlappingTimeRanges; @@ -11,7 +12,7 @@ class OpeningHoursForDayTest extends TestCase { - /** @test */ + #[Test] public function it_can_be_created_from_an_array_of_time_range_strings() { $openingHoursForDay = OpeningHoursForDay::fromStrings(['09:00-12:00', '13:00-18:00']); @@ -25,7 +26,7 @@ public function it_can_be_created_from_an_array_of_time_range_strings() $this->assertSame('13:00-18:00', (string) $openingHoursForDay[1]); } - /** @test */ + #[Test] public function it_cant_be_created_when_time_ranges_overlap() { $this->expectException(OverlappingTimeRanges::class); @@ -33,7 +34,7 @@ public function it_cant_be_created_when_time_ranges_overlap() OpeningHoursForDay::fromStrings(['09:00-18:00', '14:00-20:00']); } - /** @test */ + #[Test] public function it_can_determine_whether_its_open_at_a_time() { $openingHoursForDay = OpeningHoursForDay::fromStrings(['09:00-18:00']); @@ -43,7 +44,7 @@ public function it_can_determine_whether_its_open_at_a_time() $this->assertFalse($openingHoursForDay->isOpenAt(Time::fromString('18:00'))); } - /** @test */ + #[Test] public function it_casts_to_string() { $openingHoursForDay = OpeningHoursForDay::fromStrings(['09:00-12:00', '13:00-18:00']); @@ -51,7 +52,7 @@ public function it_casts_to_string() $this->assertSame('09:00-12:00,13:00-18:00', (string) $openingHoursForDay); } - /** @test */ + #[Test] public function it_can_offset_is_existed() { $openingHoursForDay = OpeningHoursForDay::fromStrings(['09:00-12:00', '13:00-18:00']); @@ -61,7 +62,7 @@ public function it_can_offset_is_existed() $this->assertFalse($openingHoursForDay->offsetExists(2)); } - /** @test */ + #[Test] public function it_can_unset_offset() { $this->expectException(NonMutableOffsets::class); @@ -71,7 +72,7 @@ public function it_can_unset_offset() $openingHoursForDay->offsetUnset(0); } - /** @test */ + #[Test] public function it_can_get_iterator() { $openingHoursForDay = OpeningHoursForDay::fromStrings(['09:00-12:00', '13:00-18:00']); @@ -79,7 +80,7 @@ public function it_can_get_iterator() $this->assertCount(2, $openingHoursForDay->getIterator()->getArrayCopy()); } - /** @test */ + #[Test] public function it_cant_set_iterator_item() { $this->expectException(NonMutableOffsets::class); diff --git a/tests/OpeningHoursOverflowTest.php b/tests/OpeningHoursOverflowTest.php index d2e1834..dc98ad1 100644 --- a/tests/OpeningHoursOverflowTest.php +++ b/tests/OpeningHoursOverflowTest.php @@ -4,13 +4,14 @@ use DateTime; use DateTimeImmutable; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\OpeningHours\OpeningHours; use Spatie\OpeningHours\TimeRange; class OpeningHoursOverflowTest extends TestCase { - /** @test */ + #[Test] public function it_fills_opening_hours_with_overflow() { $openingHours = OpeningHours::create([ @@ -22,7 +23,7 @@ public function it_fills_opening_hours_with_overflow() $this->assertSame((string) $openingHours->forDay('monday')[0], '09:00-02:00'); } - /** @test */ + #[Test] public function check_open_with_overflow() { $openingHours = OpeningHours::create([ @@ -60,7 +61,7 @@ public function check_open_with_overflow() $this->assertTrue($openingHours->isOpenAt($shouldBeOpen)); } - /** @test */ + #[Test] public function check_open_with_overflow_immutable() { $openingHours = OpeningHours::create([ @@ -72,7 +73,7 @@ public function check_open_with_overflow_immutable() $this->assertTrue($openingHours->isOpenAt($shouldBeOpen)); } - /** @test */ + #[Test] public function next_close_with_overflow() { $openingHours = OpeningHours::create([ @@ -84,7 +85,7 @@ public function next_close_with_overflow() $this->assertSame('2019-04-23 02:00:00', $openingHours->nextClose($shouldBeOpen)->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function next_close_with_overflow_immutable() { $openingHours = OpeningHours::create([ @@ -141,7 +142,7 @@ public function next_close_with_overflow_immutable() $this->assertSame('2019-04-22 02:00:00', $previousTimeOpen); } - /** @test */ + #[Test] public function overflow_on_simple_ranges() { //Tuesday 4th of June 2019, 11.35 am diff --git a/tests/OpeningHoursStructuredDataTest.php b/tests/OpeningHoursStructuredDataTest.php index 3c582e5..16d6cb4 100644 --- a/tests/OpeningHoursStructuredDataTest.php +++ b/tests/OpeningHoursStructuredDataTest.php @@ -3,12 +3,13 @@ namespace Spatie\OpeningHours\Test; use DateTimeZone; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\OpeningHours\OpeningHours; class OpeningHoursStructuredDataTest extends TestCase { - /** @test */ + #[Test] public function it_can_render_opening_hours_as_an_array_of_structured_data() { $openingHours = OpeningHours::create([ diff --git a/tests/OpeningHoursTest.php b/tests/OpeningHoursTest.php index 3210d3c..7b89e75 100644 --- a/tests/OpeningHoursTest.php +++ b/tests/OpeningHoursTest.php @@ -6,6 +6,8 @@ use DateTimeImmutable; use DateTimeZone; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\OpeningHours\Day; use Spatie\OpeningHours\Exceptions\InvalidDateRange; @@ -18,7 +20,7 @@ class OpeningHoursTest extends TestCase { - /** @test */ + #[Test] public function it_can_return_the_opening_hours_for_a_regular_week() { $openingHours = OpeningHours::create([ @@ -37,7 +39,7 @@ public function it_can_return_the_opening_hours_for_a_regular_week() $this->assertCount(0, $openingHoursForWeek['sunday']); } - /** @test */ + #[Test] public function it_can_return_consecutive_opening_hours_for_a_regular_week() { $openingHours = OpeningHours::create([ @@ -104,7 +106,7 @@ public function it_can_return_consecutive_opening_hours_for_a_regular_week() ], $dump); } - /** @test */ + #[Test] public function it_can_return_combined_opening_hours_for_a_regular_week() { $openingHours = OpeningHours::create([ @@ -143,7 +145,7 @@ public function it_can_return_combined_opening_hours_for_a_regular_week() ], $dump); } - /** @test */ + #[Test] public function it_can_validate_the_opening_hours() { $valid = OpeningHours::isValid([ @@ -158,7 +160,7 @@ public function it_can_validate_the_opening_hours() $this->assertFalse($invalid); } - /** @test */ + #[Test] public function it_can_return_the_exceptions() { $openingHours = OpeningHours::create([ @@ -174,7 +176,7 @@ public function it_can_return_the_exceptions() $this->assertCount(0, $exceptions['2016-09-26']); } - /** @test */ + #[Test] public function it_can_return_the_opening_hours_for_a_regular_week_day() { $openingHours = OpeningHours::create([ @@ -190,7 +192,7 @@ public function it_can_return_the_opening_hours_for_a_regular_week_day() $this->assertCount(0, $openingHoursForTuesday); } - /** @test */ + #[Test] public function it_can_determine_that_its_regularly_open_on_a_week_day() { $openingHours = OpeningHours::create([ @@ -207,7 +209,7 @@ public function it_can_determine_that_its_regularly_open_on_a_week_day() $this->assertFalse($openingHours->isOpenOn((new DateTime('First Tuesday of January'))->format('m-d'))); } - /** @test */ + #[Test] public function it_can_determine_that_its_regularly_closed_on_a_week_day() { $openingHours = OpeningHours::create([ @@ -224,7 +226,7 @@ public function it_can_determine_that_its_regularly_closed_on_a_week_day() $this->assertTrue($openingHours->isClosedOn((new DateTime('First Tuesday of January'))->format('m-d'))); } - /** @test */ + #[Test] public function it_can_return_the_opening_hours_for_a_specific_date() { $openingHours = OpeningHours::create([ @@ -253,7 +255,7 @@ public function it_can_return_the_opening_hours_for_a_specific_date() $this->assertCount(0, $openingHoursForMonday2609); } - /** @test */ + #[Test] public function it_can_determine_that_its_open_at_a_certain_date_and_time() { $openingHours = OpeningHours::create([ @@ -289,7 +291,7 @@ public function it_can_determine_that_its_open_at_a_certain_date_and_time() $this->assertTrue($openingHours->isClosedAt($shouldBeClosedBecauseOfDay)); } - /** @test */ + #[Test] public function it_can_determine_that_its_open_at_a_certain_date_and_time_on_an_exceptional_day() { $openingHours = OpeningHours::create([ @@ -308,7 +310,7 @@ public function it_can_determine_that_its_open_at_a_certain_date_and_time_on_an_ $this->assertTrue($openingHours->isClosedAt($shouldBeClosed)); } - /** @test */ + #[Test] public function it_can_determine_that_its_open_at_a_certain_date_and_time_on_an_recurring_exceptional_day() { $openingHours = OpeningHours::create([ @@ -345,7 +347,7 @@ public function it_can_determine_that_its_open_at_a_certain_date_and_time_on_an_ $this->assertFalse($openingHours->isClosedAt($openOnChristmasMorning)); } - /** @test */ + #[Test] public function it_can_prioritize_exceptions_by_giving_full_dates_priority() { $openingHours = OpeningHours::create([ @@ -374,7 +376,7 @@ public function it_can_prioritize_exceptions_by_giving_full_dates_priority() $this->assertTrue($openingHours->isClosedAt($closedOnNewYearDay2019)); } - /** @test */ + #[Test] public function it_can_handle_consecutive_open_hours() { $openingHours = OpeningHours::create([ @@ -442,7 +444,7 @@ public function it_can_handle_consecutive_open_hours() $this->assertSame('2022-08-04 00:00:00', $openingHours->previousClose($friday)->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_can_determine_next_open_hours_from_non_working_date_time() { $openingHours = OpeningHours::create([ @@ -460,7 +462,7 @@ public function it_can_determine_next_open_hours_from_non_working_date_time() $this->assertSame('2016-09-26 09:00:00', $previousTimeOpen->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_can_determine_next_open_hours_from_edges_time() { $openingHours = OpeningHours::create([ @@ -549,7 +551,7 @@ public function it_can_determine_next_open_hours_from_edges_time() $this->assertSame('2016-09-26 13:00:00', $previousTimeOpen->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_can_determine_next_open_hours_from_mixed_structures() { $openingHours = OpeningHours::create([ @@ -653,7 +655,7 @@ public function it_can_determine_next_open_hours_from_mixed_structures() $this->assertSame('2019-02-18 11:00:00', $nextTimeClose->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_can_determine_next_open_hours_from_non_working_date_time_immutable() { $openingHours = OpeningHours::create([ @@ -672,7 +674,7 @@ public function it_can_determine_next_open_hours_from_non_working_date_time_immu $this->assertSame('2016-09-26 13:00:00', $nextTimeOpen->foo()); } - /** @test */ + #[Test] public function it_can_determine_next_close_hours_from_non_working_date_time() { $ranges = [ @@ -721,7 +723,7 @@ public function it_can_determine_next_close_hours_from_non_working_date_time() $this->assertSame('09:00-18:00', strval($openingHours->forDate(new DateTime('2016-11-14')))); } - /** @test */ + #[Test] public function it_can_determine_next_close_hours_from_non_working_date_time_immutable() { $openingHours = OpeningHours::create([ @@ -734,7 +736,7 @@ public function it_can_determine_next_close_hours_from_non_working_date_time_imm $this->assertSame('2016-09-26 19:00:00', $nextTimeOpen->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_can_determine_next_open_hours_from_working_date_time() { $openingHours = OpeningHours::create([ @@ -748,7 +750,7 @@ public function it_can_determine_next_open_hours_from_working_date_time() $this->assertSame('2016-09-27 10:00:00', $nextTimeOpen->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_can_determine_next_open_hours_from_working_date_time_immutable() { $openingHours = OpeningHours::create([ @@ -762,7 +764,7 @@ public function it_can_determine_next_open_hours_from_working_date_time_immutabl $this->assertSame('2016-09-27 10:00:00', $nextTimeOpen->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_can_determine_next_close_hours_from_working_date_time() { $openingHours = OpeningHours::create([ @@ -776,7 +778,7 @@ public function it_can_determine_next_close_hours_from_working_date_time() $this->assertSame('2016-09-26 19:00:00', $nextTimeClose->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_can_determine_next_close_hours_from_working_date_time_immutable() { $openingHours = OpeningHours::create([ @@ -790,7 +792,7 @@ public function it_can_determine_next_close_hours_from_working_date_time_immutab $this->assertSame('2016-09-26 19:00:00', $nextTimeClose->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_can_determine_next_open_hours_from_early_morning() { $openingHours = OpeningHours::create([ @@ -807,7 +809,7 @@ public function it_can_determine_next_open_hours_from_early_morning() $this->assertSame('2016-09-27 10:00:00', $nextTimeOpen->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_can_determine_next_open_hours_from_early_morning_immutable() { $openingHours = OpeningHours::create([ @@ -824,7 +826,7 @@ public function it_can_determine_next_open_hours_from_early_morning_immutable() $this->assertSame('2016-09-27 10:00:00', $nextTimeOpen->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_can_determine_next_close_hours_from_early_morning() { $openingHours = OpeningHours::create([ @@ -841,7 +843,7 @@ public function it_can_determine_next_close_hours_from_early_morning() $this->assertSame('2016-09-27 11:00:00', $nextClosedTime->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_can_determine_next_close_hours_from_early_morning_immutable() { $openingHours = OpeningHours::create([ @@ -858,7 +860,7 @@ public function it_can_determine_next_close_hours_from_early_morning_immutable() $this->assertSame('2016-09-27 11:00:00', $nextClosedTime->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_can_set_the_timezone_on_the_openings_hours_object() { $openingHours = OpeningHours::create([ @@ -914,11 +916,8 @@ public function it_can_set_the_timezone_on_the_openings_hours_object() date_default_timezone_set($timezone); } - /** - * @test - * - * @dataProvider timezones - */ + #[Test] + #[DataProvider('timezones')] public function it_can_handle_timezone_for_date_string($timezone) { $openingHours = OpeningHours::create([ @@ -938,7 +937,7 @@ public static function timezones(): array ]; } - /** @test */ + #[Test] public function it_can_determine_that_its_open_now() { $openingHours = OpeningHours::create([ @@ -954,7 +953,7 @@ public function it_can_determine_that_its_open_now() $this->assertTrue($openingHours->isOpen()); } - /** @test */ + #[Test] public function it_can_use_day_enum() { $openingHours = new class extends OpeningHours @@ -970,7 +969,7 @@ public function __construct() $this->assertSame(['monday'], $openingHours->days); } - /** @test */ + #[Test] public function it_can_determine_that_its_closed_now() { $openingHours = OpeningHours::create([]); @@ -978,7 +977,7 @@ public function it_can_determine_that_its_closed_now() $this->assertTrue($openingHours->isClosed()); } - /** @test */ + #[Test] public function it_can_retrieve_regular_closing_days_as_strings() { $openingHours = OpeningHours::create([ @@ -994,7 +993,7 @@ public function it_can_retrieve_regular_closing_days_as_strings() $this->assertSame(['saturday', 'sunday'], $openingHours->regularClosingDays()); } - /** @test */ + #[Test] public function it_can_retrieve_regular_closing_days_as_iso_numbers() { $openingHours = OpeningHours::create([ @@ -1010,7 +1009,7 @@ public function it_can_retrieve_regular_closing_days_as_iso_numbers() $this->assertSame([6, 7], $openingHours->regularClosingDaysISO()); } - /** @test */ + #[Test] public function it_can_retrieve_a_list_of_exceptional_closing_dates() { $openingHours = OpeningHours::create([ @@ -1027,7 +1026,7 @@ public function it_can_retrieve_a_list_of_exceptional_closing_dates() $this->assertSame('2017-06-02', $exceptionalClosingDates[1]->format('Y-m-d')); } - /** @test */ + #[Test] public function it_works_when_starting_at_midnight() { $openingHours = OpeningHours::create([ @@ -1038,7 +1037,7 @@ public function it_works_when_starting_at_midnight() $this->assertInstanceOf(DateTime::class, $nextTimeOpen); } - /** @test */ + #[Test] public function it_works_when_starting_at_midnight_immutable() { $openingHours = OpeningHours::create([ @@ -1049,7 +1048,7 @@ public function it_works_when_starting_at_midnight_immutable() $this->assertInstanceOf(DateTimeImmutable::class, $nextTimeOpen); } - /** @test */ + #[Test] public function it_can_set_the_timezone_on_construct_with_date_time_zone() { $openingHours = OpeningHours::create([ @@ -1067,7 +1066,7 @@ public function it_can_set_the_timezone_on_construct_with_date_time_zone() $this->assertCount(0, $openingHoursForWeek['sunday']); } - /** @test */ + #[Test] public function it_can_set_the_timezone_on_construct_with_string() { $openingHours = OpeningHours::create([ @@ -1085,7 +1084,7 @@ public function it_can_set_the_timezone_on_construct_with_string() $this->assertCount(0, $openingHoursForWeek['sunday']); } - /** @test */ + #[Test] public function it_throws_an_exception_on_invalid_timezone() { $this->expectException(InvalidArgumentException::class); @@ -1096,7 +1095,7 @@ public function it_throws_an_exception_on_invalid_timezone() ]); } - /** @test */ + #[Test] public function it_throws_an_exception_on_limit_exceeded_void_array_next_open() { $this->expectException(MaximumLimitExceeded::class); @@ -1105,7 +1104,7 @@ public function it_throws_an_exception_on_limit_exceeded_void_array_next_open() OpeningHours::create([])->nextOpen(new DateTime('2019-06-06 19:02:00')); } - /** @test */ + #[Test] public function it_throws_an_exception_on_limit_exceeded_void_array_previous_open() { $this->expectException(MaximumLimitExceeded::class); @@ -1114,7 +1113,7 @@ public function it_throws_an_exception_on_limit_exceeded_void_array_previous_ope OpeningHours::create([])->previousOpen(new DateTime('2019-06-06 19:02:00')); } - /** @test */ + #[Test] public function it_throws_an_exception_on_limit_exceeded_full_array_next_open() { $this->expectException(MaximumLimitExceeded::class); @@ -1131,7 +1130,7 @@ public function it_throws_an_exception_on_limit_exceeded_full_array_next_open() ])->nextOpen(new DateTime('2019-06-06 19:02:00')); } - /** @test */ + #[Test] public function it_throws_an_exception_on_limit_exceeded_full_array_previous_open() { $this->expectException(MaximumLimitExceeded::class); @@ -1148,7 +1147,7 @@ public function it_throws_an_exception_on_limit_exceeded_full_array_previous_ope ])->previousOpen(new DateTime('2019-06-06 19:02:00')); } - /** @test */ + #[Test] public function it_throws_an_exception_on_limit_exceeded_full_array_next_open_with_exceptions() { $this->expectException(MaximumLimitExceeded::class); @@ -1168,7 +1167,7 @@ public function it_throws_an_exception_on_limit_exceeded_full_array_next_open_wi ])->nextOpen(new DateTime('2019-06-06 19:02:00')); } - /** @test */ + #[Test] public function it_throws_an_exception_on_search_limit_exceeded_with_next_open() { $this->expectException(SearchLimitReached::class); @@ -1180,7 +1179,7 @@ public function it_throws_an_exception_on_search_limit_exceeded_with_next_open() ); } - /** @test */ + #[Test] public function it_throws_an_exception_on_search_limit_exceeded_with_next_close() { $this->expectException(SearchLimitReached::class); @@ -1192,7 +1191,7 @@ public function it_throws_an_exception_on_search_limit_exceeded_with_next_close( ); } - /** @test */ + #[Test] public function it_throws_an_exception_on_search_limit_exceeded_with_previous_open() { $this->expectException(SearchLimitReached::class); @@ -1204,7 +1203,7 @@ public function it_throws_an_exception_on_search_limit_exceeded_with_previous_op ); } - /** @test */ + #[Test] public function it_throws_an_exception_on_search_limit_exceeded_with_previous_close() { $this->expectException(SearchLimitReached::class); @@ -1216,7 +1215,7 @@ public function it_throws_an_exception_on_search_limit_exceeded_with_previous_cl ); } - /** @test */ + #[Test] public function it_stops_at_cap_limit_with_next_open() { $this->assertSame( @@ -1229,7 +1228,7 @@ public function it_stops_at_cap_limit_with_next_open() ); } - /** @test */ + #[Test] public function it_stops_at_cap_limit_exceeded_with_next_close() { $this->assertSame( @@ -1242,7 +1241,7 @@ public function it_stops_at_cap_limit_exceeded_with_next_close() ); } - /** @test */ + #[Test] public function it_stops_at_cap_limit_with_previous_open() { $this->assertSame( @@ -1255,7 +1254,7 @@ public function it_stops_at_cap_limit_with_previous_open() ); } - /** @test */ + #[Test] public function it_stops_at_cap_limit_exceeded_with_previous_close() { $this->assertSame( @@ -1268,7 +1267,7 @@ public function it_stops_at_cap_limit_exceeded_with_previous_close() ); } - /** @test */ + #[Test] public function it_throws_an_exception_on_limit_exceeded_void_array_next_close() { $this->expectException(MaximumLimitExceeded::class); @@ -1277,7 +1276,7 @@ public function it_throws_an_exception_on_limit_exceeded_void_array_next_close() OpeningHours::create([])->nextClose(new DateTime('2019-06-06 19:02:00')); } - /** @test */ + #[Test] public function it_throws_an_exception_on_limit_exceeded_void_array_previous_close() { $this->expectException(MaximumLimitExceeded::class); @@ -1286,7 +1285,7 @@ public function it_throws_an_exception_on_limit_exceeded_void_array_previous_clo OpeningHours::create([])->previousClose(new DateTime('2019-06-06 19:02:00')); } - /** @test */ + #[Test] public function it_throws_an_exception_on_limit_exceeded_full_array_next_close() { $this->expectException(MaximumLimitExceeded::class); @@ -1303,7 +1302,7 @@ public function it_throws_an_exception_on_limit_exceeded_full_array_next_close() ])->nextClose(new DateTime('2019-06-06 19:02:00')); } - /** @test */ + #[Test] public function it_throws_an_exception_on_limit_exceeded_full_array_previous_close() { $this->expectException(MaximumLimitExceeded::class); @@ -1320,7 +1319,7 @@ public function it_throws_an_exception_on_limit_exceeded_full_array_previous_clo ])->previousClose(new DateTime('2019-06-06 19:02:00')); } - /** @test */ + #[Test] public function it_should_handle_far_exception() { $this->assertSame('2019-12-25 00:00:00', OpeningHours::create([ @@ -1337,7 +1336,7 @@ public function it_should_handle_far_exception() ])->nextClose(new DateTime('2019-06-06 19:02:00'))->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_should_handle_very_far_future_exception_by_changing_limit() { $openingHours = OpeningHours::create([ @@ -1357,7 +1356,7 @@ public function it_should_handle_very_far_future_exception_by_changing_limit() $this->assertSame('2022-12-25 00:00:00', $openingHours->nextClose(new DateTime('2019-06-06 19:02:00'))->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_should_handle_very_far_past_exception_by_changing_limit() { $openingHours = OpeningHours::create([ @@ -1377,7 +1376,7 @@ public function it_should_handle_very_far_past_exception_by_changing_limit() $this->assertSame('2013-12-26 00:00:00', $openingHours->previousOpen(new DateTime('2019-06-06 19:02:00'))->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_should_handle_open_range() { $openingHours = OpeningHours::create([ @@ -1423,7 +1422,7 @@ public function it_should_handle_open_range() $this->assertSame('2020-09-22 02:30', $range->end()->date()->format('Y-m-d H:i')); } - /** @test */ + #[Test] public function it_should_handle_open_start_date_time() { $openingHours = OpeningHours::create([ @@ -1448,7 +1447,7 @@ public function it_should_handle_open_start_date_time() $this->assertSame('2019-07-17 07:00:00', $openingHours->currentOpenRangeStart(new DateTime('2019-07-17 07:59:59'))->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_should_handle_open_end_date_time() { $openingHours = OpeningHours::create([ @@ -1473,7 +1472,7 @@ public function it_should_handle_open_end_date_time() $this->assertSame('2019-07-17 10:00:00', $openingHours->currentOpenRangeEnd(new DateTime('2019-07-17 07:59:59'))->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_should_support_empty_arrays_with_merge() { $hours = OpeningHours::createAndMergeOverlappingRanges( @@ -1498,7 +1497,7 @@ public function it_should_support_empty_arrays_with_merge() $this->assertTrue($hours->isClosedAt(new DateTimeImmutable('2020-01-01'))); } - /** @test */ + #[Test] public function it_can_calculate_time_diff() { $openingHours = OpeningHours::create([ diff --git a/tests/PreciseTimeTest.php b/tests/PreciseTimeTest.php index a4d58aa..33c7c13 100644 --- a/tests/PreciseTimeTest.php +++ b/tests/PreciseTimeTest.php @@ -5,12 +5,13 @@ use DateTimeImmutable; use DateTimeZone; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\OpeningHours\PreciseTime; class PreciseTimeTest extends TestCase { - /** @test */ + #[Test] public function it_can_be_formatted() { $date = new DateTimeImmutable('2022-08-07 23:32:58.123456 America/Toronto'); @@ -24,7 +25,7 @@ public function it_can_be_formatted() ); } - /** @test */ + #[Test] public function it_can_return_original_datetime() { $date = new DateTimeImmutable('2022-08-07 23:32:58.123456 America/Toronto'); @@ -34,7 +35,7 @@ public function it_can_return_original_datetime() )->format('Y-m-d H:i:s'.(PHP_VERSION < 7.1 ? '' : '.u').' e')); } - /** @test */ + #[Test] public function it_can_return_diff() { $date = new DateTimeImmutable('2021-08-07 23:32:58.123456 America/Toronto'); @@ -46,7 +47,7 @@ public function it_can_return_diff() ); } - /** @test */ + #[Test] public function it_can_be_compared() { $date = new DateTimeImmutable('2022-08-07 23:32:58.123456 America/Toronto'); @@ -63,7 +64,7 @@ public function it_can_be_compared() ))); } - /** @test */ + #[Test] public function it_can_output_hours_and_minutes() { $date = PreciseTime::fromString('2022-08-07 23:32:58.123456 America/Toronto'); @@ -71,7 +72,7 @@ public function it_can_output_hours_and_minutes() $this->assertSame(32, $date->minutes()); } - /** @test */ + #[Test] public function it_cannot_have_date_reference_point() { $this->expectExceptionObject(new InvalidArgumentException( diff --git a/tests/TimeRangeTest.php b/tests/TimeRangeTest.php index e20cf99..cf432c8 100644 --- a/tests/TimeRangeTest.php +++ b/tests/TimeRangeTest.php @@ -2,6 +2,7 @@ namespace Spatie\OpeningHours\Test; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\OpeningHours\Exceptions\InvalidTimeRangeArray; use Spatie\OpeningHours\Exceptions\InvalidTimeRangeList; @@ -11,13 +12,13 @@ class TimeRangeTest extends TestCase { - /** @test */ + #[Test] public function it_can_be_created_from_a_string() { $this->assertSame('16:00-18:00', (string) TimeRange::fromString('16:00-18:00')); } - /** @test */ + #[Test] public function it_cant_be_created_from_an_invalid_range() { $this->expectException(InvalidTimeRangeString::class); @@ -25,7 +26,7 @@ public function it_cant_be_created_from_an_invalid_range() TimeRange::fromString('16:00/18:00'); } - /** @test */ + #[Test] public function it_will_throw_an_exception_when_passing_a_invalid_array() { $this->expectException(InvalidTimeRangeArray::class); @@ -33,7 +34,7 @@ public function it_will_throw_an_exception_when_passing_a_invalid_array() TimeRange::fromArray([]); } - /** @test */ + #[Test] public function it_will_throw_an_exception_when_passing_a_empty_array_to_list() { $this->expectException(InvalidTimeRangeList::class); @@ -41,7 +42,7 @@ public function it_will_throw_an_exception_when_passing_a_empty_array_to_list() TimeRange::fromList([]); } - /** @test */ + #[Test] public function it_will_throw_an_exception_when_passing_a_invalid_array_to_list() { $this->expectException(InvalidTimeRangeList::class); @@ -51,7 +52,7 @@ public function it_will_throw_an_exception_when_passing_a_invalid_array_to_list( ]); } - /** @test */ + #[Test] public function it_can_get_the_time_objects() { $timeRange = TimeRange::fromString('16:00-18:00'); @@ -60,14 +61,14 @@ public function it_can_get_the_time_objects() $this->assertInstanceOf(Time::class, $timeRange->end()); } - /** @test */ + #[Test] public function it_can_determine_that_it_spills_over_to_the_next_day() { $this->assertTrue(TimeRange::fromString('18:00-01:00')->spillsOverToNextDay()); $this->assertFalse(TimeRange::fromString('18:00-23:00')->spillsOverToNextDay()); } - /** @test */ + #[Test] public function it_can_determine_that_it_contains_a_time() { $this->assertTrue(TimeRange::fromString('16:00-18:00')->containsTime(Time::fromString('16:00'))); @@ -88,7 +89,7 @@ public function it_can_determine_that_it_contains_a_time() $this->assertFalse(TimeRange::fromMidnight(Time::fromString('01:00'))->containsTime(Time::fromString('01:00'))); } - /** @test */ + #[Test] public function it_can_determine_that_it_contains_a_time_over_midnight() { $this->assertFalse(TimeRange::fromString('10:00-18:00')->containsNightTime(Time::fromString('17:00'))); @@ -97,7 +98,7 @@ public function it_can_determine_that_it_contains_a_time_over_midnight() $this->assertTrue(TimeRange::fromString('18:00-10:00')->containsNightTime(Time::fromString('08:00'))); } - /** @test */ + #[Test] public function it_can_determine_that_it_overlaps_another_time_range() { $this->assertTrue(TimeRange::fromString('16:00-18:00')->overlaps(TimeRange::fromString('15:00-17:00'))); @@ -112,7 +113,7 @@ public function it_can_determine_that_it_overlaps_another_time_range() $this->assertFalse(TimeRange::fromString('16:00-18:00')->overlaps(TimeRange::fromString('19:00-20:00'))); } - /** @test */ + #[Test] public function it_can_be_formatted() { $this->assertSame('16:00-18:00', TimeRange::fromString('16:00-18:00')->format()); diff --git a/tests/TimeTest.php b/tests/TimeTest.php index 70df230..f57c4b7 100644 --- a/tests/TimeTest.php +++ b/tests/TimeTest.php @@ -4,13 +4,14 @@ use DateTime; use DateTimeImmutable; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\OpeningHours\Exceptions\InvalidTimeString; use Spatie\OpeningHours\Time; class TimeTest extends TestCase { - /** @test */ + #[Test] public function it_can_be_created_from_a_string() { $this->assertSame('00:00', (string) Time::fromString('00:00')); @@ -18,7 +19,7 @@ public function it_can_be_created_from_a_string() $this->assertSame('24:00', (string) Time::fromString('24:00')); } - /** @test */ + #[Test] public function it_cant_be_created_from_an_invalid_string() { $this->expectException(InvalidTimeString::class); @@ -26,7 +27,7 @@ public function it_cant_be_created_from_an_invalid_string() Time::fromString('aa:bb'); } - /** @test */ + #[Test] public function it_cant_be_created_from_an_invalid_hour() { $this->expectException(InvalidTimeString::class); @@ -34,7 +35,7 @@ public function it_cant_be_created_from_an_invalid_hour() Time::fromString('26:00'); } - /** @test */ + #[Test] public function it_cant_be_created_from_an_out_of_bound_hour() { $this->expectException(InvalidTimeString::class); @@ -42,7 +43,7 @@ public function it_cant_be_created_from_an_out_of_bound_hour() Time::fromString('24:01'); } - /** @test */ + #[Test] public function it_cant_be_created_from_an_invalid_minute() { $this->expectException(InvalidTimeString::class); @@ -50,7 +51,7 @@ public function it_cant_be_created_from_an_invalid_minute() Time::fromString('14:60'); } - /** @test */ + #[Test] public function it_can_be_created_from_a_date_time_instance() { $dateTime = new DateTime('2016-09-27 16:00:00'); @@ -62,7 +63,7 @@ public function it_can_be_created_from_a_date_time_instance() $this->assertSame('16:00', (string) Time::fromDateTime($dateTime)); } - /** @test */ + #[Test] public function it_can_determine_that_its_the_same_as_another_time() { $this->assertTrue(Time::fromString('09:00')->isSame(Time::fromString('09:00'))); @@ -70,7 +71,7 @@ public function it_can_determine_that_its_the_same_as_another_time() $this->assertFalse(Time::fromString('09:00')->isSame(Time::fromString('09:30'))); } - /** @test */ + #[Test] public function it_can_determine_that_its_before_another_time() { $this->assertTrue(Time::fromString('09:00')->isBefore(Time::fromString('10:00'))); @@ -81,7 +82,7 @@ public function it_can_determine_that_its_before_another_time() $this->assertFalse(Time::fromString('08:30')->isBefore(Time::fromString('08:00'))); } - /** @test */ + #[Test] public function it_can_determine_that_its_after_another_time() { $this->assertTrue(Time::fromString('09:00')->isAfter(Time::fromString('08:00'))); @@ -92,7 +93,7 @@ public function it_can_determine_that_its_after_another_time() $this->assertFalse(Time::fromString('09:00')->isAfter(Time::fromString('10:00'))); } - /** @test */ + #[Test] public function it_can_determine_that_its_the_same_or_after_another_time() { $this->assertTrue(Time::fromString('09:00')->isSameOrAfter(Time::fromString('08:00'))); @@ -102,7 +103,7 @@ public function it_can_determine_that_its_the_same_or_after_another_time() $this->assertFalse(Time::fromString('09:00')->isSameOrAfter(Time::fromString('10:00'))); } - /** @test */ + #[Test] public function it_can_accept_any_date_format_with_the_date_time_interface() { $dateTime = date_create_immutable('2012-11-06 13:25:59.123456'); @@ -110,7 +111,7 @@ public function it_can_accept_any_date_format_with_the_date_time_interface() $this->assertSame('13:25', (string) Time::fromDateTime($dateTime)); } - /** @test */ + #[Test] public function it_can_be_formatted() { $this->assertSame('09:00', Time::fromString('09:00')->format()); @@ -118,7 +119,7 @@ public function it_can_be_formatted() $this->assertSame('9 AM', Time::fromString('09:00')->format('g A')); } - /** @test */ + #[Test] public function it_can_get_hours_and_minutes() { $time = Time::fromString('16:30'); @@ -126,7 +127,7 @@ public function it_can_get_hours_and_minutes() $this->assertSame(30, $time->minutes()); } - /** @test */ + #[Test] public function it_can_calculate_diff() { $time1 = Time::fromString('16:30'); @@ -135,7 +136,7 @@ public function it_can_calculate_diff() $this->assertSame(25, $time1->diff($time2)->i); } - /** @test */ + #[Test] public function it_should_not_mutate_passed_datetime() { $dateTime = new DateTime('2016-09-27 12:00:00'); @@ -144,7 +145,7 @@ public function it_should_not_mutate_passed_datetime() $this->assertSame('2016-09-27 12:00:00', $dateTime->format('Y-m-d H:i:s')); } - /** @test */ + #[Test] public function it_should_not_mutate_passed_datetime_immutable() { $dateTime = new DateTimeImmutable('2016-09-27 12:00:00');