sysinfo:
i am trying to follow a link on a "download" page and verify the file is downloadable but when i follow the link $client->click($crawlerDownload->link());
i get a 404
. is it not possible for the symfony $client
to access a static file in the webdirectory? how can i test this?
the favicon test is the simplified version of the testcase.
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
}
You can't, tests are bootstraping the application, it's not a "real web server" so when requesting /favicon.ico
, it searches for a route in the application corresponding to this path which is not found.
To verify this, create a fake route:
/**
* @Route("/favicon.ico", name="fake_favicon_route")
*
* @return Response
*/
You will see that the test will now pass.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With