php Zend-Http-Client-Adapter-Test类(方法)实例源码

下面列出了php Zend-Http-Client-Adapter-Test 类(方法)源码代码实例,从而了解它的用法。

作者:robborock    项目:ZendService_Amazo   
/**
  * Tests Zend_Service_Amazon_Ec2_Instance_Reserved->purchaseOffering()
  */
 public function testPurchaseOffering()
 {
     $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "<PurchaseReservedInstancesOfferingResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n" . "  <reservedInstancesId>4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8</reservedInstancesId>\r\n" . "</PurchaseReservedInstancesOfferingResponse>";
     $this->httpClientTestAdapter->setResponse($rawHttpResponse);
     $return = $this->instance->purchaseOffering('4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8');
     $this->assertSame('4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8', $return);
 }

作者:robertodormepoc    项目:zf   
public function testGetAdapterWithConfig()
 {
     $httptest = new HttpClientTest();
     // Nirvanix adapter
     $nirvanixConfig = ConfigFactory::fromFile(realpath(dirname(__FILE__) . '/_files/config/nirvanix.ini'), true);
     $nirvanixConfig = $nirvanixConfig->toArray();
     $nirvanixConfig[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 = HttpResponse::fromString("HTTP/1.1 200 OK\nContent-type: text/xml;charset=UTF-8\nDate: 0\n\n" . $body);
     $httptest->setResponse($resp);
     $nirvanixAdapter = Factory::getAdapter($nirvanixConfig);
     $this->assertEquals('Zend\\Cloud\\StorageService\\Adapter\\Nirvanix', get_class($nirvanixAdapter));
     // S3 adapter
     $s3Config = ConfigFactory::fromFile(realpath(dirname(__FILE__) . '/_files/config/s3.ini'), true);
     $s3Adapter = Factory::getAdapter($s3Config);
     $this->assertEquals('Zend\\Cloud\\StorageService\\Adapter\\S3', get_class($s3Adapter));
     // file system adapter
     $fileSystemConfig = ConfigFactory::fromFile(realpath(dirname(__FILE__) . '/_files/config/filesystem.ini'), true);
     $fileSystemAdapter = Factory::getAdapter($fileSystemConfig);
     $this->assertEquals('Zend\\Cloud\\StorageService\\Adapter\\FileSystem', get_class($fileSystemAdapter));
     // Azure adapter
     /*
             $azureConfig    = ConfigFactory::fromFile(realpath(dirname(__FILE__) . '/_files/config/windowsazure.ini'), true);
             $azureConfig    = $azureConfig->toArray();
             $azureContainer = $azureConfig[WindowsAzure::CONTAINER];
             $azureConfig[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 = HttpResponse::fromString("HTTP/1.1 200 OK\nContent-type: text/xml;charset=UTF-8\nx-ms-request-id: 0\n\n".$body);
     
             $httptest->setResponse($resp);
             $azureAdapter = Factory::getAdapter($azureConfig);
             $this->assertEquals('Zend\Cloud\StorageService\Adapter\WindowsAzure', get_class($azureAdapter));
     *
     */
 }

作者:robborock    项目:ZendService_Amazo   
public function testDescribeMultipleRegions()
 {
     $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "<DescribeRegionsResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n" . "  <regionInfo>\r\n" . "    <item>\r\n" . "      <regionName>us-east-1</regionName>\r\n" . "      <regionUrl>us-east-1.ec2.amazonaws.com</regionUrl>\r\n" . "    </item>\r\n" . "    <item>\r\n" . "      <regionName>us-west-1</regionName>\r\n" . "      <regionUrl>us-west-1.ec2.amazonaws.com</regionUrl>\r\n" . "    </item>\r\n" . "  </regionInfo>\r\n" . "</DescribeRegionsResponse>";
     $this->httpClientTestAdapter->setResponse($rawHttpResponse);
     $response = $this->regionInstance->describe(array('us-east-1', 'us-west-1'));
     $arrRegion = array(array('regionName' => 'us-east-1', 'regionUrl' => 'us-east-1.ec2.amazonaws.com'), array('regionName' => 'us-west-1', 'regionUrl' => 'us-west-1.ec2.amazonaws.com'));
     $this->assertSame($arrRegion, $response);
 }

作者:robertodormepoc    项目:zf   
/**
  * Tests Zend_Service_Amazon_Ec2_Instance_Windows->describeBundle()
  */
 public function testDescribeBundle()
 {
     $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "<DescribeBundleTasksResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n" . "  <bundleInstanceTasksSet>\r\n" . "    <item>\r\n" . "      <instanceId>i-12345678</instanceId>\r\n" . "      <bundleId>bun-cla322b9</bundleId>\r\n" . "      <state>bundling</state>\r\n" . "      <startTime>2008-10-07T11:41:50.000Z</startTime>\r\n" . "      <updateTime>2008-10-07T11:51:50.000Z</updateTime>\r\n" . "      <progress>20%</progress>\r\n" . "      <storage>\r\n" . "        <S3>\r\n" . "          <bucket>my-bucket</bucket>\r\n" . "          <prefix>my-new-image</prefix>\r\n" . "        </S3>\r\n" . "      </storage>\r\n" . "    </item>\r\n" . "  </bundleInstanceTasksSet>\r\n" . "</DescribeBundleTasksResponse>";
     $this->httpClientTestAdapter->setResponse($rawHttpResponse);
     $return = $this->instance->describeBundle('bun-cla322b9');
     $arrReturn = array(array("instanceId" => "i-12345678", "bundleId" => "bun-cla322b9", "state" => "bundling", "startTime" => "2008-10-07T11:41:50.000Z", "updateTime" => "2008-10-07T11:51:50.000Z", "progress" => "20%", "storage" => array("s3" => array("bucket" => "my-bucket", "prefix" => "my-new-image"))));
     $this->assertSame($arrReturn, $return);
 }

作者:guenter    项目:vufin   
public function testZF8149()
 {
     $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "<GetMetricStatisticsResponse xmlns=\"http://monitoring.amazonaws.com/doc/2009-05-15/\">\r\n" . "  <GetMetricStatisticsResult>\r\n" . "    <Datapoints>\r\n" . "      <member>\r\n" . "        <Timestamp>2009-11-19T21:52:00Z</Timestamp>\r\n" . "        <Unit>Percent</Unit>\r\n" . "        <Samples>1.0</Samples>\r\n" . "        <Average>0.09</Average>\r\n" . "      </member>\r\n" . "      <member>\r\n" . "        <Timestamp>2009-11-19T21:55:00Z</Timestamp>\r\n" . "        <Unit>Percent</Unit>\r\n" . "        <Samples>1.0</Samples>\r\n" . "        <Average>0.18</Average>\r\n" . "      </member>\r\n" . "      <member>\r\n" . "        <Timestamp>2009-11-19T21:54:00Z</Timestamp>\r\n" . "        <Unit>Percent</Unit>\r\n" . "        <Samples>1.0</Samples>\r\n" . "        <Average>0.09</Average>\r\n" . "      </member>\r\n" . "      <member>\r\n" . "        <Timestamp>2009-11-19T21:51:00Z</Timestamp>\r\n" . "        <Unit>Percent</Unit>\r\n" . "        <Samples>1.0</Samples>\r\n" . "        <Average>0.18</Average>\r\n" . "      </member>\r\n" . "      <member>\r\n" . "        <Timestamp>2009-11-19T21:53:00Z</Timestamp>\r\n" . "        <Unit>Percent</Unit>\r\n" . "        <Samples>1.0</Samples>\r\n" . "        <Average>0.09</Average>\r\n" . "      </member>\r\n" . "    </Datapoints>\r\n" . "    <Label>CPUUtilization</Label>\r\n" . "  </GetMetricStatisticsResult>\r\n" . "  <ResponseMetadata>\r\n" . "    <RequestId>6fb864fd-d557-11de-ac37-475775222f21</RequestId>\r\n" . "  </ResponseMetadata>\r\n" . "</GetMetricStatisticsResponse>";
     $this->httpClientTestAdapter->setResponse($rawHttpResponse);
     $return = $this->cloudWatchInstance->getMetricStatistics(array('MeasureName' => 'CPUUtilization', 'Statistics' => array('Average'), 'Dimensions' => array('InstanceId' => 'i-93ba31fa'), 'StartTime' => '2009-11-19T21:51:57+00:00', 'EndTime' => '2009-11-19T21:56:57+00:00'));
     $arrReturn = array('label' => 'CPUUtilization', 'datapoints' => array(0 => array('Timestamp' => '2009-11-19T21:52:00Z', 'Unit' => 'Percent', 'Samples' => '1.0', 'Average' => '0.09'), 1 => array('Timestamp' => '2009-11-19T21:55:00Z', 'Unit' => 'Percent', 'Samples' => '1.0', 'Average' => '0.18'), 2 => array('Timestamp' => '2009-11-19T21:54:00Z', 'Unit' => 'Percent', 'Samples' => '1.0', 'Average' => '0.09'), 3 => array('Timestamp' => '2009-11-19T21:51:00Z', 'Unit' => 'Percent', 'Samples' => '1.0', 'Average' => '0.18'), 4 => array('Timestamp' => '2009-11-19T21:53:00Z', 'Unit' => 'Percent', 'Samples' => '1.0', 'Average' => '0.09')));
     $this->assertSame($arrReturn, $return);
 }

作者:bbeckma    项目:NDL-VuFind   
/**
  * Load HTTP client w/ fixture
  *
  * @param string $fixture Fixture name
  *
  * @return HttpClient
  */
 protected function getClient($fixture)
 {
     $file = realpath(__DIR__ . '/../../../../fixtures/wikipedia/' . $fixture);
     $adapter = new TestAdapter();
     $adapter->setResponse(file_get_contents($file));
     $client = new HttpClient();
     $client->setAdapter($adapter);
     return $client;
 }

作者:poka    项目:webarchiv   
public function testRetrieve()
 {
     $mock = $this->getMock('WebArchive\\Provider\\ProviderInterface');
     $mock->expects($this->once())->method('generateSnapshots')->will($this->returnValue(true));
     $client = new Client(new Request(null), $mock);
     $adapter = new TestAdapter();
     $adapter->setResponse(new Response());
     $client->getClient()->setAdapter($adapter);
     $this->assertTrue($client->retrieve());
 }

作者:robertodormepoc    项目:zf   
/**
  * Sets up this test case
  *
  * @return void
  */
 public function setUp()
 {
     $this->gogrid = new Server('foo', 'bar');
     $this->httpClientAdapterTest = new \Zend\Http\Client\Adapter\Test();
     $this->gogrid->getHttpClient()->setAdapter($this->httpClientAdapterTest);
     $filename = __DIR__ . '/_files/' . $this->getName() . '.response';
     if (file_exists($filename)) {
         $this->httpClientAdapterTest->setResponse($this->loadResponse($filename));
     }
 }

作者:bix0    项目:Stjornvis   
/**
  * Result is not HTTP/1.1 200
  */
 public function testHttpError()
 {
     $client = new Client();
     $adapter = new Test();
     $adapter->setResponse(file_get_contents(__DIR__ . '/../data/google-map-response/03.txt'));
     $client->setAdapter($adapter);
     $map = new GoogleMap($client);
     $result = $map->request('My address');
     $this->assertNull($result->lat);
     $this->assertNull($result->lng);
 }

作者:grharr    项目:vufin   
/**
  * Load WorldCatUtils client w/ fixture
  *
  * @param string $fixture Fixture name
  * @param bool   $silent  Use silent mode?
  *
  * @return WorldCatUtils
  */
 protected function getClient($fixture = null, $silent = true)
 {
     $client = new HttpClient();
     if (null !== $fixture) {
         $adapter = new TestAdapter();
         $file = realpath(__DIR__ . '/../../../../fixtures/worldcat/' . $fixture);
         $adapter->setResponse(file_get_contents($file));
         $client->setAdapter($adapter);
     }
     return new WorldCatUtils('dummy', $client, $silent);
 }

作者:guenter    项目:vufin   
public function testDescribeMultipleAvailabilityZones()
 {
     $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "<DescribeAvailabilityZonesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n" . "  <availabilityZoneInfo>\r\n" . "    <item>\r\n" . "      <zoneName>us-east-1a</zoneName>\r\n" . "      <zoneState>available</zoneState>\r\n" . "    </item>\r\n" . "    <item>\r\n" . "      <zoneName>us-east-1b</zoneName>\r\n" . "      <zoneState>available</zoneState>\r\n" . "    </item>\r\n" . "    <item>\r\n" . "      <zoneName>us-east-1c</zoneName>\r\n" . "      <zoneState>available</zoneState>\r\n" . "    </item>\r\n" . "  </availabilityZoneInfo>\r\n" . "</DescribeAvailabilityZonesResponse>";
     $this->httpClientTestAdapter->setResponse($rawHttpResponse);
     $response = $this->availabilityZones->describe();
     $this->assertInternalType('array', $response);
     $arrExpected = array('us-east-1a', 'us-east-1b', 'us-east-1c');
     foreach ($response as $k => $node) {
         $this->assertEquals($arrExpected[$k], $node['zoneName']);
     }
 }

作者:DavidHav    项目:Ajast   
/**
  * @covers ::updateAddressFormats
  */
 public function testUpdateAddressFormatsUsesProgresAdapter()
 {
     $testAdapter = new HttpTestAdapter();
     $testAdapter->setResponse([(new HttpResponse())->setContent('empty'), (new HttpResponse())->setContent('{"name": "ZZ"}')]);
     $httpClient = new HttpClient();
     $httpClient->setAdapter($testAdapter);
     $progressAdapter = $this->getMock('Zend\\ProgressBar\\Adapter\\AbstractAdapter');
     $progressAdapter->expects($this->any())->method('notify')->with($this->logicalOr($this->equalTo(0.0), $this->equalTo(1.0)), $this->equalTo(1.0));
     $maintenanceService = new MaintenanceService($this->options, $httpClient);
     $maintenanceService->updateAddressFormats($progressAdapter);
 }

作者:bix0    项目:Stjornvis   
/**
  * Data is OK, but the response header
  * is HTTP/1.1 404 Not Found
  */
 public function testNot200ResponseCode()
 {
     $client = new Client();
     $adapter = new Test();
     $adapter->setResponse(file_get_contents(__DIR__ . '/../data/ja-response/03.txt'));
     $client->setAdapter($adapter);
     $map = new JaMap($client);
     $result1 = $map->request("Hringbraut 107, 101 Reykjavík");
     $this->assertNull($result1->lat);
     $this->assertNull($result1->lng);
 }

作者:poka    项目:webarchiv   
/**
  * @return \WebArchive\SnapshotCollection
  */
 private function generateSnapshots()
 {
     $uri = 'http://pokap.io/';
     $provider = new MementoProvider();
     $client = new Client($provider->createUrlRequest($uri));
     $response = new Response();
     $response->setContent(implode(gzfile(__DIR__ . '/fixtures/pokap.io-memento.gz')));
     $adapter = new TestAdapter();
     $adapter->setResponse($response);
     $client->setAdapter($adapter);
     return $provider->generateSnapshots($client->send(), $uri);
 }

作者:poka    项目:webarchiv   
/**
  * @param int $year
  *
  * @return \WebArchive\SnapshotCollection
  */
 private function generateSnapshots($year)
 {
     $uri = 'http://archive.org/';
     $provider = new WayBackProvider($year);
     $client = new Client($provider->createUrlRequest($uri));
     $response = new Response();
     $response->setContent(implode(gzfile(__DIR__ . '/fixtures/archive.org-' . $year . '.html.gz')));
     $adapter = new TestAdapter();
     $adapter->setResponse($response);
     $client->setAdapter($adapter);
     return $provider->generateSnapshots($client->send(), $uri);
 }

作者:robertodormepoc    项目:zf   
/**
  * Set up the test case
  *
  * @return void
  */
 public function setUp()
 {
     $this->rackspace = new RackspaceFiles('foo', 'bar');
     $this->httpClientAdapterTest = new HttpTest();
     $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()));
 }

作者:nathanp    项目:ZendService_IBMObjectStorag   
public function setUp()
 {
     $this->options = array('url' => TESTS_ZENDSERVICE_OPENSTACK_URL, 'user' => TESTS_ZENDSERVICE_OPENSTACK_USER, 'password' => TESTS_ZENDSERVICE_OPENSTACK_PASSWORD, 'key' => TESTS_ZENDSERVICE_OPENSTACK_APIKEY);
     $http = new HttpClient();
     if (!TESTS_ZENDSERVICE_OPENSTACK_ONLINE && $this->responseExists($this->getName())) {
         $httpAdapter = new HttpTest();
         $httpAdapter->setResponse($this->loadResponse('../../Identity/_files/testAuthenticate'));
         $http->setAdapter($httpAdapter);
     }
     $this->compute = new Compute($this->options, $http);
     if (!TESTS_ZENDSERVICE_OPENSTACK_ONLINE && $this->responseExists($this->getName())) {
         $this->compute->getHttpClient()->getAdapter()->setResponse($this->loadResponse($this->getName()));
     }
 }

作者:nathanp    项目:ZendService_IBMObjectStorag   
public function setUp()
 {
     $this->options = array('url' => 'http://identity.api.openstack.com', 'user' => 'test', 'password' => 'test', 'key' => '123cfe4c13a3e321d609c402cd43f936a');
     $this->backupId = '2ef47aee-8844-490c-804d-2a8efe561c65';
     $this->volumeId = '795114e8-7489-40be-a978-83797f2c1dd3';
     if (!$this->responseExists($this->getName())) {
         $this->markTestSkipped('I cannot find the ' . $this->getName() . '.response file');
     }
     $httpAdapter = new HttpTest();
     $httpAdapter->setResponse($this->loadResponse('../../../Identity/_files/testAuthenticate'));
     $http = new HttpClient();
     $http->setAdapter($httpAdapter);
     $this->backup = new Backup($this->options, $http);
     $this->backup->getHttpClient()->getAdapter()->setResponse($this->loadResponse($this->getName()));
 }

作者:guenter    项目:vufin   
public function testResetAttribute()
 {
     $rawHttpResponse = "HTTP/1.1 200 OK\r\n" . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Server: hi\r\n" . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n" . "Status: 200 OK\r\n" . "Content-type: application/xml; charset=utf-8\r\n" . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "<ResetImageAttributeResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n" . "  <return>true</return>\r\n" . "</ResetImageAttributeResponse>\r\n";
     $this->httpClientTestAdapter->setResponse($rawHttpResponse);
     $return = $this->ec2ImageInstance->resetAttribute('ami-61a54008', 'launchPermission');
     $this->assertTrue($return);
 }

作者:navassouz    项目:zf   
/**
  * 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__));
     $this->setExpectedException('Zend\\Service\\Flickr\\Exception\\RuntimeException', 'Group not found');
     $this->flickr->groupPoolGetPhotos('2e38a9d9425d7e2c9d0788455e9ccc61');
 }


问题


面经


文章

微信
公众号

扫码关注公众号