1

在 PHPUnit 测试中使用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..."任何地方 :( 但是我可以将内容放在标题中,所以我确信插件可以正常工作,至少在某种程度上是这样。

4

1 回答 1

0

问题是我没有正确发送或阅读。

据此,需要阅读内容以$response->getBody(true)将其作为字符串阅读。

你们中的一些人可能已经注意到了$content->asXML()in post 功能。所以我实际上需要做$response->xml()的,并且记得把->asXML()发送的内容放在。现在它起作用了!

于 2013-10-15T13:49:54.623 回答