Failed asserting the HTTP status code is 200 not 500

后端 未结 2 1367
伪装坚强ぢ
伪装坚强ぢ 2021-01-20 05:06

I\'m trying to functional test the HTTP status code for a certain request is 200 not 500. I\'m using Symfony2, and here\'s the code:



        
相关标签:
2条回答
  • 2021-01-20 05:21

    The 500 error can be caused by anything in your case.

    What you could do in such situation is to dump the content of the response and check the Symfony debugging message.

    I usually use such code snippet for quick checking such errors directly in terminal:

    if (!$response->isSuccessful()) {
        $block = $crawler->filter('div.text_exception > h1');
        if ($block->count()) {
            $error = $block->text();
        }
    }
    

    where div.text_exception > h1 is the xpath from Symfony2 debug page to the message itself

    Then just print the $error

    0 讨论(0)
  • 2021-01-20 05:23

    You could also echo the html after the request to see what's in the response.

    echo $crawler->html();
    
    0 讨论(0)
提交回复
热议问题