name = 'Gamme Initiale'; $range->description = 'Ancien contenu'; $range->picture_alt = 'Ancien alt'; $range->picture_title = 'Ancien title'; $range->status = true; $range->save(); // Storage is a strict double: no network/S3 side effect, and the upload is asserted. $storage = \Mockery::mock(StorageService::class); $storage->shouldReceive('storeFileOntoDisk')->once()->andReturn(new StorageFilePath('media/range.jpg')); $action = new UpdateRange( $storage, new PublicS3Disk('https://cdn.test'), new ImageOptimizerService(new TemporaryFileFactory(), new NullLogger()), ); $input = new UpdateRangeInput( range: $range, name: 'Gamme Renommée', description: 'Nouveau contenu', picture: UploadedFile::fake()->image('new-range.jpg', 500, 500), pictureMetadata: new PictureMetadata(alt: 'Nouveau alt', title: 'Nouveau title'), status: false, ); // WHEN $updatedRange = $action($input); // THEN expect($updatedRange->id)->toBe($range->id) ->and($updatedRange->name)->toBe('Gamme Renommée') ->and($updatedRange->slug)->toBe('gamme-renommee') ->and($updatedRange->description)->toBe('Nouveau contenu') ->and($updatedRange->picture_alt)->toBe('Nouveau alt') ->and($updatedRange->picture_title)->toBe('Nouveau title') ->and($updatedRange->status)->toBeFalse(); $this->assertDatabaseHas('ranges', [ 'id' => $range->id, 'name' => 'Gamme Renommée', 'status' => 0, ]); }); test('it throws when an invalid input is passed', function () { // GIVEN $storage = \Mockery::mock(StorageService::class); $storage->shouldNotReceive('storeFileOntoDisk'); $action = new UpdateRange( $storage, new PublicS3Disk('https://cdn.test'), new ImageOptimizerService(new TemporaryFileFactory(), new NullLogger()), ); $invalidInput = new class () implements ActionInput { }; // WHEN & THEN expect(fn () => $action($invalidInput)) ->toThrow(\InvalidArgumentException::class); }); });