unit testing - Assert 403 Access Denied http status with PHPUnit test case -


i have custom error templates in projects 404, 403 , other exceptions. want create unit test case assert http errors. when logging user , accessing authorized page of vendor getting 403 access denied in browser in unit test case getting 404 page not found error.

here test scenario:

class errorexceptiontest extends webtestcase {     public function testaccessdeniedexception()     {         $server['http_host'] = 'http://www.test.com/';         $client = static::createclient(array('debug' => false), $server);         $client->disablereboot();          $session = $client->getcontainer()->get('session');         $firewall = 'main';          $token = new usernamepasswordtoken('user', null, $firewall, array('role_user'));          $session->set("_security_$firewall", serialize($token));         $session->save();          $cookie = new cookie($session->getname(), $session->getid());         $client->getcookiejar()->set($cookie);          $client->request('get', '/vendor/profile/edit');          $this->assertequals(403, $client->getresponse()->getstatuscode());         $this->assertcontains('sorry! access denied',  $client->getresponse()->getcontent());     } } 

my test case being failed, when print response content show 404 error template.

worked around , find issue. so, solution no need use http host.

public function testaccessdeniedexception() {     $client = static::createclient(array('debug' => false));      $session = $client->getcontainer()->get('session');     $firewall = 'main';      $token = new usernamepasswordtoken('user', null, $firewall, array('role_user'));      $session->set("_security_$firewall", serialize($token));     $session->save();      $cookie = new cookie($session->getname(), $session->getid());     $client->getcookiejar()->set($cookie);      $client->request('get', 'fr/vendor/profile/edit');      $this->assertequals(403, $client->getresponse()->getstatuscode());     $this->assertcontains('sorry! access denied',  $client->getresponse()->getcontent()); } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -