Ejemplo n.º 1
0
 public function testApiClient()
 {
     // test selectHeaderAccept
     $api_client = new ApiClient();
     $this->assertSame('application/json', $api_client->selectHeaderAccept(array('application/xml', 'application/json')));
     $this->assertSame(null, $api_client->selectHeaderAccept(array()));
     $this->assertSame('application/yaml,application/xml', $api_client->selectHeaderAccept(array('application/yaml', 'application/xml')));
     // test selectHeaderContentType
     $this->assertSame('application/json', $api_client->selectHeaderContentType(array('application/xml', 'application/json')));
     $this->assertSame('application/json', $api_client->selectHeaderContentType(array()));
     $this->assertSame('application/yaml,application/xml', $api_client->selectHeaderContentType(array('application/yaml', 'application/xml')));
     // test addDefaultHeader and getDefaultHeader
     $api_client->getConfig()->addDefaultHeader('test1', 'value1');
     $api_client->getConfig()->addDefaultHeader('test2', 200);
     $defaultHeader = $api_client->getConfig()->getDefaultHeaders();
     $this->assertSame('value1', $defaultHeader['test1']);
     $this->assertSame(200, $defaultHeader['test2']);
     // test deleteDefaultHeader
     $api_client->getConfig()->deleteDefaultHeader('test2');
     $defaultHeader = $api_client->getConfig()->getDefaultHeaders();
     $this->assertFalse(isset($defaultHeader['test2']));
     $pet_api2 = new Api\PetApi();
     $config3 = new Configuration();
     $apiClient3 = new ApiClient($config3);
     $apiClient3->getConfig()->setUserAgent('api client 3');
     $config4 = new Configuration();
     $apiClient4 = new ApiClient($config4);
     $apiClient4->getConfig()->setUserAgent('api client 4');
     $pet_api3 = new Api\PetApi($apiClient3);
     // 2 different api clients are not the same
     $this->assertNotEquals($apiClient3, $apiClient4);
     // customied pet api not using the old pet api's api client
     $this->assertNotEquals($pet_api2->getApiClient(), $pet_api3->getApiClient());
     // test access token
     $api_client->getConfig()->setAccessToken("testing_only");
     $this->assertSame('testing_only', $api_client->getConfig()->getAccessToken());
 }