title = 'Ancien Titre'; $slide->text = '
Ancien texte
'; $slide->saveOrFail(); // Strict double: no picture in this input, so storeFileOntoDisk must never be touched. $storage = \Mockery::mock(StorageService::class); $storage->shouldNotReceive('storeFileOntoDisk'); $action = new UpdateSlide( $storage, new PublicS3Disk('https://cdn.test'), new ImageOptimizerService(new TemporaryFileFactory(), new NullLogger()), ); $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
'); $this->assertDatabaseHas('slides', [ 'id' => $slide->id, 'title' => 'Titre Mis à Jour', ]); }); it('updates an existing slide with a new uploaded picture', function (): void { /** @var \Tests\TestCase $this */ // GIVEN $slide = new Slide(); $slide->title = 'Ancien Titre'; $slide->text = 'Ancien texte
'; $slide->saveOrFail(); $storage = \Mockery::mock(StorageService::class); $storage->shouldReceive('storeFileOntoDisk')->once()->andReturn(new StorageFilePath('slides/new-slide.jpg')); $action = new UpdateSlide( $storage, new PublicS3Disk('https://cdn.test'), new ImageOptimizerService(new TemporaryFileFactory(), new NullLogger()), ); $input = new UpdateSlideInput( slide: $slide, title: 'Titre Avec Image', text: 'Texte avec image
', picture: UploadedFile::fake()->image('new-slide.jpg', 600, 400), pictureAlt: 'Nouvel alt', pictureTitle: 'Nouveau titre', ); // WHEN $updatedSlide = $action($input); // THEN expect($updatedSlide->id)->toBe($slide->id) ->and($updatedSlide->title)->toBe('Titre Avec Image') ->and($updatedSlide->picture_alt)->toBe('Nouvel alt') ->and($updatedSlide->picture_title)->toBe('Nouveau titre') ->and($updatedSlide->picture)->toBeInstanceOf(StorageFilePath::class) ->and($updatedSlide->picture?->value)->toBe('slides/new-slide.jpg'); $fresh = Slide::query()->find($slide->id); expect($fresh)->not->toBeNull() ->and($fresh?->title)->toBe('Titre Avec Image') ->and($fresh?->picture?->value)->toBe('slides/new-slide.jpg'); $this->assertDatabaseHas('slides', [ 'id' => $slide->id, 'title' => 'Titre Avec Image', 'picture_alt' => 'Nouvel alt', 'picture_title' => 'Nouveau titre', ]); }); it('throws when an invalid input is passed', function (): void { // GIVEN $storage = \Mockery::mock(StorageService::class); $storage->shouldNotReceive('storeFileOntoDisk'); $action = new UpdateSlide( $storage, new PublicS3Disk('https://cdn.test'), new ImageOptimizerService(new TemporaryFileFactory(), new NullLogger()), ); $invalidInput = new class () implements ActionInput { }; // WHEN expect( /** @phpstan-ignore argument.type */ fn () => $action($invalidInput) ) // THEN ->toThrow(\InvalidArgumentException::class); }); });