2016-04-15 98 views
1

我想從我的項目中測試URL的http狀態碼。phpunit/Symfony:BadMethodCallException

通過一些測試,我從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

這是一個奇怪的解決方案,但它在我的問題。請將assertEquals更改爲assertContains。

+0

這更適合作爲註釋。 –

0

更改配置processIsolation,你應該得到一個更清晰的測試失敗的消息