我想测试项目中URL的http状态代码。
通过一些测试,我从phpunit收到以下错误消息:
1) pp\TheBundle\Tests\UrlTests\UrlTests::test18Url
PHPUnit_Framework_Exception: PHP Fatal error: Uncaught exception 'BadMethodCallException' with message 'A Crawler cannot be serialized.' in /var/www/viasenso/muttersystem/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Crawler.php:315
Stack trace:
#0 [internal function]: Symfony\Component\DomCrawler\Crawler->serialize()
#1 -(364): serialize(Array)
#2 -(513): __phpunit_run_isolated_test()
#3 {main}
thrown in /var/www/viasenso/muttersystem/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Crawler.php on line 315
Fatal error: Uncaught exception 'BadMethodCallException' with message 'A Crawler cannot be serialized.' in /var/www/viasenso/muttersystem/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Crawler.php on line 315
BadMethodCallException: A Crawler cannot be serialized. in /var/www/viasenso/muttersystem/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Crawler.php on line 315
Call Stack:
0.0022 441400 1. {main}() -:0
0.0400 4434840 2. __phpunit_run_isolated_test() -:513
0.6232 30949432 3. serialize() -:364
0.6235 31024280 4. Symfony\Component\DomCrawler\Crawler->serialize() -:364
这是测试功能的内容:
$crawler = $this->helper->getCrawler('/de/profil/the-profile/123/veroeffentlichen', [
'user' => $this->helper->getParameter('testing')['user']['admin']['username'],
'pwd' => $this->helper->getParameter('testing')['user']['admin']['password'],
]);
$this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode(),
'Status-Code ' . $this->client->getResponse()->getStatusCode() . ' on URL ' . $this->client->getRequest()->getUri() . '');
任何想法,为什么会发生这种错误?来自phpunit的调试信息并没有真正有用......
答案 0 :(得分:0)
这是一个奇怪的解决方案,但它解决了我的问题。请将assertEquals更改为assertContains。
答案 1 :(得分:0)
将config processIsolation 更改为 false ,您应该获得更清晰的测试失败消息