public function testThatAssumeRoleWithWebIdentityRequestsDoNotGetSigned() { $client = StsClient::factory(); $mock = new MockPlugin(); $mock->addResponse(new Response(200)); $client->addSubscriber($mock); $command = $client->getCommand('AssumeRoleWithWebIdentity', array('RoleArn' => 'xxxxxxxxxxxxxxxxxxxxxx', 'RoleSessionName' => 'xx', 'WebIdentityToken' => 'xxxx')); $request = $command->prepare(); $command->execute(); $this->assertFalse($request->hasHeader('Authorization')); }
/** * @param array $input * @param bool $expectSuccess * * @covers GeoPal\Open311\Clients\TorontoClient::createServiceRequest * @dataProvider providerTestCreateServiceRequest */ public function testCreateServiceRequest($input, $expectSuccess) { $stubResponse = array(array(ServiceRequest::FIELD_SERVICE_REQUEST_ID => 'stub_id')); /** * Create and set up fake guzzle client */ $response = is_null($stubResponse) ? new Response(200) : new Response(200, null, json_encode($stubResponse)); $mockPlugin = new MockPlugin(); $mockPlugin->addResponse($response); $stubGuzzleClient = new Client(); $stubGuzzleClient->addSubscriber($mockPlugin); /** * Create test client */ $client = new TorontoClient('testing', $stubGuzzleClient); /** * Check call result */ if ($expectSuccess) { $this->assertInstanceOf('\\GeoPal\\Open311\\ServiceRequestResponse', $client->createServiceRequest($input[ServiceRequest::FIELD_SERVICE_CODE], $input[ServiceRequest::FIELD_LATITUDE], $input[ServiceRequest::FIELD_LONGITUDE], $input[ServiceRequest::FIELD_ADDRESS_STRING], $input[ServiceRequest::FIELD_ADDRESS_ID], $input[ServiceRequest::FIELD_EMAIL], $input[ServiceRequest::FIELD_DEVICE_ID], $input[ServiceRequest::FIELD_ACCOUNT_ID], $input[ServiceRequest::FIELD_FIRST_NAME], $input[ServiceRequest::FIELD_LAST_NAME], $input[ServiceRequest::FIELD_PHONE], $input[ServiceRequest::FIELD_DESCRIPTION], $input[ServiceRequest::FIELD_MEDIA_URL])); } else { $result = false; $exceptionThrown = false; try { // Throw an exception or change $result from false to null $result = $client->createServiceRequest($input[ServiceRequest::FIELD_SERVICE_CODE], $input[ServiceRequest::FIELD_LATITUDE], $input[ServiceRequest::FIELD_LONGITUDE], $input[ServiceRequest::FIELD_ADDRESS_STRING], $input[ServiceRequest::FIELD_EMAIL], $input[ServiceRequest::FIELD_DEVICE_ID], $input[ServiceRequest::FIELD_ACCOUNT_ID], $input[ServiceRequest::FIELD_FIRST_NAME], $input[ServiceRequest::FIELD_LAST_NAME], $input[ServiceRequest::FIELD_PHONE], $input[ServiceRequest::FIELD_DESCRIPTION], $input[ServiceRequest::FIELD_MEDIA_URL]); } catch (Open311Exception $e) { $exceptionThrown = true; } $this->assertTrue($exceptionThrown || is_null($result)); } }
public function testGetQueue() { $client = new Client(); $mock = new MockPlugin(); $mock->addResponse(__DIR__ . '/fixtures/get-queue'); $client->addGuzzlePlugin($mock); $response = $client->getQueue('/', 'testqueue'); $this->assertInstanceOf(Queue::class, $response); $this->assertEquals(17568, $response->getMemory()); $this->assertEquals('', $response->getConsumerUtilisation()); $this->assertEquals(new \DateTime('2014-11-21 00:48:25'), $response->getIdleSince()); $this->assertEquals('HA', $response->getPolicy()); $this->assertEquals(4, $response->getConsumerCount()); $this->assertEquals('', $response->getExclusiveConsumerTag()); $this->assertEquals(['rabbit@cookie', 'rabbit@cupcake'], $response->getSlaveNodes()); $this->assertEquals(['rabbit@cupcake', 'rabbit@cookie'], $response->getSynchronizedSlaveNodes()); $this->assertEquals('running', $response->getState()); $this->assertCount(4, $response->getConsumers()); foreach ($response->getConsumers() as $consumer) { $this->verifyConsumer($consumer); } $this->assertEquals('datawarehouse_update_sku_saleability', $response->getQueueName()); $this->assertEquals('/', $response->getQueueVhost()); $this->assertEquals(true, $response->isDurable()); $this->assertEquals(false, $response->isAutoDeleted()); $this->assertEquals([], $response->getArguments()); $this->assertEquals('rabbit@scone', $response->getNode()); $this->assertEquals(1293437, $response->getAckCount()); }
public function testDeletesArchive() { // Arrange $mock = new MockPlugin(); $response = MockPlugin::getMockFile(self::$mockBasePath . 'v2/partner/APIKEY/archive/ARCHIVEID/delete'); $mock->addResponse($response); $this->client->addSubscriber($mock); // Act // TODO: should this test be run on an archive object whose fixture has status 'available' // instead of 'started'? $success = $this->archive->delete(); // Assert $requests = $mock->getReceivedRequests(); $this->assertCount(1, $requests); $request = $requests[0]; $this->assertEquals('DELETE', strtoupper($request->getMethod())); $this->assertEquals('/v2/partner/' . $this->API_KEY . '/archive/' . $this->archiveData['id'], $request->getPath()); $this->assertEquals('api.opentok.com', $request->getHost()); $this->assertEquals('https', $request->getScheme()); $contentType = $request->getHeader('Content-Type'); $this->assertNotEmpty($contentType); $this->assertEquals('application/json', $contentType); $authString = $request->getHeader('X-TB-PARTNER-AUTH'); $this->assertNotEmpty($authString); $this->assertEquals($this->API_KEY . ':' . $this->API_SECRET, $authString); // TODO: test the dynamically built User Agent string $userAgent = $request->getHeader('User-Agent'); $this->assertNotEmpty($userAgent); $this->assertStringStartsWith('OpenTok-PHP-SDK/2.3.2-alpha.1', $userAgent->__toString()); $this->assertTrue($success); // TODO: assert that all properties of the archive object were cleared }
public function newHttpClient() { $client = parent::newHttpClient(); $plugin = new MockPlugin(); $plugin->addResponse(new Response(200)); $client->addSubscriber($plugin); return $client; }
private function getMockGuzzle3Client($statusCode = 200, $content = null) { $plugin = new MockPlugin(); $plugin->addResponse(new Guzzle3Response($statusCode, null, $content)); $client = new Guzzle3Client(); $client->addSubscriber($plugin); return $client; }
private function getMockClient($statusCode = 200, $content = null) { $plugin = new MockPlugin(); $plugin->addResponse(new Response($statusCode, null, $content)); $client = new Client(null, array('request.options' => array('exceptions' => false))); $client->addSubscriber($plugin); return $client; }
public function addResponse($code, $body, $headers = null) { $plugin = new MockPlugin(); $response = new Response($code, $headers, $body); $plugin->addResponse($response); $this->plugin = $plugin; $this->getClient()->addSubscriber($plugin); }
/** * @expectedException Fabricius\Exception\RuntimeException */ public function testHandlerThrowsErrorWhenClassNotExists() { $plugin = new MockPlugin(); $plugin->addResponse(__DIR__ . '/md_github_400_response.txt'); $this->client->addSubscriber($plugin); $handler = new MarkdownGithubHandler($this->client); $formatted = $handler->format("#Hello World"); }
/** * @dataProvider requestProvider */ public function testSendsRequests($method) { $mock = new MockPlugin(array(new Response(200))); call_user_func('Guzzle\\Http\\StaticClient::' . $method, 'http://foo.com', array('plugins' => array($mock))); $requests = $mock->getReceivedRequests(); $this->assertCount(1, $requests); $this->assertEquals($method, $requests[0]->getMethod()); }
public function testGetTokenFromJwt() { $xml = file_get_contents(__DIR__ . '/samples/token-without-consumer.xml'); $response = new Response('200', null, $xml); $this->apiMock->addResponse($response); $token = $this->fetcher->getAccessTokenFromJwt('0005548e3bfe0a47938fd5b1c8369ff1'); $correctToken = new Token('2143f7db7642b3687e90d718b79a42ce', '4c06eb61aa814a057578640ee61ea420', new User('12346093-0e7e-4803-be0b-69b24c145f89', 'testtesttest', '*****@*****.**')); $this->assertEquals($correctToken, $token); }
public function testGetCampaignSuppressionImports() { $client = new AdvertiserClient(); $plugin = new MockPlugin(); $plugin->addResponse(new Response(200)); $client->addSubscriber($plugin); $client->setAdvertiser(2, 'thekey', 'thesecret'); $client->getCampaignSuppressionImports(1); }
protected function getMockClient(Response $response = null) { $response = $response ?: new Response(200); $plugin = new MockPlugin(); $plugin->addResponse($response); $client = new Client(); $client->addSubscriber($plugin); return $client; }
function let() { $client = new Client(); $plugin = new MockPlugin(); $plugin->addResponse(new Response(200, ['Content-Type' => 'text/xml'], file_get_contents(__DIR__ . '/station-facilities.xml'))); $client->addSubscriber($plugin); $this->beConstructedWith('http://example/station-facilities.xml'); $this->setClient($client); }
/** * @expectedException Fabricius\Exception\RuntimeException * @expectedExceptionMessage Request to Github failed: An error occured [500] */ public function testExceptionThrownWhenBatchErrors() { $this->plugin->addResponse(new Response(200, null, json_encode(array(array('path' => 'mock'))))); $this->plugin->addResponse(new Response(500, null, json_encode(array('message' => 'An error occured')))); $parser = Phake::mock('Fabricius\\Parser\\ParserInterface'); $provider = new GithubLoader($this->client, 'GITHUB OWNER', 'GITHUB REPO'); $metadata = Phake::mock('Fabricius\\Metadata\\ClassMetadata'); $content = $provider->load($metadata, $parser); }
/** * */ protected function setUp() { parent::setUp(); $guzzleClient = new GuzzleClient('http://www.test.com/'); $mock = new MockPlugin(); $mock->addResponse(new Response(200, array(), 'test')); $guzzleClient->addSubscriber($mock); $this->geopalClient = new GeoPalClient(null, null, $guzzleClient); }
private function createConfiguration($response) { $plugin = new MockPlugin(); $plugin->addResponse(new Response(200, null, $response)); $client = new GuzzleClient(); $client->addSubscriber($plugin); $this->ringCaptcha = new RingCaptcha($this->apiKey, $this->appKey); $this->ringCaptcha->setClient($client); }
/** * Setup */ public function setUp() { $plugin = new MockPlugin(); $response = new GuzzleResponse(200); $response->setBody(file_get_contents(__DIR__ . '/Fixtures/response_projects.json')); $plugin->addResponse($response); $client = new VersionEyeClient('foo'); $client->addSubscriber($plugin); $this->object = new VersionEyeApi($client, 'foo'); }
public function testReponse() { // example for mock Responses $client = OmDataClient::factory(array('api_key' => '****')); $plugin = new MockPlugin(); $plugin->addResponse(new Response(200, null, 'This is the body content')); $client->addSubscriber($plugin); $command = $client->getCommand('serps_weekly/get_rankings', array('keyword' => 'hausbau', 'date' => '2013-11-24')); $result = $command->execute(); //var_dump($result->getBody(true)); }
public function testThatAssumeRoleWithWebIdentityRequestsDoNotGetSigned() { $client = CognitoIdentityClient::factory(array('region' => 'us-east-1')); $mock = new MockPlugin(); $mock->addResponse(new Response(200)); $client->addSubscriber($mock); $command = $client->getCommand('GetId', array('AccountId' => '1234567890', 'IdentityPoolId' => 'abc:abc')); $request = $command->prepare(); $command->execute(); $this->assertFalse($request->hasHeader('Authorization')); }
public function buildClient($code, $headers, $body) { $response = new Response($code, $headers, $body); $client = new HTTPClient('https://api.sendgrid.com'); $mock = new MockPlugin(); $mock->addResponse($response); $client->addSubscriber($mock); $sendgrid = new Client('sendgrid_apikey'); $sendgrid->setClient($client); return $sendgrid; }
public function testXYZ() { $client = new Client(); $mock = new MockPlugin(); $mock->addResponse(new Response(200, null, json_encode(array("access_token" => "my_access_token", "token_type" => "BeArEr", "refresh_token" => "why_not_a_refresh_token")))); $client->addSubscriber($mock); $state = new State(array("state" => "my_state", "client_config_id" => "foo", "issue_time" => time() - 100, "user_id" => "my_user_id", "scope" => Scope::fromString("foo bar"))); $this->storage->storeState($state); $callback = new Callback("foo", $this->clientConfig[0], $this->storage, $client); $tokenResponse = $callback->handleCallback(array("state" => "my_state", "code" => "my_code")); $this->assertEquals("my_access_token", $tokenResponse->getAccessToken()); }
protected function getMockedClient(Response $response) { $operation = new Operation(array('httpMethod' => 'GET', 'name' => 'Mock')); $service = new ServiceDescription(); $service->addOperation($operation); $plugin = new MockPlugin(); $plugin->addResponse($response); $client = new Client(); $client->setDescription($service); $client->addSubscriber($plugin); return $client; }
public function testRegisterPlugin() { $client = new Client('http://example.com'); $client->addSubscriber($this->getPlugin()); $mock = new MockPlugin(); $mock->addResponse(new Response(200)); $client->addSubscriber($mock); $request = $client->get('/resource/1'); $request->send(); $authorization = (string) $request->getHeader('Authorization'); $this->assertRegExp('@Acquia 1:([a-zA-Z0-9+/]+={0,2})$@', $authorization); }
public function testXYZ() { $client = new Client(); $mock = new MockPlugin(); $mock->addResponse(new Response(200, null, json_encode(array('access_token' => 'my_access_token', 'token_type' => 'BeArEr', 'refresh_token' => 'why_not_a_refresh_token')))); $client->addSubscriber($mock); $state = new State(array('state' => 'my_state', 'client_config_id' => 'foo', 'issue_time' => time() - 100, 'user_id' => 'my_user_id', 'scope' => Scope::fromString('foo bar'))); $this->storage->storeState($state); $guzzle3Client = new Guzzle3Client($client); $callback = new Callback('foo', $this->clientConfig[0], $this->storage, $guzzle3Client); $tokenResponse = $callback->handleCallback(array('state' => 'my_state', 'code' => 'my_code')); $this->assertEquals('my_access_token', $tokenResponse->getAccessToken()); }
/** * @param array $responseCollection * @return \CanalTP\AbstractGuzzle\Guzzle */ public function getMock(array $responseCollection) { $plugin = new MockPlugin(); foreach ($responseCollection as $response) { if ($response instanceof Psr7Response) { $response = new Response($response->getStatusCode(), $response->getHeaders(), $response->getBody()); } $plugin->addResponse($response); } $client = GuzzleFactory::createClient(''); $client->addSubscriber($plugin); return $client; }
protected function getClient($fixtureFilePath = null) { if (null === $fixtureFilePath) { return $this->getMock('Guzzle\\Http\\Client'); } $response = new Response(200); $response->setBody(file_get_contents($fixtureFilePath)); $mock = new MockPlugin(); $mock->addResponse($response); $client = new Client(); $client->addSubscriber($mock); return $client; }
public function mock(array $responses) { $plugin = new MockPlugin(); foreach ($responses as $r) { $status = isset($r[0]) ? $r[0] : 200; $headers = isset($r[1]) ? $r[1] : []; $body = isset($r[2]) ? $r[2] : null; $mockResponse = new \Guzzle\Http\Message\Response($status, $headers, $body); $plugin->addResponse($mockResponse); } $this->getClient()->addSubscriber($plugin); return $plugin; }
public function testMockSearch() { $solr = $this->getAcquiaSearchClient(); $mock = new MockPlugin(); $mock->addResponse(new Response(200)); $solr->addSubscriber($mock); $request = $solr->get('select'); $request->send(); $headers = $request->getHeaders()->get('cookie')->toArray(); $string = join(';', $headers); $this->assertRegExp('/acquia_solr_time=\\d+;/', $string); $this->assertRegExp('/acquia_solr_nonce=[a-zA-Z0-9+\\/]+;/', $string); $this->assertRegExp('/acquia_solr_hmac=[a-f0-9]+;/', $string); }
public function setUp() { parent::setUp(); $mock = new MockPlugin(); $body = file_get_contents(dirname(__FILE__) . '/Mock/TokenPurchaseSuccess.txt'); $mock->addResponse(new Response(200, array('Content-Type' => 'application/json'), $body))->addResponse($this->getMockHttpResponse('TokenPurchaseFailure.txt')); // Add the mock plugin to the client object $httpClient = $this->getHttpClient(); $httpClient->addSubscriber($mock); $this->gateway = new TokenGateway($httpClient, $this->getHttpRequest()); $this->options = array('card' => $this->getValidCard(), 'token' => 'Y2RkZDdjN2EtNjFmZS00ZGYzLWI4NmEtNGZhMjI3NmExMzQ0', 'transactionId' => '123456', 'currency' => 'USD', 'amount' => '20.5'); $this->gateway->setAccountNumber('801290261'); $this->gateway->setTestMode(true); $this->gateway->setPrivateKey('5F876A36-D506-4E1F-8EE9-DA2358500F9C'); }