0

As the title states, I want to be able to test the upload of a file using the available scalar while also providing additional parameters to the same mutation. The documentation provides a helper on how to test this Lighthouse docs simulating file uploads. But my mutation also needs some additional dynamic parameters for the test. But I can't figure out how to provide these additional parameters. An example of my current setup:

$response = $this->multipartGraphQL(['operations' => {
   "query": "mutation ($file: Upload!) {registerUser(email: $email, files: [$file]) {courseRegistrationFiles{id}}}",
   "variables": {"file": null}
}', 'map' => '{"0": ["variables.file"]}'], [
   '0' => UploadedFile::fake()->create('document.pdf', 100)
]);

A few additional notes the $email should be represented using a faked email address, this is done in the line above this snippet. At first, I imagined that I had to provide the email variable within the same brackets as where I define the uploadeFile::fake() but this lead to the error that stated that parameters within this portion of the method should be of the type UploaedFile. After that I've also tried simply adding them to the map/variables portions but this lead to the param being null.

MikeSli
  • 927
  • 2
  • 14
  • 32

1 Answers1

1

Now is a bit different, you need 3 array params like:

$operations = [
    'operationName' => 'upload',
    'query' => 'mutation upload ($file: Upload!) {
                    upload (file: $file)
                }',
    'variables' => [
        'file' => null,
    ],
];

$map = [
    '0' => ['variables.file'],
];

$file = [
    '0' => UploadedFile::fake()->create('test.pdf', 500),
];

$this->multipartGraphQL($operations, $map, $file);

Here are docs to help you out: https://lighthouse-php.com/5.2/testing/phpunit.html#simulating-file-uploads

francisco
  • 1,387
  • 2
  • 12
  • 23