diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 76570b9..e9c255b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,16 +10,9 @@ jobs: strategy: matrix: os: [ubuntu-latest] - php: [8.2] - laravel: [9.*, 10.*] - dependency-version: [prefer-lowest, prefer-stable] - include: - - laravel: 9.* - framework: ^9.0 - testbench: 7.* - - laravel: 10.* - framework: ^10.0 - testbench: 8.* + php: [8.2, 8.3] + laravel: [11.*] + dependency-version: [prefer-stable] name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ubuntu-latest steps: - name: Checkout code @@ -40,7 +33,6 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.framework }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction - name: Execute tests diff --git a/composer.json b/composer.json index 5002b64..7142f99 100644 --- a/composer.json +++ b/composer.json @@ -45,9 +45,9 @@ }, "require-dev": { "mockery/mockery": "^1.3.1", - "nunomaduro/collision": "^6.0 || ^7.0", - "phpunit/phpunit": "^9.0 || ^10.0", - "orchestra/testbench": "^7.0 || ^8.0", + "nunomaduro/collision": "^6.0 || ^7.0 || ^8.0", + "phpunit/phpunit": "^9.0 || ^10.0 || ^11.0", + "orchestra/testbench": "^7.0 || ^8.0 || ^9.0", "spatie/laravel-ray": "^1.35", "spatie/test-time": "^1.2" }, diff --git a/phpunit.xml b/phpunit.xml index 18f9dca..7d3ac12 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,12 +2,6 @@ - - ./tests/Unit - - - ./tests/Feature - ./tests diff --git a/src/Types/Event.php b/src/Types/Event.php index 36ef5c7..6697fcc 100644 --- a/src/Types/Event.php +++ b/src/Types/Event.php @@ -15,15 +15,21 @@ abstract class Event { abstract protected function rule(): RRuleInterface; - public function __construct(protected Entry $event) - { - } + public function __construct(protected Entry $event) {} public function __get(string $key): mixed { return $this->event->$key; } + /* + Can remove this once https://github.com/statamic/cms/pull/11402 is released + */ + public function __isset(string $key): bool + { + return isset($this->event->$key); + } + public function endTime(): string { return $this->end_time ?? now()->endOfDay()->toTimeString(); diff --git a/tests/Feature/EventsOffsetTest.php b/tests/Feature/EventsOffsetTest.php index d947ef1..96d0a35 100644 --- a/tests/Feature/EventsOffsetTest.php +++ b/tests/Feature/EventsOffsetTest.php @@ -3,118 +3,115 @@ namespace TransformStudios\Events\Tests\Feature; use Illuminate\Support\Carbon; -use Statamic\Facades\Cascade; +use PHPUnit\Framework\Attributes\Test; use Statamic\Facades\Entry; use TransformStudios\Events\Tags\Events; -use TransformStudios\Events\Tests\PreventSavingStacheItemsToDisk; use TransformStudios\Events\Tests\TestCase; class EventsOffsetTest extends TestCase { - use PreventSavingStacheItemsToDisk; - - private Events $tag; - - public function setUp(): void - { - parent::setUp(); - - Entry::make() - ->collection('events') - ->slug('recurring-event') - ->id('recurring-event') - ->data([ - 'title' => 'Recurring Event', - 'start_date' => Carbon::now()->toDateString(), - 'start_time' => '11:00', - 'end_time' => '12:00', - 'recurrence' => 'weekly', - 'categories' => ['one'], - ])->save(); - - $this->tag = app(Events::class); - } - - /** @test */ - public function canOffsetUpcomingOccurrences() - { - Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); - - $this->tag - ->setContext([]) - ->setParameters([ - 'collection' => 'events', - 'limit' => 5, - 'offset' => 2, - ]); - - $occurrences = $this->tag->upcoming(); - - $this->assertCount(3, $occurrences); - } - - /** @test */ - public function canOffsetBetweenOccurrences() - { - Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); - - $this->tag->setContext([]) - ->setParameters([ - 'collection' => 'events', - 'from' => Carbon::now()->toDateString(), - 'to' => Carbon::now()->addWeek(3), - 'offset' => 2, - ]); - - $occurrences = $this->tag->between(); - - $this->assertCount(2, $occurrences); - } - - /** @test */ - public function canOffsetTodayOccurrences() - { - Carbon::setTestNow(now()->setTimeFromTimeString('12:01')); - - Entry::make() - ->collection('events') - ->slug('single-event') - ->data([ - 'title' => 'Single Event', - 'start_date' => Carbon::now()->toDateString(), - 'start_time' => '13:00', - 'end_time' => '15:00', - ])->save(); - - $this->tag->setContext([]) - ->setParameters([ - 'collection' => 'events', - 'offset' => 1, - ]); - - $this->assertCount(1, $this->tag->today()); - - $this->tag->setContext([]) - ->setParameters([ - 'collection' => 'events', - 'ignore_finished' => true, - 'offset' => 1, - ]); - - $this->assertCount(0, $this->tag->today()); - } - - /** @test */ - public function canOffsetSingleDayOccurrences() - { - Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); - - $this->tag->setContext([]) - ->setParameters([ - 'collection' => 'events', - 'offset' => 1, - ]); - - $this->assertCount(0, $this->tag->today()); - } + private Events $tag; + + protected function setUp(): void + { + parent::setUp(); + + Entry::make() + ->collection('events') + ->slug('recurring-event') + ->id('recurring-event') + ->data([ + 'title' => 'Recurring Event', + 'start_date' => Carbon::now()->toDateString(), + 'start_time' => '11:00', + 'end_time' => '12:00', + 'recurrence' => 'weekly', + 'categories' => ['one'], + ])->save(); + + $this->tag = app(Events::class); + } + + #[Test] + public function can_offset_upcoming_occurrences() + { + Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); + + $this->tag + ->setContext([]) + ->setParameters([ + 'collection' => 'events', + 'limit' => 5, + 'offset' => 2, + ]); + + $occurrences = $this->tag->upcoming(); + + $this->assertCount(3, $occurrences); + } + + #[Test] + public function can_offset_between_occurrences() + { + Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); + + $this->tag->setContext([]) + ->setParameters([ + 'collection' => 'events', + 'from' => Carbon::now()->toDateString(), + 'to' => Carbon::now()->addWeek(3), + 'offset' => 2, + ]); + + $occurrences = $this->tag->between(); + + $this->assertCount(2, $occurrences); + } + + #[Test] + public function can_offset_today_occurrences() + { + Carbon::setTestNow(now()->setTimeFromTimeString('12:01')); + + Entry::make() + ->collection('events') + ->slug('single-event') + ->data([ + 'title' => 'Single Event', + 'start_date' => Carbon::now()->toDateString(), + 'start_time' => '13:00', + 'end_time' => '15:00', + ])->save(); + + $this->tag->setContext([]) + ->setParameters([ + 'collection' => 'events', + 'offset' => 1, + ]); + + $this->assertCount(1, $this->tag->today()); + + $this->tag->setContext([]) + ->setParameters([ + 'collection' => 'events', + 'ignore_finished' => true, + 'offset' => 1, + ]); + + $this->assertCount(0, $this->tag->today()); + } + + #[Test] + public function can_offset_single_day_occurrences() + { + Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); + + $this->tag->setContext([]) + ->setParameters([ + 'collection' => 'events', + 'offset' => 1, + ]); + + $this->assertCount(0, $this->tag->today()); + } } diff --git a/tests/Feature/IcsControllerTest.php b/tests/Feature/IcsControllerTest.php index 3dcf1ec..8aa8aa4 100755 --- a/tests/Feature/IcsControllerTest.php +++ b/tests/Feature/IcsControllerTest.php @@ -3,15 +3,13 @@ namespace TransformStudios\Events\Tests\Feature; use Illuminate\Support\Carbon; +use PHPUnit\Framework\Attributes\Test; use Statamic\Facades\Entry; -use TransformStudios\Events\Tests\PreventSavingStacheItemsToDisk; use TransformStudios\Events\Tests\TestCase; class IcsControllerTest extends TestCase { - use PreventSavingStacheItemsToDisk; - - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -28,8 +26,8 @@ public function setUp(): void ])->save(); } - /** @test */ - public function canCreateSingleDayEventIcsFile() + #[Test] + public function can_create_single_day_event_ics_file() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -38,12 +36,12 @@ public function canCreateSingleDayEventIcsFile() 'event' => 'the-id', ]))->assertDownload('single-event.ics'); - $this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis\Z'), $response->streamedContent()); + $this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent()); $this->assertStringContainsString('LOCATION:The Location', $response->streamedContent()); } - /** @test */ - public function canCreateSingleDayRecurringEventIcsFile() + #[Test] + public function can_create_single_day_recurring_event_ics_file() { Carbon::setTestNow(now()->addDay()->setTimeFromTimeString('10:00')); @@ -64,7 +62,7 @@ public function canCreateSingleDayRecurringEventIcsFile() 'event' => 'the-recurring-id', ]))->assertDownload('recurring-event.ics'); - $this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis\Z'), $response->streamedContent()); + $this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent()); $this->get(route('statamic.events.ics.show', [ 'date' => now()->addDay()->toDateString(), @@ -72,8 +70,8 @@ public function canCreateSingleDayRecurringEventIcsFile() ]))->assertStatus(404); } - /** @test */ - public function canCreateSingleDayMultidayEventIcsFile() + #[Test] + public function can_create_single_day_multiday_event_ics_file() { Carbon::setTestNow(now()); @@ -113,11 +111,11 @@ public function canCreateSingleDayMultidayEventIcsFile() 'event' => 'the-multi-day-event', ]))->assertDownload('multi-day-event.ics'); - $this->assertStringContainsString('DTSTART:'.now()->addDay()->setTimeFromTimeString('11:00')->format('Ymd\THis\Z'), $response->streamedContent()); + $this->assertStringContainsString('DTSTART:'.now()->addDay()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent()); } - /** @test */ - public function throws404ErrorWhenEventDoesNotOccurOnDate() + #[Test] + public function throws404_error_when_event_does_not_occur_on_date() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -127,8 +125,8 @@ public function throws404ErrorWhenEventDoesNotOccurOnDate() ]))->assertStatus(404); } - /** @test */ - public function throws404ErrorWhenEventDoesNotExist() + #[Test] + public function throws404_error_when_event_does_not_exist() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); diff --git a/tests/Feature/TagTest.php b/tests/Feature/TagTest.php index 141199d..95f3d29 100755 --- a/tests/Feature/TagTest.php +++ b/tests/Feature/TagTest.php @@ -3,20 +3,18 @@ namespace TransformStudios\Events\Tests\Feature; use Illuminate\Support\Carbon; +use PHPUnit\Framework\Attributes\Test; use Statamic\Facades\Cascade; use Statamic\Facades\Entry; use Statamic\Support\Arr; use TransformStudios\Events\Tags\Events; -use TransformStudios\Events\Tests\PreventSavingStacheItemsToDisk; use TransformStudios\Events\Tests\TestCase; class TagTest extends TestCase { - use PreventSavingStacheItemsToDisk; - private Events $tag; - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -36,8 +34,8 @@ public function setUp(): void $this->tag = app(Events::class); } - /** @test */ - public function canGenerateBetweenOccurrences() + #[Test] + public function can_generate_between_occurrences() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -54,8 +52,8 @@ public function canGenerateBetweenOccurrences() $this->assertCount(4, $occurrences); } - /** @test */ - public function canGenerateBetweenOccurrencesWithDefaultFrom() + #[Test] + public function can_generate_between_occurrences_with_default_from() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -71,8 +69,8 @@ public function canGenerateBetweenOccurrencesWithDefaultFrom() $this->assertCount(4, $occurrences); } - /** @test */ - public function canGenerateCalendarOccurrences() + #[Test] + public function can_generate_calendar_occurrences() { Carbon::setTestNow('jan 1, 2022 10:00'); @@ -116,8 +114,8 @@ public function canGenerateCalendarOccurrences() $this->assertCount(1, Arr::get($occurrences, '13.dates')); } - /** @test */ - public function canGenerateInOccurrences() + #[Test] + public function can_generate_in_occurrences() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -133,8 +131,8 @@ public function canGenerateInOccurrences() $this->assertCount(4, $occurrences); } - /** @test */ - public function canGenerateTodayOccurrences() + #[Test] + public function can_generate_today_occurrences() { Carbon::setTestNow(now()->setTimeFromTimeString('12:01')); @@ -166,8 +164,8 @@ public function canGenerateTodayOccurrences() $this->assertCount(1, $this->tag->today()); } - /** @test */ - public function canGenerateUpcomingOccurrences() + #[Test] + public function can_generate_upcoming_occurrences() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -183,8 +181,8 @@ public function canGenerateUpcomingOccurrences() $this->assertCount(3, $occurrences); } - /** @test */ - public function canGenerateUpcomingLimitedOccurrences() + #[Test] + public function can_generate_upcoming_limited_occurrences() { Entry::make() ->collection('events') @@ -212,8 +210,8 @@ public function canGenerateUpcomingLimitedOccurrences() $this->assertCount(3, $occurrences); } - /** @test */ - public function canPaginateUpcomingOccurrences() + #[Test] + public function can_paginate_upcoming_occurrences() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -240,8 +238,8 @@ public function canPaginateUpcomingOccurrences() $this->assertEquals('/events?page=2', $pagination['paginate']['next_page']); } - /** @test */ - public function canGenerateUpcomingOccurrencesWithTaxonomyTerms() + #[Test] + public function can_generate_upcoming_occurrences_with_taxonomy_terms() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -270,8 +268,8 @@ public function canGenerateUpcomingOccurrencesWithTaxonomyTerms() $this->assertCount(1, $occurrences); } - /** @test */ - public function canGenerateUpcomingOccurrencesWithFilter() + #[Test] + public function can_generate_upcoming_occurrences_with_filter() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -300,8 +298,8 @@ public function canGenerateUpcomingOccurrencesWithFilter() $this->assertCount(1, $occurrences); } - /** @test */ - public function canGenerateDateEventDownloadLink() + #[Test] + public function can_generate_date_event_download_link() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -318,8 +316,8 @@ public function canGenerateDateEventDownloadLink() $this->assertEquals('http://localhost/!/events/ics?collection=events&date='.now()->toDateString().'&event=recurring-event', $url); } - /** @test */ - public function canGenerateEventDownloadLink() + #[Test] + public function can_generate_event_download_link() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -335,8 +333,8 @@ public function canGenerateEventDownloadLink() $this->assertEquals('http://localhost/!/events/ics?collection=events&event=recurring-event', $url); } - /** @test */ - public function canSortOccurrencesDesc() + #[Test] + public function can_sort_occurrences_desc() { $this->tag diff --git a/tests/PreventSavingStacheItemsToDisk.php b/tests/PreventSavingStacheItemsToDisk.php deleted file mode 100644 index 22451c7..0000000 --- a/tests/PreventSavingStacheItemsToDisk.php +++ /dev/null @@ -1,30 +0,0 @@ -fakeStacheDirectory = Path::tidy($this->fakeStacheDirectory); - - Stache::stores()->each(function ($store) { - $dir = Path::tidy(__DIR__ . '/__fixtures__'); - $relative = str_after(str_after($store->directory(), $dir), '/'); - $store->directory($this->fakeStacheDirectory . '/' . $relative); - }); - } - - protected function deleteFakeStacheDirectory() - { - app('files')->deleteDirectory($this->fakeStacheDirectory); - - mkdir($this->fakeStacheDirectory); - touch($this->fakeStacheDirectory . '/.gitkeep'); - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php index ac4df4b..203cae0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,84 +2,32 @@ namespace TransformStudios\Events\Tests; -use Orchestra\Testbench\TestCase as OrchestraTestCase; use Statamic\Entries\Collection; -use Statamic\Extend\Manifest; use Statamic\Facades\Collection as CollectionFacade; use Statamic\Facades\Fieldset; use Statamic\Facades\Taxonomy; use Statamic\Facades\Term; use Statamic\Fields\Blueprint; use Statamic\Fields\BlueprintRepository; -use Statamic\Providers\StatamicServiceProvider; use Statamic\Statamic; +use Statamic\Testing\AddonTestCase; +use Statamic\Testing\Concerns\PreventsSavingStacheItemsToDisk; use TransformStudios\Events\ServiceProvider; -abstract class TestCase extends OrchestraTestCase +abstract class TestCase extends AddonTestCase { - use PreventSavingStacheItemsToDisk; + use PreventsSavingStacheItemsToDisk; + + protected string $addonServiceProvider = ServiceProvider::class; protected Collection $collection; protected Blueprint $blueprint; - public function setup(): void - { - parent::setup(); - $this->preventSavingStacheItemsToDisk(); - } - - public function tearDown(): void - { - $this->deleteFakeStacheDirectory(); - - parent::tearDown(); - } - - protected function getPackageProviders($app) - { - return [ - StatamicServiceProvider::class, - ServiceProvider::class, - ]; - } - - protected function getPackageAliases($app) - { - return [ - 'Statamic' => Statamic::class, - ]; - } - protected function getEnvironmentSetUp($app) { parent::getEnvironmentSetUp($app); - $app->make(Manifest::class)->manifest = [ - 'transformstudios/events' => [ - 'id' => 'transformstudios/events', - 'namespace' => 'TransformStudios\\Events', - ], - ]; - - // Statamic::pushActionRoutes(function () { - // return require_once realpath(__DIR__.'/../routes/actions.php'); - // }); - } - - protected function resolveApplicationConfiguration($app) - { - parent::resolveApplicationConfiguration($app); - - $configs = ['assets', 'cp', 'forms', 'routes', 'static_caching', 'sites', 'stache', 'system', 'users']; - - foreach ($configs as $config) { - $app['config']->set("statamic.$config", require __DIR__."/../vendor/statamic/cms/config/{$config}.php"); - } - - // Setting the user repository to the default flat file system - $app['config']->set('statamic.users.repository', 'file'); - // Assume the pro edition within tests $app['config']->set('statamic.editions.pro', true); $app['config']->set('events.timezone', 'UTC'); diff --git a/tests/Unit/DayTest.php b/tests/Unit/DayTest.php index 5a5b9d0..84c3ff5 100755 --- a/tests/Unit/DayTest.php +++ b/tests/Unit/DayTest.php @@ -3,13 +3,14 @@ namespace TransformStudios\Events\Tests\Unit; use Illuminate\Support\Carbon; +use PHPUnit\Framework\Attributes\Test; use TransformStudios\Events\Day; use TransformStudios\Events\Tests\TestCase; class DayTest extends TestCase { - /** @test */ - public function canGetEndWhenNoEndTime() + #[Test] + public function can_get_end_when_no_end_time() { $dayData = [ 'date' => '2019-11-23', @@ -24,8 +25,8 @@ public function canGetEndWhenNoEndTime() ); } - /** @test */ - public function hasNoEndTimeWhenNoEndTime() + #[Test] + public function has_no_end_time_when_no_end_time() { $dayData = [ 'date' => '2019-11-23', diff --git a/tests/Unit/EventFactoryTest.php b/tests/Unit/EventFactoryTest.php index 3986c1e..ad523d7 100755 --- a/tests/Unit/EventFactoryTest.php +++ b/tests/Unit/EventFactoryTest.php @@ -3,6 +3,8 @@ namespace TransformStudios\Events\Tests\Unit; use Illuminate\Support\Carbon; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Statamic\Facades\Entry; use TransformStudios\Events\EventFactory; use TransformStudios\Events\Tests\TestCase; @@ -12,12 +14,9 @@ class EventFactoryTest extends TestCase { - /** - * @test - * - * @dataProvider provideEventData - */ - public function canGetEventTypeClass(string $class, array $data) + #[Test] + #[DataProvider('provideEventData')] + public function can_get_event_type_class(string $class, array $data) { $entry = Entry::make() ->collection('events') @@ -26,12 +25,9 @@ public function canGetEventTypeClass(string $class, array $data) $this->assertEquals($class, EventFactory::getTypeClass($entry)); } - /** - * @test - * - * @dataProvider provideEventData - */ - public function canCreateCorrectEventType(string $class, array $data) + #[Test] + #[DataProvider('provideEventData')] + public function can_create_correct_event_type(string $class, array $data) { $entry = Entry::make() ->collection('events') diff --git a/tests/Unit/EventsTest.php b/tests/Unit/EventsTest.php index c927612..54aefb4 100755 --- a/tests/Unit/EventsTest.php +++ b/tests/Unit/EventsTest.php @@ -3,6 +3,7 @@ namespace TransformStudios\Events\Tests\Unit; use Illuminate\Support\Carbon; +use PHPUnit\Framework\Attributes\Test; use Statamic\Extensions\Pagination\LengthAwarePaginator; use Statamic\Facades\Entry; use TransformStudios\Events\EventFactory; @@ -11,8 +12,8 @@ class EventsTest extends TestCase { - /** @test */ - public function canGenerateDatesWhenNowBeforeStart() + #[Test] + public function can_generate_dates_when_now_before_start() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -54,8 +55,8 @@ public function canGenerateDatesWhenNowBeforeStart() $this->assertEquals($expectedStartDates[3], $occurrences[3]->start); } - /** @test */ - public function canPaginateUpcomingOccurrences() + #[Test] + public function can_paginate_upcoming_occurrences() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -91,8 +92,8 @@ public function canPaginateUpcomingOccurrences() $this->assertEquals(3, $paginator->currentPage()); } - /** @test */ - public function canPaginateOccurrencesBetween() + #[Test] + public function can_paginate_occurrences_between() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -122,8 +123,8 @@ public function canPaginateOccurrencesBetween() $this->assertEquals(now()->addDay()->setTimeFromTimeString('11:00'), $paginator->items()[1]->start); } - /** @test */ - public function canFilterEvents() + #[Test] + public function can_filter_events() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -156,8 +157,8 @@ public function canFilterEvents() $this->assertCount(10, $occurrences); } - /** @test */ - public function canFilterMultipleEvents() + #[Test] + public function can_filter_multiple_events() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -202,8 +203,8 @@ public function canFilterMultipleEvents() $this->assertCount(10, $occurrences); } - /** @test */ - public function canFilterByTermEvents() + #[Test] + public function can_filter_by_term_events() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -238,8 +239,8 @@ public function canFilterByTermEvents() $this->assertCount(10, $occurrences); } - /** @test */ - public function canFilterByFilterEvents() + #[Test] + public function can_filter_by_filter_events() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -272,8 +273,8 @@ public function canFilterByFilterEvents() $this->assertCount(10, $occurrences); } - /** @test */ - public function canDetermineOccursAtForSingleEvent() + #[Test] + public function can_determine_occurs_at_for_single_event() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -293,8 +294,8 @@ public function canDetermineOccursAtForSingleEvent() $this->assertTrue($event->occursOnDate(now())); } - /** @test */ - public function canDetermineOccursAtForMultidayEvent() + #[Test] + public function can_determine_occurs_at_for_multiday_event() { Carbon::setTestNow(now()); @@ -331,8 +332,8 @@ public function canDetermineOccursAtForMultidayEvent() $this->assertFalse($event->occursOnDate(now()->addDays(3))); } - /** @test */ - public function canExcludeDates() + #[Test] + public function can_exclude_dates() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -354,8 +355,8 @@ public function canExcludeDates() $this->assertCount(3, $occurrences); } - /** @test */ - public function canHandleEmptyExcludeDates() + #[Test] + public function can_handle_empty_exclude_dates() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); @@ -377,8 +378,8 @@ public function canHandleEmptyExcludeDates() $this->assertCount(4, $occurrences); } - /** @test */ - public function canFilterOurEventsWithNoStartDate() + #[Test] + public function can_filter_our_events_with_no_start_date() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); diff --git a/tests/Unit/MultiDayEventsTest.php b/tests/Unit/MultiDayEventsTest.php index 57605e2..48a0b78 100755 --- a/tests/Unit/MultiDayEventsTest.php +++ b/tests/Unit/MultiDayEventsTest.php @@ -3,7 +3,7 @@ namespace TransformStudios\Events\Tests\Unit; use Carbon\Carbon; -use Statamic\Facades\Blueprint; +use PHPUnit\Framework\Attributes\Test; use Statamic\Facades\Entry; use TransformStudios\Events\EventFactory; use TransformStudios\Events\Tests\TestCase; @@ -20,7 +20,7 @@ class MultiDayEventsTest extends TestCase /** @var MultiDayEvent */ private $noEndTimeEvnt; - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -90,7 +90,7 @@ public function setUp(): void $this->allDayEvent = EventFactory::createFromEntry($allDayEntry); } - /** @test */ + #[Test] public function canCreateMultiDayEvent() { $this->assertTrue($this->event instanceof MultiDayEvent); @@ -101,7 +101,7 @@ public function canCreateMultiDayEvent() $this->assertTrue($this->noEndTimeEvent->isMultiDay()); } - /** @test */ + #[Test] public function canGetStart() { $this->assertEquals( @@ -118,14 +118,14 @@ public function canGetStart() ); } - /** @test */ + #[Test] public function noOccurrencesIfNowAfterEndDate() { Carbon::setTestNow('2019-11-26'); $this->assertEmpty($this->event->nextOccurrences(1)); } - /** @test */ + #[Test] public function canGenerateNextOccurrenceIfBefore() { Carbon::setTestNowAndTimezone('2019-11-22', 'America/Vancouver'); @@ -140,7 +140,7 @@ public function canGenerateNextOccurrenceIfBefore() ); } - /** @test */ + #[Test] public function canGenerateNextOccurrenceIfDuring() { Carbon::setTestNowAndTimezone('2019-11-24 10:00', 'America/Vancouver'); @@ -150,16 +150,7 @@ public function canGenerateNextOccurrenceIfDuring() ); } - /** @test */ - public function canGenerateICalendar() - { - $this->markTestSkipped('revisit'); - $events = $this->event->toICalendarEvents(); - - dd($events); - } - - /** @test */ + #[Test] public function dayIsAllDayWhenNoStartAndEndTime() { $days = $this->allDayEvent->days(); diff --git a/tests/Unit/RecurringDailyEventsTest.php b/tests/Unit/RecurringDailyEventsTest.php index a6b905e..d2ffb50 100755 --- a/tests/Unit/RecurringDailyEventsTest.php +++ b/tests/Unit/RecurringDailyEventsTest.php @@ -4,13 +4,14 @@ use Carbon\Carbon; use Carbon\CarbonImmutable; +use PHPUnit\Framework\Attributes\Test; use Statamic\Facades\Entry; use TransformStudios\Events\EventFactory; use TransformStudios\Events\Tests\TestCase; class RecurringDailyEventsTest extends TestCase { - /** @test */ + #[Test] public function nullNextDateIfNowAfterEndDate() { $recurringEntry = Entry::make() @@ -31,7 +32,7 @@ public function nullNextDateIfNowAfterEndDate() $this->assertEmpty($nextOccurrences); } - /** @test */ + #[Test] public function canGenerateNextDayIfNowIsBefore() { $startDate = CarbonImmutable::now()->setTimeFromTimeString('11:00'); @@ -56,7 +57,7 @@ public function canGenerateNextDayIfNowIsBefore() $this->assertEquals($startDate, $nextOccurrences->first()->start); } - /** @test */ + #[Test] public function canGenerateNextOccurrenceIfNowIsDuring() { $startDate = CarbonImmutable::now()->setTimeFromTimeString('11:00'); diff --git a/tests/Unit/RecurringEventsTest.php b/tests/Unit/RecurringEventsTest.php index 587145c..c5a80c7 100755 --- a/tests/Unit/RecurringEventsTest.php +++ b/tests/Unit/RecurringEventsTest.php @@ -3,17 +3,17 @@ namespace TransformStudios\Events\Tests\Unit; use Carbon\Carbon; +use PHPUnit\Framework\Attributes\Test; use Statamic\Facades\Entry; use TransformStudios\Events\EventFactory; use TransformStudios\Events\Events; use TransformStudios\Events\Tests\TestCase; -use TransformStudios\Events\Types\MultiDayEvent; use TransformStudios\Events\Types\RecurringEvent; use TransformStudios\Events\Types\SingleDayEvent; class RecurringEventsTest extends TestCase { - /** @test */ + #[Test] public function canCreateRecurringEvent() { $recurringEntry = Entry::make() @@ -31,7 +31,7 @@ public function canCreateRecurringEvent() $this->assertFalse($event->isMultiDay()); } - /** @test */ + #[Test] public function wontCreateRecurringEventWhenMultiDay() { $recurringEntry = Entry::make() @@ -49,7 +49,7 @@ public function wontCreateRecurringEventWhenMultiDay() $this->assertFalse($event->isMultiDay()); } - /** @test */ + #[Test] public function canShowLastOccurrenceWhenNoEndTime() { Carbon::setTestNow(now()->setTimeFromTimeString('10:00')); diff --git a/tests/Unit/RecurringEveryXEventsTest.php b/tests/Unit/RecurringEveryXEventsTest.php index ad46b16..e05d604 100755 --- a/tests/Unit/RecurringEveryXEventsTest.php +++ b/tests/Unit/RecurringEveryXEventsTest.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use Carbon\CarbonImmutable; +use PHPUnit\Framework\Attributes\Test; use Statamic\Facades\Entry; use TransformStudios\Events\EventFactory; use TransformStudios\Events\Tests\TestCase; @@ -11,7 +12,7 @@ class RecurringEveryXEventsTest extends TestCase { - /** @test */ + #[Test] public function canCreateEveryXEvent() { $recurringEntry = Entry::make() @@ -30,7 +31,7 @@ public function canCreateEveryXEvent() $this->assertInstanceOf(RecurringEvent::class, $event); } - /** @test */ + #[Test] public function noOccurencesWhenNowAfterEndDate() { $recurringEntry = Entry::make() @@ -53,7 +54,7 @@ public function noOccurencesWhenNowAfterEndDate() $this->assertEmpty($nextOccurrences); } - /** @test */ + #[Test] public function canGenerateOccurrenceIfNowBefore() { $startDate = Carbon::now()->addDay()->setTimeFromTimeString('11:00'); @@ -82,7 +83,7 @@ public function canGenerateOccurrenceIfNowBefore() $this->assertEquals($startDate, $occurrences[0]->start); } - /** @test */ + #[Test] public function canGenerateOccurrenceIfDuring() { $startDate = CarbonImmutable::now()->setTimeFromTimeString('11:00'); @@ -104,7 +105,7 @@ public function canGenerateOccurrenceIfDuring() $this->assertEquals($startDate, $occurrences[0]->start); } - /** @test */ + #[Test] public function canGenerateOccurrenceIfNowAfterFirstDate() { $startDate = CarbonImmutable::now()->setTimeFromTimeString('11:00:00'); @@ -133,7 +134,7 @@ public function canGenerateOccurrenceIfNowAfterFirstDate() // $this->assertEquals($startDate, $nextDate->start()); } - /** @test */ + #[Test] public function canGenerateNextOccurrenceInWeeksIfNowAfterStart() { $startDate = CarbonImmutable::now()->setTimeFromTimeString('11:00:00'); @@ -158,7 +159,7 @@ public function canGenerateNextOccurrenceInWeeksIfNowAfterStart() $this->assertEquals($startDate->addWeeks(2), $occurrences[0]->start); } - /** @test */ + #[Test] public function canGenerateNextOccurrenceIfNow_after_weeks() { $recurringEntry = Entry::make() @@ -183,7 +184,7 @@ public function canGenerateNextOccurrenceIfNow_after_weeks() $this->assertEquals(Carbon::parse('2021-03-15')->setTimeFromTimeString('11:00:00'), $occurrences[0]->start); } - /** @test */ + #[Test] public function canGenerateNextOccurrenceIfNowDuringMonths() { $startDate = CarbonImmutable::now()->setTimeFromTimeString('11:00:00'); @@ -208,19 +209,19 @@ public function canGenerateNextOccurrenceIfNowDuringMonths() $this->assertEquals($startDate->setTimeFromTimeString('11:00:00'), $occurrences[0]->start); } - /** @test */ + #[Test] public function canGenerateNextXOccurrencesFromTodayBeforeEventTime() { $startDate = CarbonImmutable::now()->setTimeFromTimeString('11:00:00'); $recurringEntry = Entry::make() ->collection('events') ->data([ - 'start_date' => $startDate->toDateString(), - 'start_time' => '11:00', - 'end_time' => '12:00', - 'recurrence' => 'every', - 'interval' => 2, - 'period' => 'days', + 'start_date' => $startDate->toDateString(), + 'start_time' => '11:00', + 'end_time' => '12:00', + 'recurrence' => 'every', + 'interval' => 2, + 'period' => 'days', ]); $event = EventFactory::createFromEntry($recurringEntry); @@ -238,7 +239,7 @@ public function canGenerateNextXOccurrencesFromTodayBeforeEventTime() $this->assertEquals($events[1], $occurrences[1]->start); } - /** @test */ + #[Test] public function canGenerateAllOccurrencesWhenAfterStartDateDaily() { $startDate = CarbonImmutable::now()->setTimeFromTimeString('11:00:00'); @@ -253,7 +254,7 @@ public function canGenerateAllOccurrencesWhenAfterStartDateDaily() 'recurrence' => 'every', 'interval' => 2, 'period' => 'days', - ]); + ]); for ($x = 1; $x <= 2; $x++) { $events[] = $startDate->addDays($x * 2 + 1); diff --git a/tests/Unit/SingleDayEventsTest.php b/tests/Unit/SingleDayEventsTest.php index ebe2242..7e1227c 100755 --- a/tests/Unit/SingleDayEventsTest.php +++ b/tests/Unit/SingleDayEventsTest.php @@ -5,6 +5,7 @@ use Carbon\Carbon; use Carbon\CarbonImmutable; use Carbon\CarbonTimeZone; +use PHPUnit\Framework\Attributes\Test; use Statamic\Facades\Entry; use TransformStudios\Events\EventFactory; use TransformStudios\Events\Tests\TestCase; @@ -12,7 +13,7 @@ class SingleDayEventsTest extends TestCase { - /** @test */ + #[Test] public function canCreateSingleEvent() { $entry = Entry::make() @@ -34,7 +35,7 @@ public function canCreateSingleEvent() $this->assertEquals(new CarbonTimeZone('America/Vancouver'), $event->end()->timezone); } - /** @test */ + #[Test] public function canCreateSingleAllDayEvent() { $entry = Entry::make() @@ -50,7 +51,7 @@ public function canCreateSingleAllDayEvent() $this->assertTrue($event->isAllDay()); } - /** @test */ + #[Test] public function endIsEndOfDayWhenNoEndTime() { Carbon::setTestNow(now()); @@ -71,7 +72,7 @@ public function endIsEndOfDayWhenNoEndTime() $this->assertEquals(now()->endOfDay()->setMicrosecond(0), $nextOccurrences[0]->end); } - /** @test */ + #[Test] public function emptyOccurrencesIfNowAfterEndDate() { $recurringEntry = Entry::make() @@ -90,7 +91,7 @@ public function emptyOccurrencesIfNowAfterEndDate() $this->assertEmpty($nextOccurrences); } - /** @test */ + #[Test] public function canGenerateNextDayIfNowIsBefore() { $startDate = CarbonImmutable::now()->setTimeFromTimeString('11:00'); @@ -114,7 +115,7 @@ public function canGenerateNextDayIfNowIsBefore() $this->assertEquals($startDate, $nextOccurrences->first()->start); } - /** @test */ + #[Test] public function canGenerateNextOccurrenceIfNowIsDuring() { $startDate = CarbonImmutable::now()->setTimeFromTimeString('11:00'); @@ -143,7 +144,7 @@ public function canGenerateNextOccurrenceIfNowIsDuring() $this->assertEquals($startDate, $noEndTimeEvent->nextOccurrences()[0]->start); } - /** @test */ + #[Test] public function canSupplementNoEndTime() { $startDate = CarbonImmutable::now()->setTimeFromTimeString('11:00');