forked from loafle/openapi-generator-original
* reimplemented basic requests with httpplug * added returning headers * added query params support * removed constant reference to model class * some extra @throws; form params * form and query params encoding * file upload / form multipart * added missing response headers in WithHttpInfo calls * removed Store test From PetApiTest class * removed configuration overriding test as its now task of client adapters * updated store tests with new client initialization code * updated composer.json template * not using json_decode if response is string * renamed some variables to camelCase * removed ApiClient and Configuration classes * added HeaderSelector template * added ObjectSerializer injection * regenerated all samples * added AuthConfig and readded support for custom api keys * readded support for oauth tokens * readded basic auth; moved auth tests to separate test class * readded header params * readded support for collections in paths * readded config option; readded exception handling * file downloading; readded some Configuration properties removed earlier * readded default headers * made responses and return types work same way as earlier * made all methods static in ObjectSerializer * updated test.php, replaced autoload.php with composer's autoloader * updated api doc template * removed classes used for testing; regenerated Fake_classname_tags123Api * replaced httplug with guzzle6 * updated required php version to 5.5 * clean up * readded missing userAgent feature; removed default headers from Configuration * updated test.php * downgraded phpunit back to 4.8 to work with php5.5; fixed client initialization in some tests
63 lines
1.8 KiB
PHP
63 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Swagger\Client;
|
|
|
|
use Swagger\Client\Api\FakeApi;
|
|
use Swagger\Client\Api\PetApi;
|
|
use Swagger\Client\Model\Pet;
|
|
|
|
require_once __DIR__ . '/FakeHttpClient.php';
|
|
|
|
class AuthTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function testCustomApiKeyHeader()
|
|
{
|
|
$authConfig = new Configuration();
|
|
$authConfig->setApiKey('api_key', '123qwe');
|
|
|
|
$fakeHttpClient = new FakeHttpClient();
|
|
$api = new PetApi($fakeHttpClient, $authConfig);
|
|
$api->getPetById(123);
|
|
|
|
$headers = $fakeHttpClient->getLastRequest()->getHeaders();
|
|
|
|
$this->assertArrayHasKey('api_key', $headers);
|
|
$this->assertEquals(['123qwe'], $headers['api_key']);
|
|
}
|
|
|
|
public function testApiToken()
|
|
{
|
|
$authConfig = new Configuration();
|
|
$authConfig->setAccessToken('asd123');
|
|
|
|
$fakeHttpClient = new FakeHttpClient();
|
|
$api = new PetApi($fakeHttpClient, $authConfig);
|
|
$api->addPet(new Pet());
|
|
|
|
$headers = $fakeHttpClient->getLastRequest()->getHeaders();
|
|
|
|
$this->assertArrayHasKey('Authorization', $headers);
|
|
$this->assertEquals(['Bearer asd123'], $headers['Authorization']);
|
|
}
|
|
|
|
public function testBasicAuth()
|
|
{
|
|
$username = 'user';
|
|
$password = 'password';
|
|
|
|
$authConfig = new Configuration();
|
|
$authConfig->setUsername($username);
|
|
$authConfig->setPassword($password);
|
|
|
|
$fakeHttpClient = new FakeHttpClient();
|
|
$api = new FakeApi($fakeHttpClient, $authConfig);
|
|
$api->testEndpointParameters(123, 100.1, 'ASD_', 'ASD');
|
|
|
|
$headers = $fakeHttpClient->getLastRequest()->getHeaders();
|
|
|
|
$this->assertArrayHasKey('Authorization', $headers);
|
|
$encodedCredentials = base64_encode("$username:$password");
|
|
$this->assertEquals(["Basic $encodedCredentials"], $headers['Authorization']);
|
|
}
|
|
}
|