Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PHPUnit from 10 to 11 #246

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"require-dev": {
"kylekatarnls/multi-tester": "^2.5",
"phpunit/phpunit": "^10.4.2"
"phpunit/phpunit": "^11.2"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 2 additions & 1 deletion tests/ArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions tests/OpeningHoursCustomClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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([
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
25 changes: 13 additions & 12 deletions tests/OpeningHoursFillTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,7 +15,7 @@

class OpeningHoursFillTest extends TestCase
{
/** @test */
#[Test]
public function it_fills_opening_hours()
{
$openingHours = OpeningHours::create([
Expand Down Expand Up @@ -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([
Expand All @@ -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([
Expand All @@ -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([]);
Expand All @@ -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([
Expand All @@ -125,15 +126,15 @@ 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'));

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);
Expand All @@ -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([
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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([
Expand All @@ -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([
Expand Down
17 changes: 9 additions & 8 deletions tests/OpeningHoursForDayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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']);
Expand All @@ -25,15 +26,15 @@ 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);

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']);
Expand All @@ -43,15 +44,15 @@ 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']);

$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']);
Expand All @@ -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);
Expand All @@ -71,15 +72,15 @@ 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']);

$this->assertCount(2, $openingHoursForDay->getIterator()->getArrayCopy());
}

/** @test */
#[Test]
public function it_cant_set_iterator_item()
{
$this->expectException(NonMutableOffsets::class);
Expand Down
13 changes: 7 additions & 6 deletions tests/OpeningHoursOverflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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([
Expand Down Expand Up @@ -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([
Expand All @@ -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([
Expand All @@ -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([
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/OpeningHoursStructuredDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
Loading