示例#1
0
 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
 }
 /**
  * Test a count request that cannot be satisfied with only the first page
  * of results.
  */
 public function testMultiPageCount()
 {
     $responses = array(MockPlugin::getMockFile(TEST_RESOURCE_PATH . '/http/drupal_org_major_bugs_0'), MockPlugin::getMockFile(TEST_RESOURCE_PATH . '/http/drupal_org_major_bugs_1'), MockPlugin::getMockFile(TEST_RESOURCE_PATH . '/http/drupal_org_major_bugs_2'), MockPlugin::getMockFile(TEST_RESOURCE_PATH . '/http/drupal_org_major_bugs_3'), MockPlugin::getMockFile(TEST_RESOURCE_PATH . '/http/drupal_org_major_bugs_4'), MockPlugin::getMockFile(TEST_RESOURCE_PATH . '/http/drupal_org_major_bugs_5'));
     $mockPlugin = new MockPlugin($responses);
     $client = new \Guzzle\Http\Client();
     $client->addSubscriber($mockPlugin);
     $issueCounter = new DrupalIssueCount($client);
     $issueCount = $issueCounter->getCounts(array('status' => array(1, 13, 8, 14, 15, 4)), array('major_bugs' => array('priorities' => array(300), 'categories' => array(1))));
     $this->assertEquals(271, $issueCount['major_bugs']);
 }
示例#3
0
 /**
  * Get a mock response for a client by mock file name
  *
  * @param string $path Relative path to the mock response file
  * @return Response
  */
 public function getMockHttpResponse($path)
 {
     if ($path instanceof Response) {
         return $path;
     }
     $ref = new ReflectionObject($this);
     $dir = dirname($ref->getFileName());
     // if mock file doesn't exist, check parent directory
     if (!file_exists($dir . '/Mock/' . $path) && file_exists($dir . '/../Mock/' . $path)) {
         return MockPlugin::getMockFile($dir . '/../Mock/' . $path);
     }
     return MockPlugin::getMockFile($dir . '/Mock/' . $path);
 }
 /**
  * Get a mock response for a client by mock file name
  *
  * @param string $path Relative path to the mock response file
  *
  * @return Response
  */
 public function getMockResponse($path)
 {
     return $path instanceof Response ? $path : MockPlugin::getMockFile(self::$mockBasePath . DIRECTORY_SEPARATOR . $path);
 }
示例#5
0
文件: ApiTest.php 项目: lyrixx/ratp
 private function getResponse($path)
 {
     return MockPlugin::getMockFile(__DIR__ . '/fixtures/' . $path);
 }
示例#6
0
 /**
  * @depends testAddsMockResponseToRequestFromClient
  */
 public function testDetachesTemporaryWhenEmpty()
 {
     $p = new MockPlugin(null, true);
     $p->addResponse(MockPlugin::getMockFile(__DIR__ . '/../../TestData/mock_response'));
     $client = new Client('http://localhost:123/');
     $client->getEventDispatcher()->addSubscriber($p, 9999);
     $request = $client->get();
     $request->send();
     $this->assertFalse($this->hasSubscriber($client, $p));
 }
 public function fixtureGuzzleCall($route)
 {
     $response = MockPlugin::getMockFile(__DIR__ . '/../Fixtures/GuzzleResponses/' . $route . '.txt');
     $this->guzzleMock->addResponse($response);
     return $this;
 }
示例#8
0
 public function testGetsExpiredArchive()
 {
     // Arrange
     $mock = new MockPlugin();
     $response = MockPlugin::getMockFile(self::$mockBasePath . 'v2/partner/APIKEY/archive/ARCHIVEID/get-expired');
     $mock->addResponse($response);
     $this->client->addSubscriber($mock);
     $archiveId = '063e72a4-64b4-43c8-9da5-eca071daab89';
     // Act
     $archive = $this->opentok->getArchive($archiveId);
     // Assert
     $this->assertInstanceOf('OpenTok\\Archive', $archive);
     $this->assertEquals("expired", $archive->status);
 }
示例#9
0
 private function addMock($path)
 {
     $this->mockPlugin->addResponse(MockPlugin::getMockFile(MOCK_BASE_PATH . '/' . $path));
 }