ldc-cocotte/tests/Integration/WithApp/App/Actions/Ranges/CreateRangeTest.php
Jérémy Munsch d0efb0f527
refactor: update namespaces for actions and queries
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.
2026-11-10 15:13:26 +01:00

61 lines
2 KiB
PHP

<?php
declare(strict_types=1);
use App\Contracts\ActionInput;
use App\Cqs\Actions\Ranges\CreateRange;
use App\Cqs\Actions\Ranges\CreateRangeInput;
use App\Models\Range;
use Domain\Models\ValueObjects\PictureMetadata;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
uses(RefreshDatabase::class);
describe('CreateRange action', function () {
test('it creates and persists a range in database', function () {
/** @var \Tests\TestCase $this */
// GIVEN
Storage::fake('public');
$action = new CreateRange();
$input = new CreateRangeInput(
name: 'Gamme Décoration',
description: '<p>Une superbe gamme</p>',
picture: UploadedFile::fake()->image('range.jpg', 500, 500),
pictureMetadata: new PictureMetadata(alt: 'Image alt range', title: 'Image title range'),
status: true,
);
// WHEN
$range = $action($input);
// THEN
expect($range)->toBeInstanceOf(Range::class)
->and($range->name)->toBe('Gamme Décoration')
->and($range->slug)->toBe('gamme-decoration')
->and($range->description)->toBe('<p>Une superbe gamme</p>')
->and($range->picture_alt)->toBe('Image alt range')
->and($range->picture_title)->toBe('Image title range')
->and($range->status)->toBeTrue()
->and($range->exists)->toBeTrue();
$this->assertDatabaseHas('ranges', [
'id' => $range->id,
'name' => 'Gamme Décoration',
'slug' => 'gamme-decoration',
]);
});
test('it throws when an invalid input is passed', function () {
// GIVEN
$action = new CreateRange();
$invalidInput = new class () implements ActionInput
{
};
// WHEN & THEN
expect(fn () => $action($invalidInput))
->toThrow(\InvalidArgumentException::class);
});
});