diff --git a/app/Actions/Slides/CreateSlide.php b/app/Actions/Slides/CreateSlide.php
new file mode 100644
index 00000000..3c0f1585
--- /dev/null
+++ b/app/Actions/Slides/CreateSlide.php
@@ -0,0 +1,44 @@
+
+ */
+final class CreateSlide implements Action
+{
+ /**
+ * @param \App\Actions\Slides\CreateSlideInput $input
+ */
+ #[\Override]
+ public function __invoke(ActionInput $input): Slide
+ {
+ Assert::isInstanceOf($input, CreateSlideInput::class);
+
+ $slide = new Slide();
+ $slide->title = $input->title;
+ $slide->text = $input->text;
+ if ($input->picture !== null) {
+ $slide->picture = $input->picture;
+ }
+ $slide->picture_alt = $input->pictureAlt;
+ $slide->picture_title = $input->pictureTitle;
+ $slide->link = $input->link;
+ $slide->link_label = $input->linkLabel;
+ $slide->link_new_tab = $input->linkNewTab;
+ $slide->connected = $input->connected;
+ $slide->date_start = $input->period->start !== null ? Carbon::instance($input->period->start) : null;
+ $slide->date_end = $input->period->end !== null ? Carbon::instance($input->period->end) : null;
+ $slide->saveOrFail();
+
+ return $slide;
+ }
+}
diff --git a/app/Actions/Slides/CreateSlideInput.php b/app/Actions/Slides/CreateSlideInput.php
new file mode 100644
index 00000000..a0232444
--- /dev/null
+++ b/app/Actions/Slides/CreateSlideInput.php
@@ -0,0 +1,50 @@
+title));
+ Assert::maxLength($this->title, 75);
+
+ Assert::true(
+ $this->picture !== null || ($this->text !== null && trim($this->text) !== ''),
+ 'A slide must have either a picture or text.'
+ );
+
+ if ($this->pictureAlt !== null) {
+ Assert::maxLength($this->pictureAlt, 75);
+ }
+
+ if ($this->pictureTitle !== null) {
+ Assert::maxLength($this->pictureTitle, 75);
+ }
+
+ if ($this->link !== null) {
+ Assert::maxLength($this->link, 255);
+ }
+
+ if ($this->linkLabel !== null) {
+ Assert::maxLength($this->linkLabel, 255);
+ }
+ }
+}
diff --git a/app/Actions/Slides/DeleteSlide.php b/app/Actions/Slides/DeleteSlide.php
new file mode 100644
index 00000000..c18847bf
--- /dev/null
+++ b/app/Actions/Slides/DeleteSlide.php
@@ -0,0 +1,26 @@
+
+ */
+final class DeleteSlide implements Action
+{
+ /**
+ * @param \App\Actions\Slides\DeleteSlideInput $input
+ */
+ #[\Override]
+ public function __invoke(ActionInput $input): bool
+ {
+ Assert::isInstanceOf($input, DeleteSlideInput::class);
+
+ return (bool) $input->slide->deleteOrFail();
+ }
+}
diff --git a/app/Actions/Slides/DeleteSlideInput.php b/app/Actions/Slides/DeleteSlideInput.php
new file mode 100644
index 00000000..fc57ab1d
--- /dev/null
+++ b/app/Actions/Slides/DeleteSlideInput.php
@@ -0,0 +1,16 @@
+
+ */
+final class UpdateSlide implements Action
+{
+ /**
+ * @param \App\Actions\Slides\UpdateSlideInput $input
+ */
+ #[\Override]
+ public function __invoke(ActionInput $input): Slide
+ {
+ Assert::isInstanceOf($input, UpdateSlideInput::class);
+
+ $slide = $input->slide;
+ $slide->title = $input->title;
+ $slide->text = $input->text;
+ if ($input->picture !== null) {
+ $slide->picture = $input->picture;
+ }
+ $slide->picture_alt = $input->pictureAlt;
+ $slide->picture_title = $input->pictureTitle;
+ $slide->link = $input->link;
+ $slide->link_label = $input->linkLabel;
+ $slide->link_new_tab = $input->linkNewTab;
+ $slide->connected = $input->connected;
+ $slide->date_start = $input->period->start !== null ? Carbon::instance($input->period->start) : null;
+ $slide->date_end = $input->period->end !== null ? Carbon::instance($input->period->end) : null;
+ $slide->saveOrFail();
+
+ return $slide;
+ }
+}
diff --git a/app/Actions/Slides/UpdateSlideInput.php b/app/Actions/Slides/UpdateSlideInput.php
new file mode 100644
index 00000000..5cf8845d
--- /dev/null
+++ b/app/Actions/Slides/UpdateSlideInput.php
@@ -0,0 +1,52 @@
+title));
+ Assert::maxLength($this->title, 75);
+
+ Assert::true(
+ $this->picture !== null || ! empty($this->slide->picture) || ($this->text !== null && trim($this->text) !== ''),
+ 'A slide must have either a picture or text.'
+ );
+
+ if ($this->pictureAlt !== null) {
+ Assert::maxLength($this->pictureAlt, 75);
+ }
+
+ if ($this->pictureTitle !== null) {
+ Assert::maxLength($this->pictureTitle, 75);
+ }
+
+ if ($this->link !== null) {
+ Assert::maxLength($this->link, 255);
+ }
+
+ if ($this->linkLabel !== null) {
+ Assert::maxLength($this->linkLabel, 255);
+ }
+ }
+}
diff --git a/app/Dto/SlideDto.php b/app/Dto/SlideDto.php
new file mode 100644
index 00000000..f039e27a
--- /dev/null
+++ b/app/Dto/SlideDto.php
@@ -0,0 +1,102 @@
+
+ */
+final readonly class SlideDto implements Arrayable, UrlRoutable
+{
+ public function __construct(
+ public int $id,
+ public string $title,
+ public ?string $text,
+ public ?string $picture,
+ public ?string $picture_alt,
+ public ?string $picture_title,
+ public ?string $link,
+ public ?string $link_label,
+ public bool $link_new_tab,
+ public bool $connected,
+ public ?Carbon $date_start,
+ public ?Carbon $date_end,
+ public int $order,
+ public bool $status,
+ ) {
+ }
+
+ public static function fromModel(Slide $slide): self
+ {
+ return new self(
+ id: $slide->id,
+ title: $slide->title,
+ text: $slide->text,
+ picture: is_string($slide->picture) ? $slide->picture : null,
+ picture_alt: $slide->picture_alt,
+ picture_title: $slide->picture_title,
+ link: $slide->link,
+ link_label: $slide->link_label,
+ link_new_tab: $slide->link_new_tab,
+ connected: $slide->connected,
+ date_start: $slide->date_start,
+ date_end: $slide->date_end,
+ order: $slide->order,
+ status: $slide->status,
+ );
+ }
+
+ #[\Override]
+ public function getRouteKey(): mixed
+ {
+ return $this->id;
+ }
+
+ #[\Override]
+ public function getRouteKeyName(): string
+ {
+ return 'id';
+ }
+
+ #[\Override]
+ public function resolveRouteBinding($value, $field = null): mixed
+ {
+ return null;
+ }
+
+ #[\Override]
+ public function resolveChildRouteBinding($childType, $value, $field): mixed
+ {
+ return null;
+ }
+
+ /**
+ * @return array
Contenu promo
') + ->and($slide->link)->toBe('https://example.com/promo') + ->and($slide->link_label)->toBe('En profiter') + ->and($slide->link_new_tab)->toBeTrue() + ->and($slide->connected)->toBeFalse(); + + $fresh = Slide::query()->find($slide->id); + expect($fresh)->not->toBeNull() + ->and($fresh?->title)->toBe('Nouvelle Bannière'); + }); + + it('throws when an invalid input is passed', function (): void { + // GIVEN + $action = new CreateSlide(); + $invalidInput = new class () implements ActionInput + { + }; + + // WHEN + expect( + /** @phpstan-ignore argument.type */ + fn () => $action($invalidInput) + ) + // THEN + ->toThrow(\InvalidArgumentException::class); + }); +}); diff --git a/tests/Integration/WithApp/App/Actions/Slides/DeleteSlideTest.php b/tests/Integration/WithApp/App/Actions/Slides/DeleteSlideTest.php new file mode 100644 index 00000000..f62eee68 --- /dev/null +++ b/tests/Integration/WithApp/App/Actions/Slides/DeleteSlideTest.php @@ -0,0 +1,44 @@ +title = 'Slide à supprimer'; + $slide->text = 'Contenu
'; + $slide->saveOrFail(); + + $action = new DeleteSlide(); + $input = new DeleteSlideInput(slide: $slide); + + // WHEN + $result = $action($input); + + // THEN + expect($result)->toBeTrue(); + expect(Slide::query()->find($slide->id))->toBeNull(); + }); + + it('throws when an invalid input is passed', function (): void { + // GIVEN + $action = new DeleteSlide(); + $invalidInput = new class () implements ActionInput + { + }; + + // WHEN + expect( + /** @phpstan-ignore argument.type */ + fn () => $action($invalidInput) + ) + // THEN + ->toThrow(\InvalidArgumentException::class); + }); +}); diff --git a/tests/Integration/WithApp/App/Actions/Slides/UpdateSlideTest.php b/tests/Integration/WithApp/App/Actions/Slides/UpdateSlideTest.php new file mode 100644 index 00000000..254f666c --- /dev/null +++ b/tests/Integration/WithApp/App/Actions/Slides/UpdateSlideTest.php @@ -0,0 +1,68 @@ +title = 'Ancien Titre'; + $slide->text = 'Ancien texte
'; + $slide->saveOrFail(); + + $action = new UpdateSlide(); + $start = new \DateTimeImmutable('2026-07-01 10:00:00'); + $end = new \DateTimeImmutable('2026-07-31 20:00:00'); + $period = new DatePeriod($start, $end); + + $input = new UpdateSlideInput( + slide: $slide, + title: 'Titre Mis à Jour', + text: 'Texte mis à jour
', + link: 'https://example.com/updated', + linkLabel: 'Lien mis à jour', + linkNewTab: true, + connected: true, + period: $period, + ); + + // WHEN + $updatedSlide = $action($input); + + // THEN + expect($updatedSlide->id)->toBe($slide->id) + ->and($updatedSlide->title)->toBe('Titre Mis à Jour') + ->and($updatedSlide->text)->toBe('Texte mis à jour
') + ->and($updatedSlide->link)->toBe('https://example.com/updated') + ->and($updatedSlide->link_label)->toBe('Lien mis à jour') + ->and($updatedSlide->link_new_tab)->toBeTrue() + ->and($updatedSlide->connected)->toBeTrue(); + + $fresh = Slide::query()->find($slide->id); + expect($fresh)->not->toBeNull() + ->and($fresh?->title)->toBe('Titre Mis à Jour') + ->and($fresh?->text)->toBe('Texte mis à jour
'); + }); + + it('throws when an invalid input is passed', function (): void { + // GIVEN + $action = new UpdateSlide(); + $invalidInput = new class () implements ActionInput + { + }; + + // WHEN + expect( + /** @phpstan-ignore argument.type */ + fn () => $action($invalidInput) + ) + // THEN + ->toThrow(\InvalidArgumentException::class); + }); +}); diff --git a/tests/Integration/WithApp/App/Dto/SlideDtoTest.php b/tests/Integration/WithApp/App/Dto/SlideDtoTest.php new file mode 100644 index 00000000..1b0ca647 --- /dev/null +++ b/tests/Integration/WithApp/App/Dto/SlideDtoTest.php @@ -0,0 +1,50 @@ +id = 42; + $slide->title = 'Bannière Été'; + $slide->text = 'Découvrez notre nouvelle collection
'; + $slide->picture = 'storage/modelfiles/slides/26/06/01/ab/summer.jpg'; + $slide->picture_alt = 'Collection Été'; + $slide->picture_title = 'Bannière promotionnelle été'; + $slide->link = 'https://example.com/ete'; + $slide->link_label = 'Voir les offres'; + $slide->link_new_tab = true; + $slide->connected = false; + $slide->date_start = $dateStart; + $slide->date_end = $dateEnd; + $slide->order = 3; + $slide->status = true; + + // WHEN + $dto = SlideDto::fromModel($slide); + + // THEN + expect($dto->id)->toBe(42) + ->and($dto->title)->toBe('Bannière Été') + ->and($dto->text)->toBe('Découvrez notre nouvelle collection
') + ->and($dto->picture)->toBe('storage/modelfiles/slides/26/06/01/ab/summer.jpg') + ->and($dto->picture_alt)->toBe('Collection Été') + ->and($dto->picture_title)->toBe('Bannière promotionnelle été') + ->and($dto->link)->toBe('https://example.com/ete') + ->and($dto->link_label)->toBe('Voir les offres') + ->and($dto->link_new_tab)->toBeTrue() + ->and($dto->connected)->toBeFalse() + ->and($dto->date_start)->toEqual($dateStart) + ->and($dto->date_end)->toEqual($dateEnd) + ->and($dto->order)->toBe(3) + ->and($dto->status)->toBeTrue(); + }); +}); diff --git a/tests/Integration/WithApp/App/Queries/Slides/GetPaginatedSlidesQueryTest.php b/tests/Integration/WithApp/App/Queries/Slides/GetPaginatedSlidesQueryTest.php new file mode 100644 index 00000000..87a327d4 --- /dev/null +++ b/tests/Integration/WithApp/App/Queries/Slides/GetPaginatedSlidesQueryTest.php @@ -0,0 +1,36 @@ +title = 'Premier Slide'; + $slide1->text = 'Texte premier slide'; + $slide1->order = 1; + $slide1->save(); + + $slide2 = new Slide(); + $slide2->title = 'Deuxième Slide'; + $slide2->text = 'Texte deuxième slide'; + $slide2->order = 2; + $slide2->save(); + + /** @var GetPaginatedSlidesQuery $query */ + $query = app(GetPaginatedSlidesQuery::class); + + // WHEN + $paginator = $query->execute(); + + // THEN + expect($paginator->total())->toBe(2) + ->and($paginator->items())->toHaveCount(2) + ->and($paginator->items()[0])->toBeInstanceOf(SlideDto::class) + ->and($paginator->items()[1])->toBeInstanceOf(SlideDto::class); + }); +}); diff --git a/tests/Unit/App/Actions/Slides/CreateSlideInputTest.php b/tests/Unit/App/Actions/Slides/CreateSlideInputTest.php new file mode 100644 index 00000000..78393926 --- /dev/null +++ b/tests/Unit/App/Actions/Slides/CreateSlideInputTest.php @@ -0,0 +1,98 @@ +Contenu du slide'; + $period = new DatePeriod(); + + // WHEN + $input = new CreateSlideInput( + title: $title, + text: $text, + period: $period, + ); + + // THEN + expect($input->title)->toBe($title) + ->and($input->text)->toBe($text) + ->and($input->picture)->toBeNull() + ->and($input->period)->toBe($period); + }); + + it('creates a valid CreateSlideInput instance with picture', function (): void { + // GIVEN + $title = 'Nouveau Slide Photo'; + $picture = 'storage/modelfiles/slides/picture.jpg'; + + // WHEN + $input = new CreateSlideInput( + title: $title, + picture: $picture, + pictureAlt: 'Description alternative', + pictureTitle: 'Titre image', + ); + + // THEN + expect($input->title)->toBe($title) + ->and($input->picture)->toBe($picture) + ->and($input->pictureAlt)->toBe('Description alternative') + ->and($input->pictureTitle)->toBe('Titre image'); + }); + + it('throws when title is empty', function (): void { + // GIVEN + $emptyTitle = ' '; + + // WHEN + expect(fn () => new CreateSlideInput(title: $emptyTitle, text: 'Texte')) + // THEN + ->toThrow(\InvalidArgumentException::class); + }); + + it('throws when title exceeds 75 characters', function (): void { + // GIVEN + $tooLongTitle = str_repeat('a', 76); + + // WHEN + expect(fn () => new CreateSlideInput(title: $tooLongTitle, text: 'Texte')) + // THEN + ->toThrow(\InvalidArgumentException::class); + }); + + it('throws when neither picture nor text is provided', function (): void { + // GIVEN + $title = 'Slide sans contenu'; + + // WHEN + expect(fn () => new CreateSlideInput(title: $title)) + // THEN + ->toThrow(\InvalidArgumentException::class, 'A slide must have either a picture or text.'); + }); + + it('throws when picture_alt exceeds 75 characters', function (): void { + // GIVEN + $tooLongAlt = str_repeat('a', 76); + + // WHEN + expect(fn () => new CreateSlideInput(title: 'Slide', picture: 'pic.jpg', pictureAlt: $tooLongAlt)) + // THEN + ->toThrow(\InvalidArgumentException::class); + }); + + it('throws when link exceeds 255 characters', function (): void { + // GIVEN + $tooLongLink = 'https://example.com/' . str_repeat('a', 256); + + // WHEN + expect(fn () => new CreateSlideInput(title: 'Slide', text: 'Texte', link: $tooLongLink)) + // THEN + ->toThrow(\InvalidArgumentException::class); + }); +}); diff --git a/tests/Unit/App/Actions/Slides/DeleteSlideInputTest.php b/tests/Unit/App/Actions/Slides/DeleteSlideInputTest.php new file mode 100644 index 00000000..b4f26324 --- /dev/null +++ b/tests/Unit/App/Actions/Slides/DeleteSlideInputTest.php @@ -0,0 +1,19 @@ +slide)->toBe($slide); + }); +}); diff --git a/tests/Unit/App/Actions/Slides/UpdateSlideInputTest.php b/tests/Unit/App/Actions/Slides/UpdateSlideInputTest.php new file mode 100644 index 00000000..dd5d605d --- /dev/null +++ b/tests/Unit/App/Actions/Slides/UpdateSlideInputTest.php @@ -0,0 +1,65 @@ +picture = 'storage/modelfiles/slides/existing.jpg'; + $title = 'Slide Modifié'; + + // WHEN + $input = new UpdateSlideInput( + slide: $slide, + title: $title, + ); + + // THEN + expect($input->slide)->toBe($slide) + ->and($input->title)->toBe($title) + ->and($input->picture)->toBeNull(); + }); + + it('creates a valid UpdateSlideInput instance with new text', function (): void { + // GIVEN + $slide = new Slide(); + $title = 'Slide Modifié Texte'; + $text = 'Nouveau texte
'; + + // WHEN + $input = new UpdateSlideInput( + slide: $slide, + title: $title, + text: $text, + ); + + // THEN + expect($input->slide)->toBe($slide) + ->and($input->title)->toBe($title) + ->and($input->text)->toBe($text); + }); + + it('throws when title is empty', function (): void { + // GIVEN + $slide = new Slide(); + + // WHEN + expect(fn () => new UpdateSlideInput(slide: $slide, title: ' ', text: 'Texte')) + // THEN + ->toThrow(\InvalidArgumentException::class); + }); + + it('throws when neither new nor existing picture nor text exists', function (): void { + // GIVEN + $slide = new Slide(); + + // WHEN + expect(fn () => new UpdateSlideInput(slide: $slide, title: 'Slide')) + // THEN + ->toThrow(\InvalidArgumentException::class, 'A slide must have either a picture or text.'); + }); +}); diff --git a/tests/Unit/App/Dto/SlideDtoTest.php b/tests/Unit/App/Dto/SlideDtoTest.php new file mode 100644 index 00000000..65aea3de --- /dev/null +++ b/tests/Unit/App/Dto/SlideDtoTest.php @@ -0,0 +1,68 @@ +Découvrez notre nouvelle collection', + picture: 'storage/modelfiles/slides/26/06/01/ab/summer.jpg', + picture_alt: 'Collection Été', + picture_title: 'Bannière promotionnelle été', + link: 'https://example.com/ete', + link_label: 'Voir les offres', + link_new_tab: true, + connected: false, + date_start: $dateStart, + date_end: $dateEnd, + order: 3, + status: true, + ); + + // THEN + expect($dto->id)->toBe(42) + ->and($dto->title)->toBe('Bannière Été') + ->and($dto->text)->toBe('Découvrez notre nouvelle collection
') + ->and($dto->picture)->toBe('storage/modelfiles/slides/26/06/01/ab/summer.jpg') + ->and($dto->picture_alt)->toBe('Collection Été') + ->and($dto->picture_title)->toBe('Bannière promotionnelle été') + ->and($dto->link)->toBe('https://example.com/ete') + ->and($dto->link_label)->toBe('Voir les offres') + ->and($dto->link_new_tab)->toBeTrue() + ->and($dto->connected)->toBeFalse() + ->and($dto->date_start)->toEqual($dateStart) + ->and($dto->date_end)->toEqual($dateEnd) + ->and($dto->order)->toBe(3) + ->and($dto->status)->toBeTrue() + ->and($dto->getRouteKey())->toBe(42) + ->and($dto->getRouteKeyName())->toBe('id') + ->and($dto->resolveRouteBinding(42))->toBeNull() + ->and($dto->resolveChildRouteBinding('child', 'val', 'field'))->toBeNull() + ->and($dto->toArray())->toBe([ + 'id' => 42, + 'title' => 'Bannière Été', + 'text' => 'Découvrez notre nouvelle collection
', + 'picture' => 'storage/modelfiles/slides/26/06/01/ab/summer.jpg', + 'picture_alt' => 'Collection Été', + 'picture_title' => 'Bannière promotionnelle été', + 'link' => 'https://example.com/ete', + 'link_label' => 'Voir les offres', + 'link_new_tab' => true, + 'connected' => false, + 'date_start' => $dateStart, + 'date_end' => $dateEnd, + 'order' => 3, + 'status' => true, + ]); + }); +}); diff --git a/tests/Unit/App/Policies/Backend/SlidePolicyTest.php b/tests/Unit/App/Policies/Backend/SlidePolicyTest.php index 369336dc..0c6802c1 100644 --- a/tests/Unit/App/Policies/Backend/SlidePolicyTest.php +++ b/tests/Unit/App/Policies/Backend/SlidePolicyTest.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use App\Dto\SlideDto; use App\Models\Customer; use App\Models\Slide; use App\Models\User; @@ -164,4 +165,32 @@ describe('SlidePolicy', function () { // THEN expect($result)->toBeTrue(); }); + + test('view, update, delete return true for admin user with SlideDto', function () { + // GIVEN + $user = new User(); + $user->role = UserRole::Admin; + $policy = new SlidePolicy(); + $dto = new SlideDto( + id: 1, + title: 'Titre', + text: null, + picture: 'pic.jpg', + picture_alt: null, + picture_title: null, + link: null, + link_label: null, + link_new_tab: false, + connected: false, + date_start: null, + date_end: null, + order: 1, + status: true, + ); + + // WHEN & THEN + expect($policy->view($user, $dto))->toBeTrue() + ->and($policy->update($user, $dto))->toBeTrue() + ->and($policy->delete($user, $dto))->toBeTrue(); + }); }); diff --git a/tests/Unit/Domain/Models/ValueObjects/DatePeriodTest.php b/tests/Unit/Domain/Models/ValueObjects/DatePeriodTest.php new file mode 100644 index 00000000..29518f99 --- /dev/null +++ b/tests/Unit/Domain/Models/ValueObjects/DatePeriodTest.php @@ -0,0 +1,89 @@ +isActiveAt(); + + // THEN + expect($period->start)->toBeNull() + ->and($period->end)->toBeNull() + ->and($isActive)->toBeTrue(); + }); + + it('creates a period with start and end dates', function (): void { + // GIVEN + $start = new \DateTimeImmutable('2026-01-01 00:00:00'); + $end = new \DateTimeImmutable('2026-12-31 23:59:59'); + + // WHEN + $period = new DatePeriod($start, $end); + + // THEN + expect($period->start)->toEqual($start) + ->and($period->end)->toEqual($end); + }); + + it('throws when start date is after end date', function (): void { + // GIVEN + $start = new \DateTimeImmutable('2026-12-31 23:59:59'); + $end = new \DateTimeImmutable('2026-01-01 00:00:00'); + + // WHEN + expect(fn () => new DatePeriod($start, $end)) + // THEN + ->toThrow(\InvalidArgumentException::class, 'The start date must be before or equal to the end date.'); + }); + + it('evaluates isActiveAt correctly', function (): void { + // GIVEN + $start = new \DateTimeImmutable('2026-06-01 00:00:00'); + $end = new \DateTimeImmutable('2026-06-30 23:59:59'); + $period = new DatePeriod($start, $end); + + // WHEN + $before = $period->isActiveAt(new \DateTimeImmutable('2026-05-31 23:59:59')); + $during = $period->isActiveAt(new \DateTimeImmutable('2026-06-15 12:00:00')); + $after = $period->isActiveAt(new \DateTimeImmutable('2026-07-01 00:00:00')); + + // THEN + expect($before)->toBeFalse() + ->and($during)->toBeTrue() + ->and($after)->toBeFalse(); + }); + + it('evaluates isActiveAt with only start date', function (): void { + // GIVEN + $start = new \DateTimeImmutable('2026-06-01 00:00:00'); + $period = new DatePeriod(start: $start); + + // WHEN + $before = $period->isActiveAt(new \DateTimeImmutable('2026-05-31 23:59:59')); + $during = $period->isActiveAt(new \DateTimeImmutable('2026-06-15 12:00:00')); + + // THEN + expect($before)->toBeFalse() + ->and($during)->toBeTrue(); + }); + + it('evaluates isActiveAt with only end date', function (): void { + // GIVEN + $end = new \DateTimeImmutable('2026-06-30 23:59:59'); + $period = new DatePeriod(end: $end); + + // WHEN + $during = $period->isActiveAt(new \DateTimeImmutable('2026-06-15 12:00:00')); + $after = $period->isActiveAt(new \DateTimeImmutable('2026-07-01 00:00:00')); + + // THEN + expect($during)->toBeTrue() + ->and($after)->toBeFalse(); + }); +});