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