本文整理汇总了PHP中Factory::setRequestClassNamespace方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::setRequestClassNamespace方法的具体用法?PHP Factory::setRequestClassNamespace怎么用?PHP Factory::setRequestClassNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Factory
的用法示例。
在下文中一共展示了Factory::setRequestClassNamespace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBehaviorOwner
public function testBehaviorOwner()
{
$factory = new Factory('http://localhost/');
$factory->setRequestClassNamespace('\\Sokil\\Rest\\Client\\RequestMock');
$factory->attachBehavior('my', new \Sokil\Rest\Client\MyBehavior());
// exec behavior
$requert = $factory->createRequest('GetRequestMock');
$this->assertEquals('http://localhost/some/resource', $requert->getRequestUrl());
}
示例2: testCreateSignedRequest
public function testCreateSignedRequest()
{
// replace response
$plugin = new \Guzzle\Plugin\Mock\MockPlugin();
$plugin->addResponse(new \Guzzle\Http\Message\Response(200, array('Content-type' => 'application/json'), json_encode(array('error' => 0))));
// configure subscriber
$signKey = 'APP_KEY';
$factory = new Factory('http://localhost/');
$factory->setRequestClassNamespace('\\Sokil\\Rest\\Client\\RequestMock')->setSignKey($signKey)->addSignAdditionalParam('app_id', 'APP_ID');
$request = $factory->createSignedRequest('GetRequestMock');
$request->addSubscriber($plugin);
$response = $request->setQueryParam('param', 'value')->send();
// test signature
$body = $request->getQueryParams();
unset($body['sign']);
ksort($body);
// calculate and compare sign with passed
$this->assertEquals(hash_hmac($factory->getSignAlgo(), http_build_query($body), $signKey), $request->getQueryParam('sign'));
}
示例3: testOnError
/**
* @expectedException \Guzzle\Http\Exception\BadResponseException
*/
public function testOnError()
{
// replace response
$plugin = new \Guzzle\Plugin\Mock\MockPlugin();
$plugin->addResponse(new \Guzzle\Http\Message\Response(404, array('Content-type' => 'application/json'), json_encode(array('error' => 0))));
$factory = new Factory('http://localhost/');
$factory->setRequestClassNamespace('\\Sokil\\Rest\\Client\\RequestMock');
$factory->addSubscriber($plugin);
$status = new \stdclass();
$status->status = 0;
$factory->onError(function ($event) use($status) {
$status->status = $event['response']->getStatusCode();
});
// send
$request = $factory->createRequest('GetRequestMock');
try {
$response = $request->send();
} catch (\Exception $e) {
// check if event occured
$this->assertEquals(404, $status->status);
throw $e;
}
}
示例4: testBuildUrlForRequest
public function testBuildUrlForRequest()
{
// configure subscriber
$factory = new Factory('http://localhost/basepath');
$factory->setRequestClassNamespace('\\Sokil\\Rest\\Client\\RequestMock');
$request = $factory->createRequest('GetRequestMock');
$this->assertEquals('http://localhost/basepath/some/resource', $request->getUrl());
}