Refactored the codebase to change the namespaces of various actions and queries from `App\Actions` to `App\Cqs\Actions` and `App\Queries` to `App\Cqs\Queries`. This restructuring improves organization and clarity in the codebase.
44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Contracts\ActionInput;
|
|
use App\Cqs\Actions\Slides\DeleteSlide;
|
|
use App\Cqs\Actions\Slides\DeleteSlideInput;
|
|
use App\Models\Slide;
|
|
|
|
describe('DeleteSlide action', function (): void {
|
|
it('deletes an existing slide from database', function (): void {
|
|
// GIVEN
|
|
$slide = new Slide();
|
|
$slide->title = 'Slide à supprimer';
|
|
$slide->text = '<p>Contenu</p>';
|
|
$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);
|
|
});
|
|
});
|