【发布时间】:2017-01-07 00:32:46
【问题描述】:
系统信息:
- PHPUnit 5.7.4
- PHP 7.0.13
- Symfony 3.2.1
我正在尝试点击“下载”页面上的链接并验证文件是否可下载,但是当我点击链接$client->click($crawlerDownload->link()); 时,我得到了404。 symfony $client 不能访问 web 目录中的静态文件吗?我该如何测试?
网站图标测试是测试用例的简化版本。
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