2013-10-15 29 views
1

在PHPUnit測試中使用Guzzle MockPlugin。我發現無論我做什麼,響應內容主體都是空的。Guzzle MockPlugin未響應內容正文

我做錯了什麼,或者它是一個錯誤?

測試設置

$client = new Client(); 
$plugin = new MockPlugin(); 
$plugin->addResponse(new Response(200, null, "This is never sent...")); 
$client->addSubscriber($plugin); 

$this->httpClientFactoryMock 
    ->expects($this->any()) 
    ->method('getClient') 
    ->will($this->returnValue($client)); 

方法測試

$client = $this->httpClientFactory->getClient(); 
$request = $client->post($this->url, null, $content->asXML()); 
$response = $request->send(); 

$response->body沒有"This is never sent..."任何地方:( 不過,我可以把東西放在頭,所以我確保插件正在工作,至少在某種程度上。

回答

0

問題是我沒有發送或閱讀正確。

根據this我需要讀取$response->getBody(true)的內容才能將其讀取爲字符串。

你們中的一些人可能已經注意到後功能中的$content->asXML()。所以我其實需要做$response->xml(),並且記得把->asXML()放在發送的內容上。現在它工作了!