title: CakePHP / phpunit : how to mock a file upload
body: <p>I'm trying to write tests for an endpoint that expects a post request with an attached CSV file. I know to simulate the post request like this:</p>
  
  <pre><code>$this-&gt;post('/foo/bar');
  </code></pre>
  
  <p>But I can't figure out how to add the file data. I tried manually setting the <code>$_FILES</code> array but it didn't work...</p>
  
  <pre><code>$_FILES = [
          'csvfile' =&gt; [
              'tmp_name' =&gt; '/home/path/to/tests/Fixture/csv/test.csv',
              'name' =&gt; 'test.csv',
              'type' =&gt; 'text/csv',
              'size' =&gt; 335057,
              'error' =&gt; 0,
          ],
  ];
  $this-&gt;post('/foo/bar');
  </code></pre>
  
  <p>What's the right way to do this?</p>