0

symfony2 でダウンロード ファイルをテストする方法を教えてください。私のソースコードがあります:

Controller.php

public function downloadAction($picture_id) 
{

    $fichier= $this->uploadDir.$picture_id; 
    if (($fichier != "") && (file_exists($fichier))) {
        $content = file_get_contents($fichier);

        $response = new Response();
        $response->headers->set('Content-Type', 'application/octet-stream');
        $response->headers->set('Content-Disposition', 'attachment;filename="'.$picture_id);

        $response->setContent($content);

        return $response;
    }
    else return new Response(json_encode(array("response_code" => "ko")));  


}

ControllerTest.php

public function testdownload()
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    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/img.jpg");
    $response = curl_exec($ch);
}

問題は、ダウンロードが成功したことをテストするにはどうすればよいか、または機能テストを行うためにどのアサーションを使用できるかということです。

4

1 に答える 1