本文整理汇总了PHP中Guzzle\Http\Client::dispatch方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::dispatch方法的具体用法?PHP Client::dispatch怎么用?PHP Client::dispatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Client
的用法示例。
在下文中一共展示了Client::dispatch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testWorksUsingEvents
/**
* @covers Guzzle\Http\Plugin\BatchQueuePlugin::onRequestCreate
* @covers Guzzle\Http\Plugin\BatchQueuePlugin::addRequest
* @covers Guzzle\Http\Plugin\BatchQueuePlugin::onRequestBeforeSend
*/
public function testWorksUsingEvents()
{
// Queue up some test responses
$this->getServer()->flush();
$this->getServer()->enqueue(array(new Response(200), new Response(200), new Response(200)));
$plugin = new BatchQueuePlugin(2);
$client = new Client($this->getServer()->getUrl());
$client->getEventDispatcher()->addSubscriber($plugin);
$client->get('/');
$client->get('/');
// Ensure that the requests were sent implicitly
$this->assertEquals(0, count($plugin));
$this->assertEquals(2, count($this->getServer()->getReceivedRequests()));
// Add a single request and ensure that it is in queue and not sent
$client->get('/');
$this->assertEquals(1, count($plugin));
$this->assertEquals(2, count($this->getServer()->getReceivedRequests()));
// Explicitly flush the queued requests
$client->dispatch('flush');
$this->assertEquals(0, count($plugin));
$this->assertEquals(3, count($this->getServer()->getReceivedRequests()));
}