本文整理汇总了PHP中Guzzle\Plugin\Mock\MockPlugin::addResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP MockPlugin::addResponse方法的具体用法?PHP MockPlugin::addResponse怎么用?PHP MockPlugin::addResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Plugin\Mock\MockPlugin
的用法示例。
在下文中一共展示了MockPlugin::addResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testThatAssumeRoleWithWebIdentityRequestsDoNotGetSigned
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'));
}
示例2: slackRespondsOk
/**
* @Given /^Slack will respond ok to all requests$/
*/
public function slackRespondsOk()
{
$this->plugin->addResponse($this->getSuccessResponse());
$this->plugin->getEventDispatcher()->addListener('mock.request', function () {
$this->plugin->addResponse($this->getSuccessResponse());
});
}
示例3: testExceptionThrownWhenBatchErrors
/**
* @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);
}
示例4: testGetTokenFromJwt
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', 'testtestest@cultuurnet.be'));
$this->assertEquals($correctToken, $token);
}
示例5: testGetRequestToken
public function testGetRequestToken()
{
$callbackUrl = 'http://www.example.com/twitter/callback';
$this->factoryMock->expects($this->once())->method('getOAuthConnection')->with()->will($this->returnValue($this->bootstrapClient()));
$this->mockPlugin->addResponse(__DIR__ . '/fixtures/request_token.txt');
$requestToken = $this->bootstrapGateway()->getRequestToken($callbackUrl);
$this->assertEquals('foo', $requestToken['oauth_token']);
$this->assertEquals('bar', $requestToken['oauth_token_secret']);
$receivedRequests = $this->mockPlugin->getReceivedRequests();
$this->assertCount(1, $receivedRequests);
$this->assertEquals($callbackUrl, $receivedRequests[0]->getHeader('oauth_callback'));
}
示例6: prepareClient
/**
* @param MockPlugin $plugin
* @param $code
* @param null $body
*
* @return MyrrixClient
*/
protected function prepareClient(MockPlugin $plugin, $code, $body = null)
{
$client = MyrrixClient::factory();
$plugin->addResponse(new Response($code, null, $body));
$client->addSubscriber($plugin);
return $client;
}
示例7: testCreateServiceRequest
/**
* @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));
}
}
示例8: testGetQueue
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());
}
示例9: testDeletesArchive
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
}
示例10: setUp
protected function setUp()
{
$this->mock = new MockPlugin();
$this->mock->addResponse(new Response(200));
$this->client = new Client();
$this->client->addSubscriber($this->mock);
}
示例11: testHandlerThrowsErrorWhenClassNotExists
/**
* @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");
}
示例12: addResponse
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);
}
示例13: getMockGuzzle3Client
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;
}
示例14: newHttpClient
public function newHttpClient()
{
$client = parent::newHttpClient();
$plugin = new MockPlugin();
$plugin->addResponse(new Response(200));
$client->addSubscriber($plugin);
return $client;
}
示例15: getMockClient
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;
}