示例#1
0
 public function testSend()
 {
     $container = [];
     $history = Middleware::history($container);
     $mockResponseData = json_encode(['ok' => true, 'foo' => 'bar']);
     $mock = new MockHandler([new Response(200, [], $mockResponseData)]);
     $stack = HandlerStack::create($mock);
     $stack->push($history);
     $client = new Client(['handler' => $stack]);
     $mockPayload = new MockPayload();
     $foo = 'who:(search+query+OR+other+search+query)';
     $mockPayload->setFoo($foo);
     $apiClient = new ApiClient(self::API_KEY, $client);
     $payloadResponse = $apiClient->send($mockPayload);
     $transaction = array_pop($container);
     // Assert response is of type MockPayloadResponse
     $this->assertInstanceOf('Colada\\Europeana\\Tests\\Test\\Payload\\MockPayloadResponse', $payloadResponse);
     // Assert if the responses match up.
     $transaction['response']->getBody();
     $this->assertEquals($mockResponseData, $transaction['response']->getBody());
     // Assert if the URL is unfuddled.
     $expectedRequestUri = sprintf('http://europeana.eu/api/v2/mock.json?foo=%s&wskey=%s', $foo, self::API_KEY);
     $requestUri = $transaction['request']->getUri();
     $this->assertEquals($expectedRequestUri, $requestUri);
 }
 /**
  * @covers ::send
  * @covers ::buildRequest
  * @covers ::getGzippedBody
  * @covers ::getAuthorization
  */
 public function testSend()
 {
     $container = array();
     $history = Middleware::history($container);
     $mockHandler = new MockHandler(array(new Response(200, array(), 'Everything OK')));
     $stack = HandlerStack::create($mockHandler);
     $stack->push($history);
     // $stack->push($mockHandler);
     $http = new GuzzleAdapter(new GuzzleClient(array('handler' => $stack)));
     $client = new Client('aaaaa', 'bbbbb', $http);
     $message = new Message('http://www.example.com/', $client);
     $message->set('foo', 'bar');
     // Call send() and ensure the right response was returned (which we set up above)
     $response = $message->send();
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('Everything OK', $response->getBody());
     // Ensure the request has everything that should be there
     $this->assertCount(1, $container);
     $request = $container[0]['request'];
     $this->assertEquals('POST', $request->getMethod());
     $this->assertEquals('http://www.example.com/', (string) $request->getUri());
     $this->assertEquals('gzip', $request->getHeaderLine('Content-Encoding'));
     $this->assertEquals('application/json', $request->getHeaderLine('Content-Type'));
     $this->assertEquals('2Isi0VhuV8oniANJzAZVBEZ3DSAKmP0hQrVh3jbUNaQ=', $request->getHeaderLine('Authorization'));
     $this->assertEquals('H4sIAAAAAAAAA6tWSsvPV7JSSkosUqoFAO/1K/4NAAAA', base64_encode((string) $request->getBody()));
 }
示例#3
0
 public function __construct($email, $password, SessionStorageInterface $sessionStorage = null, $env = 'prod', $debug = false)
 {
     if (!in_array($env, ['test', 'prod'], true)) {
         throw new InvalidArgumentException("Environment must be one of: prod, test");
     }
     if (null === $sessionStorage) {
         if (php_sapi_name() == "cli") {
             $sessionStorage = new MemorySessionStorage();
         } else {
             $sessionStorage = new NativeSessionStorage();
         }
     }
     $this->sessionStorage = $sessionStorage;
     $this->email = $email;
     $this->password = $password;
     $params = ['base_uri' => $this->{$env . 'Url'}];
     if ($debug) {
         $this->transactionHistory = [];
         $history = Middleware::history($this->transactionHistory);
         $stack = HandlerStack::create();
         $stack->push($history);
         $params['handler'] = $stack;
     }
     $this->client = new Client($params);
 }
 public function testBasicClient()
 {
     $mock = new MockHandler([new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}")]);
     $container = [];
     $history = Middleware::history($container);
     $stack = HandlerStack::create($mock);
     $stack->push($history);
     $http_client = new Client(['handler' => $stack]);
     $client = new BuuyersClient('u', 'p');
     $client->setClient($http_client);
     $client->companies->getCompany(1);
     foreach ($container as $transaction) {
         $basic = $transaction['request']->getHeaders()['Authorization'][0];
         $this->assertTrue($basic == "Basic dTpw");
         $method = $transaction['request']->getMethod();
         $this->assertEquals($method, 'GET');
         //> GET
         if ($transaction['response']) {
             $statusCode = $transaction['response']->getStatusCode();
             $this->assertEquals(200, $statusCode);
             //> 200, 200
         } elseif ($transaction['error']) {
             echo $transaction['error'];
             //> exception
         }
     }
 }
示例#5
0
 /**
  * Test validation of Cas tickets.
  *
  * @covers ::__construct
  * @covers ::validateTicket
  * @covers ::validateVersion1
  * @covers ::validateVersion2
  * @covers ::verifyProxyChain
  * @covers ::parseAllowedProxyChains
  * @covers ::parseServerProxyChain
  *
  * @dataProvider validateTicketDataProvider
  */
 public function testValidateTicket($version, $ticket, $username, $response, $is_proxy, $can_be_proxied, $proxy_chains, $ssl_verification)
 {
     $mock = new MockHandler([new Response(200, array(), $response)]);
     $handler = HandlerStack::create($mock);
     $container = [];
     $history = Middleware::history($container);
     $handler->push($history);
     $httpClient = new Client(['handler' => $handler]);
     $casHelper = $this->getMockBuilder('\\Drupal\\cas\\Service\\CasHelper')->disableOriginalConstructor()->getMock();
     $casValidator = new CasValidator($httpClient, $casHelper);
     $casHelper->expects($this->any())->method('getCasProtocolVersion')->will($this->returnValue($version));
     $casHelper->expects($this->once())->method('getSslVerificationMethod')->willReturn($ssl_verification);
     $casHelper->expects($this->any())->method('getCertificateAuthorityPem')->will($this->returnValue('foo'));
     $casHelper->expects($this->any())->method('isProxy')->will($this->returnValue($is_proxy));
     $casHelper->expects($this->any())->method('canBeProxied')->will($this->returnValue($can_be_proxied));
     $casHelper->expects($this->any())->method('getProxyChains')->will($this->returnValue($proxy_chains));
     $property_bag = $casValidator->validateTicket($version, $ticket, array());
     // Test that we sent the correct ssl option to the http client.
     foreach ($container as $transaction) {
         switch ($ssl_verification) {
             case CasHelper::CA_CUSTOM:
                 $this->assertEquals('foo', $transaction['options']['verify']);
                 break;
             case CasHelper::CA_NONE:
                 $this->assertEquals(FALSE, $transaction['options']['verify']);
                 break;
             default:
                 $this->assertEquals(TRUE, $transaction['options']['verify']);
         }
     }
     $this->assertEquals($username, $property_bag->getUsername());
 }
示例#6
0
 public function testSend()
 {
     $self = $this;
     $mockRequestData = ['foo' => 'bar', 'token' => self::TOKEN];
     $mockResponseData = ['ok' => true, 'foo' => 'bar'];
     $handler = HandlerStack::create(new MockHandler([new Response(200, [], json_encode($mockResponseData))]));
     $historyContainer = [];
     $history = Middleware::history($historyContainer);
     $handler->push($history);
     $apiClient = new ApiClient(self::TOKEN, new Client(['handler' => $handler]));
     $apiClient->addRequestListener(function (RequestEvent $event) use(&$eventsDispatched, $mockRequestData, $self) {
         $eventsDispatched[ApiClient::EVENT_REQUEST] = true;
         $self->assertEquals($mockRequestData, $event->getRawPayload());
     });
     $apiClient->addResponseListener(function (ResponseEvent $event) use(&$eventsDispatched, $mockResponseData, $self) {
         $eventsDispatched[ApiClient::EVENT_RESPONSE] = true;
         $self->assertEquals($mockResponseData, $event->getRawPayloadResponse());
     });
     $mockPayload = new MockPayload();
     $mockPayload->setFoo('bar');
     $apiClient->send($mockPayload);
     $transaction = $historyContainer[0];
     $requestUrl = (string) $transaction['request']->getUri();
     $requestContentType = $transaction['request']->getHeader('content-type')[0];
     parse_str($transaction['request']->getBody(), $requestBody);
     $responseBody = json_decode($transaction['response']->getBody(), true);
     $this->assertEquals(ApiClient::API_BASE_URL . 'mock', $requestUrl);
     $this->assertEquals('application/x-www-form-urlencoded', $requestContentType);
     $this->assertEquals($mockRequestData, $requestBody);
     $this->assertEquals($mockResponseData, $responseBody);
     $this->assertArrayHasKey(ApiClient::EVENT_REQUEST, $eventsDispatched);
     $this->assertArrayHasKey(ApiClient::EVENT_RESPONSE, $eventsDispatched);
 }
示例#7
0
 /**
  * Get the client for making calls
  *
  * @return Client
  */
 public function getHttpClient()
 {
     if ($this->client == null) {
         $handler = HandlerStack::create();
         if ($this->mode == 'record') {
             $history = Middleware::history($this->callList);
             $handler->push($history);
         } elseif ($this->mode == 'playback') {
             $recordings = $this->getRecordings();
             $playList = $recordings;
             $mockedResponses = [];
             foreach ($playList as $item) {
                 $mockedResponses[] = new Response($item['statusCode'], $item['headers'], $item['body']);
             }
             $mockHandler = new MockHandler($mockedResponses);
             $handler = HandlerStack::create($mockHandler);
         }
         $this->client = new Client(['handler' => $handler]);
         if (!$this->shutdownRegistered) {
             register_shutdown_function(array($this, 'endRecord'));
             $this->shutdownRegistered = true;
         }
     }
     return $this->client;
 }
 public function testDetailArray()
 {
     $mock = new MockHandler([new Response(200, ['Content-Type' => 'application/json'], '{
                 "id": "main",
                 "authorizedFor": "Myself",
                 "creator": {
                     "id": "1234",
                     "description": "*****@*****.**"
                 },
                 "created": "2016-01-31 00:13:30",
                 "#data": "KBC::ComponentProjectEncrypted==F2LdyHQB45lJHtf",
                 "oauthVersion": "2.0",
                 "appKey": "1234",
                 "#appSecret": "KBC::ComponentEncrypted==/5fEM59+3+59+5+"
             }')]);
     // Add the history middleware to the handler stack.
     $container = [];
     $history = Middleware::history($container);
     $stack = HandlerStack::create($mock);
     $stack->push($history);
     $cred = new Credentials('some-token', ['handler' => $stack, 'url' => 'https://syrup.keboola.com/oauth-v2/']);
     $cred->enableReturnArrays(true);
     $result = $cred->getDetail('wr-dropbox', 'credentials-id');
     $this->assertInternalType('array', $result);
     $this->assertCount(8, $result);
     $this->assertArrayHasKey('#data', $result);
     $this->assertArrayHasKey('#appSecret', $result);
     /** @var Request $request */
     $request = $container[0]['request'];
     $this->assertEquals("https://syrup.keboola.com/oauth-v2/credentials/wr-dropbox/credentials-id", $request->getUri()->__toString());
     $this->assertEquals("GET", $request->getMethod());
     $this->assertEquals("some-token", $request->getHeader("x-storageapi-token")[0]);
 }
 /**
  * Get Guzzle with mock response and request history stored in container
  *
  * @param array $container
  * @param Response[] $responses
  * @return Client
  */
 public function getMockHttpClientWithHistoryAndResponses(&$container, $responses)
 {
     $mock = new MockHandler($responses);
     $stack = HandlerStack::create($mock);
     $history = Middleware::history($container);
     $stack->push($history);
     return new Client(['handler' => $stack]);
 }
示例#10
0
 /**
  * @param null|string $response
  * @return GuzzleClient
  * @see ClientTest::getGuzzle()
  * @link https://github.com/FriendsOfPHP/Goutte/blob/master/Goutte/Tests/ClientTest.php
  */
 protected function getGuzzle($response)
 {
     $handlerStack = HandlerStack::create(new MockHandler([new GuzzleResponse(200, [], $response)]));
     $history = [];
     $handlerStack->push(Middleware::history($history));
     $guzzle = new GuzzleClient(['redirect.disable' => true, 'base_uri' => '', 'handler' => $handlerStack]);
     return $guzzle;
 }
示例#11
0
 public static function buildMockedClient(array &$container, array $responses)
 {
     $history = Middleware::history($container);
     $mock = new MockHandler($responses);
     $handler = HandlerStack::create($mock);
     $handler->push($history);
     return new Client(['handler' => $handler]);
 }
 public function setUp()
 {
     $this->context = new Context(['keys' => ['pda' => 'secret'], 'algorithm' => 'hmac-sha256', 'headers' => ['(request-target)', 'date']]);
     $stack = new HandlerStack();
     $stack->setHandler(new MockHandler([new Response(200, ['Content-Length' => 0])]));
     $stack->push(GuzzleHttpSignatures::middlewareFromContext($this->context));
     $stack->push(Middleware::history($this->history));
     $this->client = new Client(['handler' => $stack]);
 }
 public static function setUpBeforeClass()
 {
     $mock = new MockHandler([new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CityResponse>    <ResultCount>618</ResultCount>    <Cities>        <City>            <RcAbbreviation>PINEHURST</RcAbbreviation>            <Name>ABERDEEN</Name>        </City>        <City>            <RcAbbreviation>JULIAN</RcAbbreviation>            <Name>ADVANCE</Name>        </City>    </Cities></CityResponse>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><RateCenters>    <ResultCount>652</ResultCount>    <RateCenters>        <RateCenter>            <Abbreviation>AGOURA</Abbreviation>            <Name>AGOURA</Name>        </RateCenter>        <RateCenter>            <Abbreviation>ALAMITOS</Abbreviation>            <Name>ALAMITOS</Name>        </RateCenter>    </RateCenters></RateCenters>")]);
     self::$container = [];
     $history = Middleware::history(self::$container);
     $handler = HandlerStack::create($mock);
     $handler->push($history);
     self::$client = new Iris\Client("test", "test", array('url' => 'https://api.test.inetwork.com/v1.0', 'handler' => $handler));
 }
 protected function setUp()
 {
     $mock = new MockHandler([new Response(200, ["X-Foo" => "Bar"], "It worked!")]);
     $stack = HandlerStack::create($mock);
     $history = Middleware::history($this->container);
     $stack->push($history);
     $client = new Client(["handler" => $stack]);
     $this->object = new GuzzleTransport($client);
 }
 /**
  * @before
  */
 public function initClient()
 {
     $this->requests = [];
     $stack = HandlerStack::create();
     $stack->push(Middleware::history($this->requests));
     $this->client = new Client(['handler' => $stack]);
     $this->api = new Mailchimp($this->client, getenv('MAILCHIMP_API_KEY'));
     $this->faker = Factory::create();
 }
 private function getTestClient()
 {
     $container = [];
     $history = Middleware::history($container);
     $stack = HandlerStack::create();
     // Add the history middleware to the handler stack.
     $stack->push($history);
     return new Client(['handler' => $stack]);
 }
示例#17
0
 /**
  * Creates a HTTP client.
  *
  * @param Response|Response[] $responses
  * @param array               $history
  *
  * @return HttpClient
  */
 private function createHttpClient($responses = array(), array &$history = array())
 {
     if (!is_array($responses)) {
         $responses = array($responses);
     }
     $stack = HandlerStack::create(new MockHandler($responses));
     $stack->push(Middleware::history($history));
     return new HttpClient(array('handler' => $stack));
 }
示例#18
0
 public function __construct()
 {
     $history = Middleware::history($this->container);
     $this->mock = new MockHandler();
     $stack = HandlerStack::create($this->mock);
     // Add the history middleware to the handler stack.
     $stack->push($history);
     parent::__construct(['handler' => $stack]);
 }
示例#19
0
 public function __construct()
 {
     $this->container = [];
     $mock = new MockHandler([new Response(200, [])]);
     $history = Middleware::history($this->container);
     $stack = HandlerStack::create($mock);
     $stack->push($history);
     $this->client = new Client(['handler' => $stack]);
 }
 public static function setUpBeforeClass()
 {
     $mock = new MockHandler([new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <CoveredRateCenters><TotalCount>18</TotalCount> <Links><first>Link=&lt;https://api.inetwork.com:443/v1.0/coveredRateCenters?npa=310&amp;size=10&amp;e mbed=Cities&amp;embed=ZipCodes&amp;embed=NpaNxxX&amp;page=1&gt;;rel=\"first\";</first><next>Link=&lt;https://api.inetwork.com:443/v1.0/coveredRateCenters?npa=310&amp;size=10&amp;e mbed=Cities&amp;embed=ZipCodes&amp;embed=NpaNxxX&amp; page=5&gt;;rel=\"next\";</next></Links> <CoveredRateCenter><Name>AVALON</Name><Abbreviation>AVALON</Abbreviation> <State>CA</State><Lata>730</Lata> <AvailableNumberCount>1</AvailableNumberCount> <ZipCodes><ZipCode>90731</ZipCode> </ZipCodes><Cities><City>SAN PEDRO</City> </Cities><Tiers> <Tier>0</Tier></Tiers> <NpaNxxXs><NpaNxxX>3105100</NpaNxxX> <NpaNxxX>3105101</NpaNxxX> <NpaNxxX>3109498</NpaNxxX> <NpaNxxX>3109499</NpaNxxX> <NpaNxxX>4242260</NpaNxxX></NpaNxxXs><Id>1</Id> </CoveredRateCenter> <CoveredRateCenter><Name>BEVERLY HILLS</Name> <Abbreviation>BEVERLYHLS</Abbreviation> <State>CA</State><Lata>730</Lata><AvailableNumberCount>25</AvailableNumberCount> <ZipCodes><ZipCode>90013</ZipCode> <ZipCode>90014</ZipCode> <ZipCode>90015</ZipCode><ZipCode>91504</ZipCode><ZipCode>91505</ZipCode> </ZipCodes><Cities><City>BEVERLY HILLS</City> <City>BURBANK</City> <City>GARDENA</City> <City>LOS ANGELES</City> <City>SHERMAN OAKS</City> <City>SUN VALLEY</City> <City>VAN NUYS</City></Cities> <Tiers><Tier>0</Tier> </Tiers><NpaNxxXs> <NpaNxxX>3102010</NpaNxxX><NpaNxxX>3102011</NpaNxxX><NpaNxxX>3102012</NpaNxxX><NpaNxxX>4247777</NpaNxxX> <NpaNxxX>4247778</NpaNxxX> <NpaNxxX>4247779</NpaNxxX></NpaNxxXs><Id>3</Id> </CoveredRateCenter></CoveredRateCenters>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <CoveredRateCenters><CoveredRateCenter><Name>AVALON</Name><Abbreviation>AVALON</Abbreviation> <State>CA</State><Lata>730</Lata> <AvailableNumberCount>1</AvailableNumberCount> <ZipCodes><ZipCode>90731</ZipCode> </ZipCodes><Cities><City>SAN PEDRO</City> </Cities><Tiers> <Tier>0</Tier></Tiers> <NpaNxxXs><NpaNxxX>3105100</NpaNxxX> <NpaNxxX>3105101</NpaNxxX> <NpaNxxX>3109498</NpaNxxX> <NpaNxxX>3109499</NpaNxxX> <NpaNxxX>4242260</NpaNxxX></NpaNxxXs><Id>1</Id> </CoveredRateCenter></CoveredRateCenters>")]);
     self::$container = [];
     $history = Middleware::history(self::$container);
     $handler = HandlerStack::create($mock);
     $handler->push($history);
     $client = new Iris\Client("test", "test", array('url' => 'https://api.test.inetwork.com/v1.0', 'handler' => $handler));
     self::$rcs = new Iris\CoveredRateCenters($client);
 }
示例#21
0
 /**
  * Create a client with a mock handler and history middleware
  * 
  * @param array $responses
  * @param array $container  History container
  * @param array $config     Client configuration
  * @return Phake_IMock|Client
  */
 protected function getClientWithMockHandler(array $responses = [], array &$container = [], array $config = [])
 {
     $client = new Client('http://www.example.com', $config);
     $handlerStack = $client->getConfig('handler');
     $mock = new MockHandler($responses);
     $handlerStack->setHandler($mock);
     $history = Middleware::history($container);
     $handlerStack->push($history, 'history');
     return $client;
 }
示例#22
0
 /**
  * @return GW2Api
  */
 protected function api()
 {
     if (!isset($this->api)) {
         $this->mock = new MockHandler();
         $stack = HandlerStack::create($this->mock);
         $stack->push(Middleware::history($this->history));
         $this->api = new GW2Api(['handler' => $stack]);
     }
     return $this->api;
 }
 public static function setUpBeforeClass()
 {
     $mock = new MockHandler([new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Notes>    <Note>        <Id>11425</Id>        <UserId>byo_dev</UserId>        <Description>Test Note</Description>        <LastDateModifier>2015-06-18T04:19:59.000Z</LastDateModifier>    </Note></Notes>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Notes>    <Note>        <Id>11425</Id>        <UserId>byo_dev</UserId>        <Description>Test Note</Description>        <LastDateModifier>2015-06-18T04:19:59.000Z</LastDateModifier>    </Note></Notes>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Notes>    <Note>        <Id>11425</Id>        <UserId>byo_dev</UserId>        <Description>Test Note</Description>        <LastDateModifier>2015-06-18T04:19:59.000Z</LastDateModifier>    </Note></Notes>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Notes>    <Note>        <Id>11425</Id>        <UserId>byo_dev</UserId>        <Description>Test Note</Description>        <LastDateModifier>2015-06-18T04:19:59.000Z</LastDateModifier>    </Note></Notes>")]);
     self::$container = [];
     $history = Middleware::history(self::$container);
     $handler = HandlerStack::create($mock);
     $handler->push($history);
     $client = new Iris\Client("test", "test", array('url' => 'https://api.test.inetwork.com/v1.0', 'handler' => $handler));
     self::$account = new Iris\Account(9500249, $client);
 }
 public static function setUpBeforeClass()
 {
     $mock = new MockHandler([new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ResponseSelectWrapper>    <ListOrderIdUserIdDate>        <TotalCount>2</TotalCount>        <Links>            <first>Link=&lt;https://api.test.inetwork.com:443/v1.0/accounts/9500249/orders?page=1&amp;size=300&gt;;rel=\"first\";</first>        </Links>        <OrderIdUserIdDate>            <CountOfTNs>0</CountOfTNs>            <CustomerOrderId>123456789</CustomerOrderId>            <userId>byo_dev</userId>            <lastModifiedDate>2015-06-13T16:14:46.017Z</lastModifiedDate>            <OrderDate>2015-06-13T16:14:45.956Z</OrderDate>            <OrderType>new_number</OrderType>            <orderId>016c1aef-a873-4a90-8374-60771cba9452</orderId>            <OrderStatus>FAILED</OrderStatus>        </OrderIdUserIdDate>        <OrderIdUserIdDate>            <CountOfTNs>0</CountOfTNs>            <CustomerOrderId>123456789</CustomerOrderId>            <userId>byo_dev</userId>            <lastModifiedDate>2015-06-13T16:32:04.216Z</lastModifiedDate>            <OrderDate>2015-06-13T16:32:04.181Z</OrderDate>            <OrderType>new_number</OrderType>            <orderId>77659f47-d527-42ad-bf72-34b6841016ac</orderId>            <OrderStatus>FAILED</OrderStatus>        </OrderIdUserIdDate>    </ListOrderIdUserIdDate></ResponseSelectWrapper>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ResponseSelectWrapper>    <ListOrderIdUserIdDate>        <TotalCount>1</TotalCount>        <Links>            <first>Link=&lt;https://api.test.inetwork.com:443/v1.0/accounts/9500249/orders?page=1&amp;size=300&gt;;rel=\"first\";</first>        </Links>        <OrderIdUserIdDate>            <CountOfTNs>0</CountOfTNs>            <CustomerOrderId>123456789</CustomerOrderId>            <userId>byo_dev</userId>            <lastModifiedDate>2015-06-13T16:14:46.017Z</lastModifiedDate>            <OrderDate>2015-06-13T16:14:45.956Z</OrderDate>            <OrderType>new_number</OrderType>            <orderId>016c1aef-a873-4a90-8374-60771cba9452</orderId>            <OrderStatus>FAILED</OrderStatus>        </OrderIdUserIdDate>    </ListOrderIdUserIdDate></ResponseSelectWrapper>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ResponseSelectWrapper>    <ListOrderIdUserIdDate>        <TotalCount>0</TotalCount>        <Links>            <first>Link=&lt;https://api.test.inetwork.com:443/v1.0/accounts/9500249/orders?page=1&amp;size=300&gt;;rel=\"first\";</first>        </Links>    </ListOrderIdUserIdDate></ResponseSelectWrapper>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><OrderResponse>    <Order>        <CustomerOrderId>123456789</CustomerOrderId>        <Name>Available Telephone Number order</Name>        <OrderCreateDate>2015-06-20T10:54:08.042Z</OrderCreateDate>        <BackOrderRequested>false</BackOrderRequested>        <id>f30a31a1-1de4-4939-b094-4521bbe5c8df</id>        <ExistingTelephoneNumberOrderType>            <TelephoneNumberList>                <TelephoneNumber>9193752369</TelephoneNumber>                <TelephoneNumber>9193752720</TelephoneNumber>                <TelephoneNumber>9193752648</TelephoneNumber>            </TelephoneNumberList>        </ExistingTelephoneNumberOrderType>        <PartialAllowed>true</PartialAllowed>        <SiteId>2297</SiteId>    </Order>    <OrderStatus>RECEIVED</OrderStatus></OrderResponse>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><OrderResponse>    <CompletedQuantity>0</CompletedQuantity>    <CreatedByUser>byo_dev</CreatedByUser>    <ErrorList>        <Error>            <Code>5005</Code>            <Description>The telephone number is unavailable for ordering</Description>            <TelephoneNumber>9193752369</TelephoneNumber>        </Error>        <Error>            <Code>5005</Code>            <Description>The telephone number is unavailable for ordering</Description>            <TelephoneNumber>9193752648</TelephoneNumber>        </Error>        <Error>            <Code>5005</Code>            <Description>The telephone number is unavailable for ordering</Description>            <TelephoneNumber>9193752720</TelephoneNumber>        </Error>    </ErrorList>    <FailedNumbers>        <FullNumber>9193752369</FullNumber>        <FullNumber>9193752648</FullNumber>        <FullNumber>9193752720</FullNumber>    </FailedNumbers>    <LastModifiedDate>2015-06-20T10:54:08.094Z</LastModifiedDate>    <OrderCompleteDate>2015-06-20T10:54:08.094Z</OrderCompleteDate>    <Order>        <CustomerOrderId>123456789</CustomerOrderId>        <Name>Available Telephone Number order</Name>        <OrderCreateDate>2015-06-20T10:54:08.042Z</OrderCreateDate>        <PeerId>500709</PeerId>        <BackOrderRequested>false</BackOrderRequested>        <ExistingTelephoneNumberOrderType/>        <PartialAllowed>true</PartialAllowed>        <SiteId>2297</SiteId>    </Order>    <OrderStatus>FAILED</OrderStatus>    <FailedQuantity>3</FailedQuantity></OrderResponse>"), new Response(200, [], ""), new Response(200, [], ""), new Response(200, [], ""), new Response(200, [], ""), new Response(200, [], "")]);
     self::$container = [];
     $history = Middleware::history(self::$container);
     $handler = HandlerStack::create($mock);
     $handler->push($history);
     $client = new Iris\Client("test", "test", array('url' => 'https://api.test.inetwork.com/v1.0', 'handler' => $handler));
     self::$account = new Iris\Account(9500249, $client);
 }
 public static function setUpBeforeClass()
 {
     $mock = new MockHandler([new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <LineOptionOrderResponse><LineOptions> <CompletedNumbers><TelephoneNumber>2013223685</TelephoneNumber> </CompletedNumbers><Errors><Error><TelephoneNumber>5209072452</TelephoneNumber> <ErrorCode>5071</ErrorCode><Description>Telephone number is not available on the system.</Description></Error> <Error><TelephoneNumber>5209072451</TelephoneNumber> <ErrorCode>13518</ErrorCode><Description>CNAM for telephone number is applied at the Location level and it is notapplicable at the TN level.</Description> </Error></Errors> </LineOptions></LineOptionOrderResponse>"), new Response(200, [], "<?xml version=\"1.0\"?> <SearchResult><ResultCount>1</ResultCount> <TelephoneNumberDetailList><TelephoneNumberDetail> <City>KNIGHTDALE</City> <LATA>426</LATA> <RateCenter>KNIGHTDALE</RateCenter> <State>NC</State> <FullNumber>9192956932</FullNumber> <Tier>0</Tier><VendorId>49</VendorId> <VendorName>Bandwidth CLEC</VendorName></TelephoneNumberDetail> </TelephoneNumberDetailList></SearchResult>"), new Response(200, [], "<?xml version=\"1.0\"?> <SearchResult><ResultCount>2</ResultCount> <TelephoneNumberDetailList><TelephoneNumberDetail> <City>KNIGHTDALE</City> <LATA>426</LATA> <RateCenter>KNIGHTDALE</RateCenter> <State>NC</State> <FullNumber>9192956932</FullNumber> <Tier>0</Tier><VendorId>49</VendorId> <VendorName>Bandwidth CLEC</VendorName></TelephoneNumberDetail><TelephoneNumberDetail> <City>KNIGHTDALE</City> <LATA>426</LATA> <RateCenter>KNIGHTDALE</RateCenter> <State>NC</State> <FullNumber>9192956932</FullNumber> <Tier>0</Tier><VendorId>49</VendorId> <VendorName>Bandwidth CLEC</VendorName></TelephoneNumberDetail> </TelephoneNumberDetailList></SearchResult>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?> <SearchResult><ResultCount>5</ResultCount> <TelephoneNumberList><TelephoneNumber>9194390154</TelephoneNumber> <TelephoneNumber>9194390158</TelephoneNumber> <TelephoneNumber>9194390176</TelephoneNumber> <TelephoneNumber>9194390179</TelephoneNumber> <TelephoneNumber>9194390185</TelephoneNumber></TelephoneNumberList> </SearchResult>"), new Response(400, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <SearchResult><Error> <Code>4000</Code> <Description>The area code of telephone numbers can not end with 11. </Description></Error><ResultCount>0</ResultCount> </SearchResult>"), new Response(201, ['Location' => 'https://api.test.inetwork.com:443/v1.0/accounts/9500249/tnsreservation/2489']), new Response(200, [], "<?xml version=\"1.0\"?><ReservationResponse><Reservation> <ReservationId>0099ff73-da96-4303-8a0a-00ff316c07aa</ReservationId> <AccountId>14</AccountId> <ReservationExpires>0</ReservationExpires> <ReservedTn>2512027430</ReservedTn></Reservation> </ReservationResponse>"), new Response(200, []), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\"?><NumberPortabilityResponse>   <SupportedRateCenters />   <UnsupportedRateCenters>      <RateCenterGroup>         <RateCenter>BALTIMORE</RateCenter>         <City>BALTIMORE</City>         <State>MD</State>         <LATA>238</LATA>         <TnList>            <Tn>4109255199</Tn>            <Tn>4104685864</Tn>         </TnList>      </RateCenterGroup>      <RateCenterGroup>         <RateCenter>SPARKSGLNC</RateCenter>         <City>SPARKS GLENCOE</City>         <State>MD</State>         <LATA>238</LATA>         <TnList>            <Tn>4103431313</Tn>            <Tn>4103431561</Tn>         </TnList>      </RateCenterGroup>   </UnsupportedRateCenters>   <PartnerSupportedRateCenters>      <!-- Only available for fullCheck=offnetportability -->      <RateCenterGroup>         <RateCenter>FT COLLINS</RateCenter>         <City>FORT COLLINS</City>         <State>CO</State>         <LATA>656</LATA>         <Tiers>            <Tier>1</Tier>         </Tiers>         <TnList>            <Tn>4109235436</Tn>         </TnList>      </RateCenterGroup>   </PartnerSupportedRateCenters>   <SupportedLosingCarriers>      <LosingCarrierTnList>         <LosingCarrierSPID>9998</LosingCarrierSPID>         <LosingCarrierName>Test Losing Carrier L3</LosingCarrierName>         <LosingCarrierIsWireless>false</LosingCarrierIsWireless>         <LosingCarrierAccountNumberRequired>false</LosingCarrierAccountNumberRequired>         <LosingCarrierMinimumPortingInterval>5</LosingCarrierMinimumPortingInterval>         <TnList>            <Tn>4109255199</Tn>            <Tn>4104685864</Tn>            <Tn>4103431313</Tn>            <Tn>4103431561</Tn>         </TnList>      </LosingCarrierTnList>   </SupportedLosingCarriers>   <UnsupportedLosingCarriers /></NumberPortabilityResponse>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><SearchResultForAvailableNpaNxx>    <AvailableNpaNxxList>        <AvailableNpaNxx>            <City>COMPTON:COMPTON DA</City>            <Npa>424</Npa>            <Nxx>242</Nxx>            <Quantity>7</Quantity>            <State>CA</State>        </AvailableNpaNxx>        <AvailableNpaNxx>            <City>COMPTON:GARDENA DA</City>            <Npa>424</Npa>            <Nxx>246</Nxx>            <Quantity>5</Quantity>            <State>CA</State>        </AvailableNpaNxx>    </AvailableNpaNxxList></SearchResultForAvailableNpaNxx>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><TNs>    <TotalCount>4</TotalCount>    <Links>        <first>Link=&lt;https://api.test.inetwork.com:443/v1.0/accounts/9500249/inserviceNumbers?size=500&amp;page=1&gt;;rel=\"first\";</first>    </Links>    <TelephoneNumbers>        <Count>4</Count>        <TelephoneNumber>8183386247</TelephoneNumber>        <TelephoneNumber>8183386249</TelephoneNumber>        <TelephoneNumber>8183386251</TelephoneNumber>        <TelephoneNumber>8183386252</TelephoneNumber>    </TelephoneNumbers></TNs>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Quantity><Count>4</Count></Quantity>"), new Response(200, [], "<?xml version=\"1.0\"?><TNs><TotalCount>4</TotalCount><Links><first></first></Links><TelephoneNumbers><Count>2</Count><TelephoneNumber>4158714245</TelephoneNumber><TelephoneNumber>4352154439</TelephoneNumber></TelephoneNumbers></TNs>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Quantity><Count>4</Count></Quantity>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><BdrCreationResponse><Info>Your BDR archive is currently being constructed</Info> </BdrCreationResponse>")]);
     self::$container = [];
     $history = Middleware::history(self::$container);
     $handler = HandlerStack::create($mock);
     $handler->push($history);
     $client = new Iris\Client("test", "test", array('url' => 'https://api.test.inetwork.com/v1.0', 'handler' => $handler));
     self::$account = new Iris\Account(9500249, $client);
 }
示例#26
0
 public function setUp()
 {
     $this->requestContainer = [];
     $history = Middleware::history($this->requestContainer);
     $mock = new MockHandler([new Response(200, [])]);
     $this->handler = HandlerStack::create($mock);
     $this->handler->push($history);
     $client = new Client(['handler' => $this->handler, 'base_uri' => 'http://WhoCares/']);
     $this->newRelicInsights = new Insights($client, 'Mum-Ha');
 }
 public static function setUpBeforeClass()
 {
     $mock = new MockHandler([new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><UsersResponse><Users><User><Username>byo_dev</Username><FirstName>test</FirstName><LastName>test</LastName><EmailAddress>jsommerset@bandwidth.com</EmailAddress><TelephoneNumber>5413637598</TelephoneNumber><Roles><Role><RoleName>ROLE_USER</RoleName><Permissions><Permission><PermissionName>UPDATE</PermissionName></Permission><Permission><PermissionName>VIEW</PermissionName></Permission></Permissions></Role><Role><RoleName>ROLE_BDR</RoleName><Permissions><Permission><PermissionName>UPDATE</PermissionName></Permission><Permission><PermissionName>VIEW</PermissionName></Permission></Permissions></Role><Role><RoleName>ROLE_API_HISTORY</RoleName><Permissions><Permission><PermissionName>UPDATE</PermissionName></Permission><Permission><PermissionName>VIEW</PermissionName></Permission></Permissions></Role><Role><RoleName>ROLE_API_SITE</RoleName><Permissions><Permission><PermissionName>UPDATE</PermissionName></Permission><Permission><PermissionName>VIEW</PermissionName></Permission></Permissions></Role><Role><RoleName>ROLE_API_SEARCH</RoleName><Permissions><Permission><PermissionName>VIEW</PermissionName></Permission></Permissions></Role><Role><RoleName>ROLE_API_ORDERING</RoleName><Permissions><Permission><PermissionName>UPDATE</PermissionName></Permission><Permission><PermissionName>VIEW</PermissionName></Permission></Permissions></Role><Role><RoleName>ROLE_API_PROFILE</RoleName><Permissions><Permission><PermissionName>UPDATE</PermissionName></Permission><Permission><PermissionName>VIEW</PermissionName></Permission></Permissions></Role><Role><RoleName>ROLE_API_LNP</RoleName><Permissions><Permission><PermissionName>UPDATE</PermissionName></Permission><Permission><PermissionName>VIEW</PermissionName></Permission></Permissions></Role><Role><RoleName>ROLE_API_ACCOUNT</RoleName><Permissions><Permission><PermissionName>VIEW</PermissionName></Permission></Permissions></Role><Role><RoleName>ROLE_API_DLDA</RoleName><Permissions><Permission><PermissionName>UPDATE</PermissionName></Permission><Permission><PermissionName>VIEW</PermissionName></Permission></Permissions></Role><Role><RoleName>ROLE_API_CNAMLIDB</RoleName><Permissions><Permission><PermissionName>UPDATE</PermissionName></Permission><Permission><PermissionName>VIEW</PermissionName></Permission></Permissions></Role></Roles></User></Users></UsersResponse>"), new Response(200, [], "")]);
     self::$container = [];
     $history = Middleware::history(self::$container);
     $handler = HandlerStack::create($mock);
     $handler->push($history);
     self::$client = new Iris\Client("test", "test", array('url' => 'https://api.test.inetwork.com/v1.0', 'handler' => $handler));
     self::$account = new \Iris\Account(9500249, self::$client);
 }
示例#28
0
 public function addMockResults(array $results, callable $onFulfilled = null, callable $onRejected = null)
 {
     $mock = new MockHandler($results, $onFulfilled, $onRejected);
     $handler = HandlerStack::create($mock);
     $handler->push(Middleware::history($this->history));
     $container = WpsContainer::getInstance();
     $container->container->add('WpsClient', function () use($handler) {
         return WpsClient::factory(['base_uri' => '/', 'defaults' => ['headers' => ['Content-Type' => 'application/json']], 'handler' => $handler], true);
     });
 }
示例#29
0
 /**
  * Helper to set up Guzzle with mock response queue
  *
  * @return Guzzle
  */
 protected function setupGuzzlePlugin()
 {
     // Set up Guzzle Mock Handler
     $this->mockHandler = new MockHandler();
     // This is a container for the dummy request / responses made to Guzzle
     $history = Middleware::history($this->attemptContainer);
     $stack = HandlerStack::create($this->mockHandler);
     // Add the history middleware to the handler stack.
     $stack->push($history);
     return new Guzzle(["handler" => $stack]);
 }
 public static function setUpBeforeClass()
 {
     $mock = new MockHandler([new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><DisconnectTelephoneNumberOrderResponse> <orderRequest>  <CustomerOrderId>Disconnect1234</CustomerOrderId>  <OrderCreateDate>2015-06-17T18:14:08.683Z</OrderCreateDate>  <id>b902dee1-0585-4258-becd-5c7e51ccf5e1</id>  <DisconnectTelephoneNumberOrderType>   <TelephoneNumberList>    <TelephoneNumber>9192755378</TelephoneNumber>    <TelephoneNumber>9192755703</TelephoneNumber>   </TelephoneNumberList>   <DisconnectMode>normal</DisconnectMode>  </DisconnectTelephoneNumberOrderType> </orderRequest> <OrderStatus>RECEIVED</OrderStatus></DisconnectTelephoneNumberOrderResponse>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ResponseSelectWrapper><ListOrderIdUserIdDate><TotalCount>7</TotalCount><Links><!-- SNIP --></Links><OrderIdUserIdDate><CountOfTNs>1</CountOfTNs><userId>smckinnon</userId><lastModifiedDate>2014-01-10T17-34-15Z</lastModifiedDate><OrderId>6d7da966-e071-4741-b31c-1d8932f4b8da</OrderId><OrderType>disconnect</OrderType><OrderDate>2014-01-10T17-34-15.797Z</OrderDate><OrderStatus>COMPLETE</OrderStatus><TelephoneNumberDetails>    <!-- SNIP --></TelephoneNumberDetails></OrderIdUserIdDate><OrderIdUserIdDate><CountOfTNs>1</CountOfTNs><userId>jbm</userId><lastModifiedDate>2013-12-04T21-59-32Z</lastModifiedDate><OrderId>4ffe9262-1965-4479-a1d5-b8584440667d</OrderId><OrderType>disconnect</OrderType><OrderDate>2013-12-04T21-59-32.243Z</OrderDate><OrderStatus>COMPLETE</OrderStatus><TelephoneNumberDetails><!-- SNIP --></TelephoneNumberDetails></OrderIdUserIdDate></ListOrderIdUserIdDate></ResponseSelectWrapper>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><DisconnectTelephoneNumberOrderResponse>    <ErrorList>        <Error>            <Code>5006</Code>            <Description>Telephone number could not be disconnected since it is not associated with your account</Description>            <TelephoneNumber>9192755703</TelephoneNumber>        </Error>        <Error>            <Code>5006</Code>            <Description>Telephone number could not be disconnected since it is not associated with your account</Description>            <TelephoneNumber>9192755378</TelephoneNumber>        </Error>    </ErrorList>    <orderRequest>        <CustomerOrderId>Disconnect1234</CustomerOrderId>        <OrderCreateDate>2015-06-17T18:14:08.683Z</OrderCreateDate>        <id>b902dee1-0585-4258-becd-5c7e51ccf5e1</id>        <DisconnectTelephoneNumberOrderType>            <TelephoneNumberList>                <TelephoneNumber>9192755378</TelephoneNumber>                <TelephoneNumber>9192755703</TelephoneNumber>            </TelephoneNumberList>            <DisconnectMode>normal</DisconnectMode>        </DisconnectTelephoneNumberOrderType>    </orderRequest>    <OrderStatus>FAILED</OrderStatus></DisconnectTelephoneNumberOrderResponse>")]);
     self::$container = [];
     $history = Middleware::history(self::$container);
     $handler = HandlerStack::create($mock);
     $handler->push($history);
     $client = new Iris\Client("test", "test", array('url' => 'https://api.test.inetwork.com/v1.0', 'handler' => $handler));
     $account = new Iris\Account(9500249, $client);
     self::$disconnects = $account->disconnects();
 }