ldc-cocotte/tests/Integration/WithApp/App/Actions/Slides/CreateSlideTest.php

62 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
use App\Actions\Slides\CreateSlide;
use App\Actions\Slides\CreateSlideInput;
use App\Contracts\ActionInput;
use App\Models\Slide;
use Domain\Models\ValueObjects\DatePeriod;
describe('CreateSlide action', function (): void {
it('creates and persists a slide in database', function (): void {
// GIVEN
$action = new CreateSlide();
$start = new \DateTimeImmutable('2026-06-01 10:00:00');
$end = new \DateTimeImmutable('2026-06-30 20:00:00');
$period = new DatePeriod($start, $end);
$input = new CreateSlideInput(
title: 'Nouvelle Bannière',
text: '<p>Contenu promo</p>',
link: 'https://example.com/promo',
linkLabel: 'En profiter',
linkNewTab: true,
connected: false,
period: $period,
);
// WHEN
$slide = $action($input);
// THEN
expect($slide)->toBeInstanceOf(Slide::class)
->and($slide->id)->toBeGreaterThan(0)
->and($slide->title)->toBe('Nouvelle Bannière')
->and($slide->text)->toBe('<p>Contenu promo</p>')
->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);
});
});