shouldReceive('storeFileOntoDisk')->once()->andReturn(new StorageFilePath('media/range.jpg')); $action = new CreateRange( $storage, new PublicS3Disk('https://cdn.test'), new ImageOptimizerService(new TemporaryFileFactory(), new NullLogger()), ); $input = new CreateRangeInput( name: 'Gamme Décoration', description: '

Une superbe gamme

', 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('

Une superbe gamme

') ->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 $storage = \Mockery::mock(StorageService::class); $storage->shouldNotReceive('storeFileOntoDisk'); $action = new CreateRange( $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); }); });