本文整理汇总了PHP中Guzzle\Plugin\Mock\MockPlugin类的典型用法代码示例。如果您正苦于以下问题:PHP MockPlugin类的具体用法?PHP MockPlugin怎么用?PHP MockPlugin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MockPlugin类的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: 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));
}
}
示例3: 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());
}
示例4: 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
}
示例5: newHttpClient
public function newHttpClient()
{
$client = parent::newHttpClient();
$plugin = new MockPlugin();
$plugin->addResponse(new Response(200));
$client->addSubscriber($plugin);
return $client;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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);
}
示例9: 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");
}
示例10: testSendsRequests
/**
* @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());
}
示例11: testGetCampaignSuppressionImports
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);
}
示例12: getMockClient
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;
}
示例13: let
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);
}
示例14: setUp
/**
*
*/
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);
}
示例15: createConfiguration
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);
}