php - Symfony and PHPUnit: Exception thrown but not intercepted by setExpectedException -


i wrote test controller saves in database data passed form.

i wrote following test method sure if form empty exception thrown:

public function testregisternewmerchantexceptionnodatasubmitted() {     $client = static::createclient();     $crawler = $client->request('get', '/getstarted');      $form = $crawler->selectbutton('getstarted[submit]')->form();     $form['getstarted[email]'] = '';      $this->setexpectedexception('domainexception');     $client->submit($form);      $this->assertequals(500, $client->getresponse()->getstatuscode());      //dump($client->getresponse());die; } 

the method i'm testing following:

public function endaction(request $request) {     $form = $this->createform(new getstartedtype());      $form->handlerequest($request);      if ($form->isvalid()) {         // data form         $data = $form->getdata();     } else {         throw new  \domainexception('no data submitted.');     }      ... 

i'm sure during tests exception thrown because dumping response object page 500 error reporting exact message "no data submitted". more, assertequals test on status code successful, there no doubts exception correctly thrown.

but $this->setexpectedexception() test doesn't intercept , returns fail of test.

any idea why happens?

using $this->setexcpectedexception() tells phpunit expect given exception type thrown test method, not exception of type thrown @ point during execution.

when throw exception in controller method, symfony controller catches exception , creates 500 response. means exception not thrown test method, test fails. test looks reasonable otherwise, removing $this->setexpectedexception() should solve problem , test behavior intended.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -