title: Download file functional test on Symfony2
body: <p>With symfony2, how to test (functional test) that the file has been downloaded well on the client's side? I have tried the following code but something is wrong.</p>
  
  <p>My controller:</p>
  
  <pre class="lang-php prettyprint-override"><code>public function downloadAction($picture_id) 
  {
  
      $fichier= $this-&gt;uploadDir.$picture_id; 
      if (($fichier != "") &amp;&amp; (file_exists($fichier))) {
          $content = file_get_contents($fichier);
  
          $response = new Response();
          $response-&gt;headers-&gt;set('Content-Type', 'application/octet-stream');
          $response-&gt;headers-&gt;set('Content-Disposition', 'attachment;filename="'.$picture_id);
  
          $response-&gt;setContent($content);
  
          return $response;
      }
  }
  </code></pre>
  
  <p>Test code:</p>
  
  <pre class="lang-php prettyprint-override"><code>public function testupload()
  {
  
          $ch = curl_init();
                  curl_setopt($ch, CURLOPT_HEADER, 0);
                  //curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: image/jpeg"));
                  curl_setopt($ch, CURLOPT_VERBOSE, 1);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                  curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
                  curl_setopt($ch, CURLOPT_URL, "Path_to _myFile/file.png");
                  //curl_setopt($ch, CURLOPT_POST, true);        
                  $response = curl_exec($ch);
  
                  //$json_response = json_decode($response);
  
                  print "resp -&gt; ".$response-&gt;headers;
  
  
  }
  </code></pre>
  
  <p>Finally, the response by phpunit:</p>
  
  <blockquote>
    <p>1) Application\MediaBundle\Tests\Controller\PictureControllerCopyTest::testupload<br>
    Trying to get property of non-object</p>
    
    <p>/var/www/symfony/ws1/src/Application/MediaBundle/Tests/Controller/PictureControllerCopyTest.php:28</p>
    
    <p>FAILURES!
    Tests: 1, Assertions: 0, Errors: 1.</p>
  </blockquote>