title: How to do Unit Testing + code-coverage with file upload in Laravel 5.2
body: <p>I want to do some unit testing with file upload on Laravel 5.2.</p>
  
  <p>Here is how I do it refer to this <a href="https://stackoverflow.com/a/33396075/1040934">answer</a>:</p>
  
  <pre><code>/** app/Http/routes.php **/
  Route::post('upload', function() {
      $fileExists = false;
  
      if ($_FILES['images']) {
          $fileExists = true;
      }
  
      return ['result' =&gt; $fileExists];
  });
  
  /** tests/ExampleTest.php **/
  public function testUploadFile()
  {
      $file = new \Symfony\Component\HttpFoundation\File\UploadedFile(
          base_path() . '/tests/files/profile.png', 'profile.png');
  
          $response = $this-&gt;call('POST', 'upload', 
              [
                 'firstname' =&gt; 'firstname', 
                 'lastname'  =&gt; 'lastname', 
                 'promotion' =&gt; '2016', 
                 'isCoop' =&gt; 1
              ], 
              [
                 'images' =&gt; [$file]
              ]
          );
  }
  </code></pre>
  
  <p>The result of phpunit is:
  <a href="https://i.stack.imgur.com/eDjWf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eDjWf.png" alt="phpunit result"></a></p>
  
  <p>But, when I check the code coverage result, the line inside the if statement on routes.php file is not executed as shown below.</p>
  
  <p><a href="https://i.stack.imgur.com/awEVm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/awEVm.png" alt="Code coverage result"></a></p>
  
  <p>It seems the uploaded file is not inserted into <code>$_FILES</code> variable, so it detected as empty. </p>
  
  <p>Any idea how to fix it..? Thanks.</p>
  
  <p><strong><em>Notes: I used Larave for create an API Service, so I did not used form to upload the file</em></strong></p>