title: Api Platform: how to test file upload with ApiTestCase
body: <p>I have an endpoint, that allows file upload, everything works fine.
  Next thing is to cover the endpoint with proper functional test.
  And here's the problem - I can't pass the <code>file</code> to the client making the request.</p>
  <p>My test class extends <code>\ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase</code>.</p>
  <p><code>static::createClient()</code> method creates an instance of <code>ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Client</code> and these <code>Client</code> does not support file uploads.</p>
  <p>Beacuse of implementing the <code>Symfony\Contracts\HttpClient\HttpClientInterface</code> which defines <code>public function request(string $method, string $url, array $options = []): ResponseInterface;</code> there's no place for passing <code>files</code> argument.</p>
  <p>The allowed <code>options</code> in <code>Client</code> does not support <code>files</code> array.</p>
  <p>Internaly it looks like this:</p>
  <p><code>ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Client::request</code> passes to the internal <code>kernelBrowser</code> an empty array in place of <code>files</code> params (2nd array): <code>$this-&gt;kernelBrowser-&gt;request($method, $resolvedUrl, [], [], $server, $options['body'] ?? null)</code></p>
  <p>How do you test endpoints with file upload by extending <code>Base class for functional API tests</code> which is <code>ApiTestCase</code>?</p>
  <p>Here's some code, to help you visualize the problem:</p>
  <p>ApiResource definition in entity:</p>
  <pre><code>/**
   * @ApiResource(
   *     collectionOperations={
   *         &quot;file_upload&quot;={
   *             &quot;method&quot;=&quot;post&quot;,
   *             &quot;controller&quot;=FileUpload::class,
   *             &quot;path&quot;=&quot;/api/file-upload-endpoint&quot;,
   *             &quot;deserialize&quot;=false,
   *             &quot;openapi_context&quot;={
   *                 &quot;requestBody&quot;={
   *                     &quot;content&quot;={
   *                         &quot;multipart/form-data&quot;={
   *                             &quot;schema&quot;={
   *                                 &quot;type&quot;=&quot;object&quot;,
   *                                 &quot;properties&quot;={
   *                                     &quot;file&quot;={
   *                                         &quot;type&quot;=&quot;string&quot;,
   *                                         &quot;format&quot;=&quot;binary&quot;
   *                                     }
   *                                 }
   *                             }
   *                         }
   *                     }
   *                 }
   *             }
   *         },
   *     },
   * )
   */
  </code></pre>
  <p>Test class (don't mind the instance of <code>UploadedFile</code>, it's just there, to show you, that it cannot be passed anywhere):</p>
  <pre><code>&lt;?php
  
  declare(strict_types=1);
  
  namespace App\Tests\Api;
  
  use \ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
  use Symfony\Component\HttpFoundation\File\UploadedFile;
  
  final class FileUploadTest extends ApiTestCase
  {
      public function testFileUploadSuccessfully():void
      {
          $file = new UploadedFile(
              TESTS_PROJECT_DIR.'/tests/files/Small_sample_of_jet.jpg',
              'Small_sample_of_jet.jpg',
              'image/jpeg',
          );
  
          static::createClient()-&gt;request(
              'POST',
              '/api/file-upload-endpoint',
              [
                  'headers' =&gt; [
                      'Content-Type' =&gt; 'multipart/form-data',
                  ],
              ],
          );
  
          self::assertResponseIsSuccessful();
          self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
      }
  }
  </code></pre>
  <p>And here is what i'm looking for:</p>
  <pre><code>&lt;?php
  
  declare(strict_types=1);
  
  namespace App\Tests\Api;
  
  use \ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
  use Symfony\Component\HttpFoundation\File\UploadedFile;
  
  final class FileUploadTest extends ApiTestCase
  {
      public function testFileUploadSuccessfully():void
      {
          $file = new UploadedFile(
              TESTS_PROJECT_DIR.'/tests/files/Small_sample_of_jet.jpg',
              'Small_sample_of_jet.jpg',
              'image/jpeg',
          );
  
          static::createClient()-&gt;request(
              'POST',
              '/api/file-upload-endpoint',
              [
                  'headers' =&gt; [
                      'Content-Type' =&gt; 'multipart/form-data',
                  ],
              ],
              [
                  'file'=&gt;$file
              ]
          );
  
          self::assertResponseIsSuccessful();
          self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
      }
  }
  </code></pre>
  <p>When modyfing the <code>vendor</code> itself and passing the <code>files</code> to the <code>Client::request</code> and then to the <code>kernelBrowser</code> in place of 2nd empty array, everything works fine (I'm aware of breaking the contract, that's not the issue here ;)).</p>
  <p>I'm thinking if there's missing feature of uploading files in <code>ApiTestCase</code> or I just can't find the solution.</p>
  <p>Pls halp!</p>
  <p>Api Platform version: 2.5.6</p>
  <p>PS: I know i can use different client - <code>test.client</code></p>
  <pre><code>$client = static::$kernel-&gt;getContainer()-&gt;get('test.client');
  </code></pre>
  <p>which is an instance of <code>Symfony\Bundle\FrameworkBundle\KernelBrowser</code>, the same that is used internally by the Api Platform's <code>Client</code> and that <strong>supports</strong> <code>files</code> array, but that's not the point of my question. I'd like to know how to do file upload with <code>ApiTestCase</code>.</p>