【发布时间】:2017-02-05 20:51:20
【问题描述】:
我刚刚开始使用Guzzle 使用PHPUnit 对 API 进行验收测试。 API 驻留在我的本地机器上,但Guzzle 的响应时间仍然是~5 秒!当我使用浏览器时,它会“立即”加载网站,让我相信这是Guzzle 或cURL 的问题。
这是我的测试单元:
class MyTest extends \PHPUnit_Framework_TestCase {
/** @var GuzzleHttp\Client */
private $http;
protected function setUp() {
$this->http = new GuzzleHttp\Client(['base_uri' => 'http://test-site.local']);
}
protected function tearDown() {
$this->http = null;
}
public function testGet() {
$response = $this->http->request('GET', 'users');
$this->assertEquals(200, $response->getStatusCode());
$contentType = $response->getHeaders()["Content-Type"][0];
$this->assertStringStartsWith("application/json", $contentType);
}
}
什么可能导致响应时间过长?
【问题讨论】:
标签: curl phpunit localhost guzzle