コード例 #1
0
ファイル: OrdinanceTests.php プロジェクト: BRGWeb/gedcomx-php
 /**
  * @vcr OrdinanceTests/testReadOrdinancesForbidden.json
  * @link https://familysearch.org/developers/docs/api/ordinances/Read_Ordinances_%28Access_Forbidden%29_usecase
  */
 public function testReadOrdinancesForbidden()
 {
     $factory = new StateFactory();
     $collectionState = $factory->newCollectionState()->authenticateViaOAuth2Password('general_public_user', '1234pass', SandboxCredentials::API_KEY);
     $response = $collectionState->getClient()->get($this->ordinanceUri, ['headers' => ['Authorization' => "Bearer " . $collectionState->getAccessToken(), 'Accept' => Gedcomx::JSON_MEDIA_TYPE, 'Content-Type' => Gedcomx::JSON_MEDIA_TYPE]]);
     $this->assertEquals(HttpStatus::FORBIDDEN, $response->getStatusCode(), 'Error with invalid Ordinance test. Returned: ' . HttpStatus::getText($response->getStatusCode()) . "(" . $response->getStatusCode() . ")");
 }
コード例 #2
0
 /**
  * @vcr Authentication/testDeleteAccessToken.json
  * @link https://familysearch.org/developers/docs/api/authentication/Delete_Access_Token_usecase
  */
 public function testDeleteAccessToken()
 {
     $factory = new StateFactory();
     $collectionState = $factory->newCollectionState()->authenticateViaOAuth2Password(SandboxCredentials::USERNAME, SandboxCredentials::PASSWORD, SandboxCredentials::API_KEY);
     $link = $collectionState->getLink(Rel::OAUTH2_TOKEN);
     $request = new Request('DELETE', $link->getHref(), ['Accept' => Gedcomx::JSON_APPLICATION_TYPE, 'Authorization' => "Bearer {$collectionState->getAccessToken()}"]);
     $request = $request->withUri($request->getUri()->withQuery('access_token=' . $collectionState->getAccessToken()));
     $response = $collectionState->getClient()->send($request);
     $this->assertEquals(HttpStatus::NO_CONTENT, $response->getStatusCode(), __METHOD__ . " failed. " . HttpStatus::getText($response->getStatusCode()) . "(" . $response->getStatusCode() . ") returned.");
 }
コード例 #3
0
ファイル: ApiTestCase.php プロジェクト: BRGWeb/gedcomx-php
 protected function buildFailMessage($methodName, $stateObj)
 {
     $method = explode("\\", $methodName);
     $methodName = array_pop($method);
     $request = $stateObj->getRequest();
     $code = $stateObj->getStatus();
     $message = $methodName . " failed. Returned " . $code . ":" . HttpStatus::getText($code);
     $message .= "\n" . $request->getMethod() . ": " . $stateObj->getResponse()->effectiveUri;
     $message .= "\nContent-Type: " . count($request->getHeader("Content-Type")) > 0 ? $request->getHeader("Content-Type")[0] : '';
     $message .= "\nAccept: " . count($request->getHeader("Accept")) > 0 ? $request->getHeader("Accept")[0] : '';
     $message .= "\nRequest:" . ($request instanceof Request ? "\n" . $request->getBody() : " n/a");
     $message .= "\nResponse:\n" . $stateObj->getResponse()->getBody();
     $warnings = $stateObj->getHeader('warning');
     if (!empty($warnings)) {
         $message .= "Warnings:\n";
         foreach ($warnings as $msg) {
             $message .= $msg . "\n";
         }
     }
     return $message;
 }