ldc-cocotte/tests/Unit/App/Cqs/Actions/Slides/UpdateSlideInputTest.php

68 lines
2 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\App\Cqs\Actions\Slides;
use App\Cqs\Actions\Slides\UpdateSlideInput;
use App\Models\Slide;
use Uwil\Storage\Lib\ValueObjects\StorageFilePath;
describe('UpdateSlideInput', function (): void {
it('creates a valid UpdateSlideInput instance with existing slide picture', function (): void {
// GIVEN
$slide = new Slide();
$slide->picture = new StorageFilePath('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 = '<p>Nouveau texte</p>';
// 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.');
});
});