本文整理汇总了PHP中Zend_Http_Client_Adapter_Test::setResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Client_Adapter_Test::setResponse方法的具体用法?PHP Zend_Http_Client_Adapter_Test::setResponse怎么用?PHP Zend_Http_Client_Adapter_Test::setResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Http_Client_Adapter_Test
的用法示例。
在下文中一共展示了Zend_Http_Client_Adapter_Test::setResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Set up the test case
*
* @return void
*/
public function setUp()
{
$this->rackspace = new Zend_Service_Rackspace_Files('foo', 'bar');
$this->httpClientAdapterTest = new Zend_Http_Client_Adapter_Test();
$this->rackspace->getHttpClient()->setAdapter($this->httpClientAdapterTest);
// authentication (from a file)
$this->httpClientAdapterTest->setResponse(self::loadResponse('../../_files/testAuthenticate'));
$this->assertTrue($this->rackspace->authenticate(), 'Authentication failed');
$this->metadata = array('foo' => 'bar', 'foo2' => 'bar2');
$this->metadata2 = array('hello' => 'world');
// load the HTTP response (from a file)
$this->httpClientAdapterTest->setResponse($this->loadResponse($this->getName()));
}
示例2: setUp
/**
* Setup for each test
*/
public function setUp()
{
$this->infrastructure = Zend_Cloud_Infrastructure_Factory::getAdapter(array(Zend_Cloud_Infrastructure_Factory::INFRASTRUCTURE_ADAPTER_KEY => 'Zend_Cloud_Infrastructure_Adapter_Ec2', Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_ACCESS_KEY => 'foo', Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_SECRET_KEY => 'bar', Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_REGION => 'us-east-1'));
$this->httpClientAdapterTest = new Zend_Http_Client_Adapter_Test();
// load the HTTP response (from a file)
$shortClassName = substr(__CLASS__, strlen('Zend_Cloud_Infrastructure_Adapter_'));
$filename = dirname(__FILE__) . '/_files/' . $shortClassName . '_' . $this->getName() . '.response';
if (file_exists($filename)) {
$this->httpClientAdapterTest->setResponse($this->loadResponse($filename));
}
$adapter = $this->infrastructure->getAdapter();
$client = new Zend_Http_Client(null, array('adapter' => $this->httpClientAdapterTest));
call_user_func(array($adapter, 'setHttpClient'), $client);
}
示例3: testTagSearchBasic
/**
* Basic testing to ensure that tagSearch() works as expected
*
* @return void
*/
public function testTagSearchBasic()
{
$this->_flickr->getRestClient()->getHttpClient()->setAdapter($this->_httpClientAdapterTest);
$this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__));
$options = array('per_page' => 10, 'page' => 1, 'tag_mode' => 'or', 'extras' => 'license, date_upload, date_taken, owner_name, icon_server');
$resultSet = $this->_flickr->tagSearch('php', $options);
$this->assertEquals(4285, $resultSet->totalResultsAvailable);
$this->assertEquals(10, $resultSet->totalResults());
$this->assertEquals(10, $resultSet->totalResultsReturned);
$this->assertEquals(1, $resultSet->firstResultPosition);
$this->assertEquals(0, $resultSet->key());
try {
$resultSet->seek(-1);
} catch (OutOfBoundsException $e) {
$this->assertContains('Illegal index', $e->getMessage());
}
$resultSet->seek(9);
try {
$resultSet->seek(10);
} catch (OutOfBoundsException $e) {
$this->assertContains('Illegal index', $e->getMessage());
}
$resultSet->rewind();
$resultSetIds = array('428222530', '427883929', '427884403', '427887192', '427883923', '427884394', '427883930', '427884398', '427883924', '427884401');
$this->assertTrue($resultSet->valid());
foreach ($resultSetIds as $resultSetId) {
$this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__ . "-result_{$resultSetId}"));
$result = $resultSet->current();
$this->assertTrue($result instanceof Zend_Service_Flickr_Result);
$resultSet->next();
}
$this->assertFalse($resultSet->valid());
}
示例4: testGravatarExistsWithCache
/**
* @covers Robo47_Service_Gravatar::gravatarExists
* @covers Robo47_Service_Gravatar::_getCacheId
* @dataProvider gravatarExistsProvider
*/
public function testGravatarExistsWithCache()
{
$cache = Zend_Cache::factory('Core', new Robo47_Cache_Backend_Array(), array('automatic_cleaning_factor' => 0), array('automatic_cleaning_factor' => 0));
$options = array('cachePrefix' => 'foo_', 'cache' => $cache);
$service = new Robo47_Service_Gravatar($options);
// do first request
$this->_adapter->setResponse(new Zend_Http_Response(404, array()));
$this->assertSame(false, $service->gravatarExists('foo@example.com'));
$cacheEntry = $cache->load($service->getCacheId('foo@example.com'));
$this->assertEquals('false', $cacheEntry, 'wrong value in cache');
// assert cache is used and no request is made
$this->_adapter->setResponse(new Zend_Http_Response(200, array()));
$this->assertSame(false, $service->gravatarExists('foo@example.com'));
$cacheEntry = $cache->load($service->getCacheId('foo@example.com'));
$this->assertEquals('false', $cacheEntry, 'wrong value in cache');
// ignore cache for checking
$this->_adapter->setResponse(new Zend_Http_Response(200, array()));
$this->assertSame(true, $service->gravatarExists('foo@example.com', false));
$cacheEntry = $cache->load($service->getCacheId('foo@example.com'));
$this->assertEquals('true', $cacheEntry, 'wrong value in cache');
// use cache for checking
$this->_adapter->setResponse(new Zend_Http_Response(404, array()));
$this->assertSame(true, $service->gravatarExists('foo@example.com'));
$cacheEntry = $cache->load($service->getCacheId('foo@example.com'));
$this->assertEquals('true', $cacheEntry, 'wrong value in cache');
// ignore cache again for checking
$this->_adapter->setResponse(new Zend_Http_Response(404, array()));
$this->assertSame(false, $service->gravatarExists('foo@example.com', false));
$cacheEntry = $cache->load($service->getCacheId('foo@example.com'));
$this->assertEquals('false', $cacheEntry, 'wrong value in cache');
}
示例5: setUp
/**
* Setup for each test
*/
public function setUp()
{
$this->infrastructure = Zend_Cloud_Infrastructure_Factory::getAdapter(array(Zend_Cloud_Infrastructure_Factory::INFRASTRUCTURE_ADAPTER_KEY => 'Zend_Cloud_Infrastructure_Adapter_Rackspace', Zend_Cloud_Infrastructure_Adapter_Rackspace::RACKSPACE_USER => 'foo', Zend_Cloud_Infrastructure_Adapter_Rackspace::RACKSPACE_KEY => 'bar', Zend_Cloud_Infrastructure_Adapter_Rackspace::RACKSPACE_REGION => 'USA'));
$this->httpClientAdapterTest = new Zend_Http_Client_Adapter_Test();
$this->infrastructure->getAdapter()->getHttpClient()->setAdapter($this->httpClientAdapterTest);
// load the HTTP response (from a file)
$shortClassName = 'RackspaceTest';
$filename = dirname(__FILE__) . '/_files/' . $shortClassName . '_' . $this->getName() . '.response';
if (file_exists($filename)) {
// authentication (from file)
$content = dirname(__FILE__) . '/_files/' . $shortClassName . '_testAuthenticate.response';
$this->httpClientAdapterTest->setResponse($this->loadResponse($content));
$this->assertTrue($this->infrastructure->getAdapter()->authenticate(), 'Authentication failed');
$this->httpClientAdapterTest->setResponse($this->loadResponse($filename));
}
}
示例6: shouldUnshortenAGivenShortenedUrl
/**
* @test
*/
public function shouldUnshortenAGivenShortenedUrl()
{
$adapter = new Zend_Http_Client_Adapter_Test();
$client = new Zend_Http_Client('http://adapter.org', array('adapter' => $adapter));
$adapter->setResponse("HTTP/1.1 302 Found" . "\r\n" . "Location: http://zendframework.com" . "\r\n");
$this->_service = new Recordshelf_Service_Isgd($client);
$this->assertEquals('http://zendframework.com', $this->_service->unshorten('http://is.gd/1T35Q'));
}
示例7: testAuthenticateError
/**
* Test the authentication error (401 Unauthorized - Bad username or password)
*
* @return void
*/
public function testAuthenticateError()
{
$this->_files->getHttpClient()->setAdapter($this->_httpClientAdapterTest);
$this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__));
$this->assertFalse($this->_files->authenticate());
$this->assertFalse($this->_files->isSuccessful());
$this->assertEquals($this->_files->getErrorCode(), '401');
$this->assertEquals($this->_files->getErrorMsg(), 'Bad username or password');
}
示例8: testSettingNextResponseByIndex
public function testSettingNextResponseByIndex()
{
$expected = array("HTTP/1.1 200 OK\r\n\r\n", "HTTP/1.1 302 Moved Temporarily\r\n\r\n", "HTTP/1.1 404 Not Found\r\n\r\n");
$this->adapter->setResponse($expected);
$this->assertEquals($expected[0], $this->adapter->read());
foreach ($expected as $i => $expected) {
$this->adapter->setResponseIndex($i);
$this->assertEquals($expected, $this->adapter->read());
}
}
示例9: _importInvalid
/**
* Import an invalid feed
*/
protected function _importInvalid($filename)
{
$response = new Zend_Http_Response(200, array(), file_get_contents("{$this->_feedDir}/{$filename}"));
$this->_adapter->setResponse($response);
try {
$feed = Zend_Feed::import('http://localhost');
} catch (Exception $e) {
}
$this->assertTrue($e instanceof Zend_Feed_Exception, 'Expected Zend_Feed_Exception to be thrown');
}
示例10: _importInvalid
/**
* Imports an invalid feed
*/
protected function _importInvalid($filename)
{
$response = new Zend_Http_Response(200, array(), file_get_contents("{$this->_feedDir}/{$filename}"));
$this->_adapter->setResponse($response);
try {
$feed = Zend_Feed::import('http://localhost');
$this->fail('Expected Zend_Feed_Exception not thrown');
} catch (Zend_Feed_Exception $e) {
$this->assertType('Zend_Feed_Exception', $e);
}
}
示例11: testUserSearchExceptionEmailInvalid
/**
* Ensures that userSearch() throws an exception when an invalid e-mail address is given
*
* @return void
*/
public function testUserSearchExceptionEmailInvalid()
{
$this->_flickr->getRestClient()->getHttpClient()->setAdapter($this->_httpClientAdapterTest);
$this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__));
try {
$this->_flickr->userSearch('2e38a9d9425d7e2c9d0788455e9ccc61@example.com');
$this->fail('Expected Zend_Service_Exception not thrown');
} catch (Zend_Service_Exception $e) {
$this->assertContains('User not found', $e->getMessage());
}
}
示例12: testGroupPoolGetPhotosExceptionGroupIdInvalid
/**
* Ensures that groupPoolGetPhotos() throws an exception when an invalid group_id is given
*
* @return void
*/
public function testGroupPoolGetPhotosExceptionGroupIdInvalid()
{
$this->_flickr->getRestClient()->getHttpClient()->setAdapter($this->_httpClientAdapterTest);
$this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__));
try {
$this->_flickr->groupPoolGetPhotos('2e38a9d9425d7e2c9d0788455e9ccc61');
$this->fail('Expected Zend_Service_Exception not thrown');
} catch (Zend_Service_Exception $e) {
$this->assertContains('Group not found', $e->getMessage());
}
}
示例13: testGetAdapterWithConfig
public function testGetAdapterWithConfig()
{
$httptest = new Zend_Http_Client_Adapter_Test();
// Nirvanix adapter
$nirvanixConfig = new Zend_Config_Ini(realpath(dirname(__FILE__) . '/_files/config/nirvanix.ini'));
$nirvanixConfig = $nirvanixConfig->toArray();
$nirvanixConfig[Zend_Cloud_StorageService_Adapter_Nirvanix::HTTP_ADAPTER] = $httptest;
$doc = new DOMDocument('1.0', 'utf-8');
$root = $doc->createElement('Response');
$responseCode = $doc->createElement('ResponseCode', 0);
$sessionTok = $doc->createElement('SessionToken', '54592180-7060-4D4B-BC74-2566F4B2F943');
$root->appendChild($responseCode);
$root->appendChild($sessionTok);
$doc->appendChild($root);
$body = $doc->saveXML();
$resp = new Zend_Http_Response(200, array('Date' => 0), $body);
$httptest->setResponse($resp);
$nirvanixAdapter = Zend_Cloud_StorageService_Factory::getAdapter($nirvanixConfig);
$this->assertEquals('Zend_Cloud_StorageService_Adapter_Nirvanix', get_class($nirvanixAdapter));
// S3 adapter
$s3Config = new Zend_Config_Ini(realpath(dirname(__FILE__) . '/_files/config/s3.ini'));
$s3Adapter = Zend_Cloud_StorageService_Factory::getAdapter($s3Config);
$this->assertEquals('Zend_Cloud_StorageService_Adapter_S3', get_class($s3Adapter));
// file system adapter
$fileSystemConfig = new Zend_Config_Ini(realpath(dirname(__FILE__) . '/_files/config/filesystem.ini'));
$fileSystemAdapter = Zend_Cloud_StorageService_Factory::getAdapter($fileSystemConfig);
$this->assertEquals('Zend_Cloud_StorageService_Adapter_FileSystem', get_class($fileSystemAdapter));
// Azure adapter
$azureConfig = new Zend_Config_Ini(realpath(dirname(__FILE__) . '/_files/config/windowsazure.ini'));
$azureConfig = $azureConfig->toArray();
$azureContainer = $azureConfig[Zend_Cloud_StorageService_Adapter_WindowsAzure::CONTAINER];
$azureConfig[Zend_Cloud_StorageService_Adapter_WindowsAzure::HTTP_ADAPTER] = $httptest;
$q = "?";
$doc = new DOMDocument('1.0', 'utf-8');
$root = $doc->createElement('EnumerationResults');
$acctName = $doc->createAttribute('AccountName');
$acctName->value = 'http://myaccount.blob.core.windows.net';
$root->appendChild($acctName);
$maxResults = $doc->createElement('MaxResults', 1);
$containers = $doc->createElement('Containers');
$container = $doc->createElement('Container');
$containerName = $doc->createElement('Name', $azureContainer);
$container->appendChild($containerName);
$containers->appendChild($container);
$root->appendChild($maxResults);
$root->appendChild($containers);
$doc->appendChild($root);
$body = $doc->saveXML();
$resp = new Zend_Http_Response(200, array('x-ms-request-id' => 0), $body);
$httptest->setResponse($resp);
$azureAdapter = Zend_Cloud_StorageService_Factory::getAdapter($azureConfig);
$this->assertEquals('Zend_Cloud_StorageService_Adapter_WindowsAzure', get_class($azureAdapter));
}
示例14: testWebSourceSearch
public function testWebSourceSearch()
{
$this->_bing->getHttpClient()->setAdapter($this->_httpClientAdapterTest);
$this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__));
$searchResult = $this->_bing->search('tom graham', array('web' => array('count' => 10, 'offset' => 0)));
$this->assertTrue($searchResult->hasSource('web'));
// Check the source name isn't case sensitive
$this->assertTrue($searchResult->hasSource('Web'));
$resultSet = $searchResult->getSource('web');
$this->assertType('Noginn_Service_Bing_WebResultSet', $resultSet);
$this->assertEquals(10, count($resultSet));
$this->assertEquals(25800000, $resultSet->getTotal());
$this->assertEquals(0, $resultSet->getOffset());
$this->assertEquals(0, $resultSet->key());
// Attempt to seek below the lower bound
try {
$resultSet->seek(-1);
$this->fail('Expected OutOfBoundsException not thrown');
} catch (OutOfBoundsException $e) {
$this->assertContains('Illegal index', $e->getMessage());
}
$resultSet->seek(9);
// Attempt to seek above the upper bound
try {
$resultSet->seek(10);
$this->fail('Expected OutOfBoundsException not thrown');
} catch (OutOfBoundsException $e) {
$this->assertContains('Illegal index', $e->getMessage());
}
$resultSet->rewind();
$this->assertTrue($resultSet->valid());
$result = $resultSet->current();
$this->assertEquals('Thomas Graham and Sons', $result->getTitle());
$this->assertEquals('Stockists of engineering fasteners and steel stock. The site gives information on the range of products and a history of the company.', $result->getDescription());
$this->assertEquals('http://www.thomas-graham.co.uk/', $result->getUrl());
$this->assertEquals('http://cc.bingj.com/cache.aspx?q=tom+graham&d=76275785218222&w=608c9417,5ee03831', $result->getCacheUrl());
$this->assertEquals('www.thomas-graham.co.uk', $result->getDisplayUrl());
$this->assertEquals('2009-06-21T09:09:36Z', $result->getDateTime());
}
示例15: testApiMethods
/**
* @covers Robo47_Service_Bitly::_callApi
* @covers Robo47_Service_Bitly::_getData
* @covers Robo47_Service_Bitly::shorten
* @covers Robo47_Service_Bitly::expandByHash
* @covers Robo47_Service_Bitly::expandByShortUrl
* @covers Robo47_Service_Bitly::infoByHash
* @covers Robo47_Service_Bitly::infoByHashWithKeys
* @covers Robo47_Service_Bitly::infoByShortUrl
* @covers Robo47_Service_Bitly::infoByShortUrlWithKeys
* @covers Robo47_Service_Bitly::statsByHash
* @covers Robo47_Service_Bitly::statsByShortUrl
* @covers Robo47_Service_Bitly::errors
* @dataProvider apiMethodsProvider
*/
public function testApiMethods($method, $params, $format, $resultFormat)
{
$service = new Robo47_Service_Bitly('login', 'apiKey', $format, $resultFormat);
$this->_adapter->setResponse($this->getResponse($format, $method));
$result = call_user_func_array(array($service, $method), $params);
$response = $service->getHttpClient()->request()->getBody();
if ($format == Robo47_Service_Bitly::FORMAT_JSON) {
if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_NATIVE) {
$this->assertEquals($result, $response, 'Mismatch of result and response');
} else {
if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_ARRAY) {
$this->assertEquals($result, json_decode($response, true), 'Mismatch of result and response');
} else {
if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_OBJECT) {
$this->assertEquals($result, json_decode($response, false), 'Mismatch of result and response');
} else {
$this->fail('invalid resultformat: ' . $resultFormat);
}
}
}
} else {
if ($format == Robo47_Service_Bitly::FORMAT_XML) {
if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_NATIVE) {
$this->assertEquals($result, $response, 'Mismatch of result and response');
} else {
if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_ARRAY) {
$this->assertEquals($result, $service->xmlToArray($response), 'Mismatch of result and response');
} else {
if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_OBJECT) {
$this->assertEquals($result, $service->xmlToObject($response), 'Mismatch of result and response');
} else {
$this->fail('invalid resultformat: ' . $resultFormat);
}
}
}
} else {
$this->fail('invalid format: ' . $format);
}
}
}