shouldNotReceive('storeUploadedOntoDisk'); $action = new SubmitContactForm($storage, new PrivateS3Disk()); $orderRef = new OrderReference(Uuid::uuid7()); $input = new SubmitContactFormInput( lastName: 'Doe', firstName: 'John', email: 'john.doe@example.com', subject: 'Question', message: 'Bonjour, ceci est un message de test valide.', orderRef: $orderRef, ); // WHEN $result = $action($input); // THEN expect($result)->toBeInstanceOf(ContactFormData::class) ->and($result->lastName)->toBe('Doe') ->and($result->firstName)->toBe('John') ->and($result->email)->toBe('john.doe@example.com') ->and($result->subject)->toBe('Question') ->and($result->orderRef)->toBe($orderRef) ->and($result->file)->toBeNull(); }); it('uploads attachment to private S3 disk and attaches metadata', function (): void { // GIVEN $file = UploadedFile::fake()->create('document.pdf', 100, 'application/pdf'); $storage = \Mockery::mock(StorageService::class); $storage->shouldReceive('storeUploadedOntoDisk') ->once() ->with( $file, \Mockery::on(fn (DiskName $disk): bool => $disk->value === PrivateS3Disk::DISK_NAME), ) ->andReturn(new StorageFilePath('contact-attachments/document.pdf')); $action = new SubmitContactForm($storage, new PrivateS3Disk()); $input = new SubmitContactFormInput( lastName: 'Doe', firstName: 'John', email: 'john.doe@example.com', subject: 'Question', message: 'Bonjour, ceci est un message de test valide.', file: $file, ); // WHEN $result = $action($input); // THEN expect($result)->toBeInstanceOf(ContactFormData::class) ->and($result->file)->toBeInstanceOf(AttachedFile::class) ->and($result->file?->path)->toBe('contact-attachments/document.pdf') ->and($result->file?->originalName)->toBe('document.pdf') ->and($result->file?->mimeType)->toBe('application/pdf'); }); it('throws when an invalid input is passed', function (): void { // GIVEN $storage = \Mockery::mock(StorageService::class); $storage->shouldNotReceive('storeUploadedOntoDisk'); $action = new SubmitContactForm($storage, new PrivateS3Disk()); $invalidInput = new class () implements ActionInput { }; // WHEN expect( /** @phpstan-ignore argument.type */ fn () => $action($invalidInput) ) // THEN ->toThrow(\InvalidArgumentException::class); }); });