symfony2 で、クライアント側でファイルがうまくダウンロードされていることをテスト (機能テスト) するにはどうすればよいですか? 次のコードを試しましたが、何かが間違っています。
私のコントローラー:
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;
}
}
テストコード:
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 -> ".$response->headers;
}
最後に、phpunit による応答:
1) Application\MediaBundle\Tests\Controller\PictureControllerCopyTest::testupload
非オブジェクトのプロパティを取得しようとしています/var/www/symfony/ws1/src/Application/MediaBundle/Tests/Controller/PictureControllerCopyTest.php:28
失敗!テスト: 1、アサーション: 0、エラー: 1。