本文整理汇总了PHP中Factory::createRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::createRequest方法的具体用法?PHP Factory::createRequest怎么用?PHP Factory::createRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Factory
的用法示例。
在下文中一共展示了Factory::createRequest方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateFactory
public function testCreateFactory()
{
$factory = new Factory('http://localhost/');
$factory->setRequestClassNamespace('\\Sokil\\Rest\\Client\\RequestMock');
$request = $factory->createRequest('getRequestMock');
$this->assertInstanceOf('\\Sokil\\Rest\\Client\\Request', $request);
}
示例2: 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());
}
示例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());
}