SYSINFO:如何使用phpunit測試位於symfony web文件夾中的靜態文件?
- PHPUnit的5.7.4
- PHP 7.0.13
- 的Symfony 3.2.1
我試圖遵循 「下載」 頁面上的鏈接和驗證文件是可下載的,但當我按照鏈接$client->click($crawlerDownload->link());
我得到一個404
。 symfony $client
不可能訪問web目錄中的靜態文件嗎?我如何測試這個?
favicon測試是測試用例的簡化版本。
public function testPressDownload()
{
$client = static::createClient();
$client->followRedirects(false);
//create fixture file
$kernelDir = $client->getKernel()->getRootDir();
$file = "${kernelDir}/../web/download/example.zip";
file_put_contents($file, "dummy content");
$crawler = $client->request('GET', '/files');
$this->assertEquals(200, $client->getResponse()->getStatusCode()); //ok
$crawlerDownload = $crawler
->filter('a[title="example.zip"]')
;
$this->assertEquals(1, $crawlerDownload->count()); //ok
$client->click($crawlerDownload->link());
$this->assertEquals(200, $client->getResponse()->getStatusCode()); //fails 404
}
public function testFavicon()
{
$crawler = $client->request('GET', '/favicon.ico');
$this->assertEquals(200, $client->getResponse()->getStatusCode()); //fails 404
}
你有沒有嘗試過:'$ crawler = $ client-> request('GET','favicon.ico');'沒有正斜槓? –
是的也試過沒有斜槓'/'。相同的結果 - >'404' – c33s