forked from loafle/openapi-generator-original
* Bump minimum required version to PHP7.1 ref: http://php.net/supported-versions.php * Bump phpunit * Update [api|model]_test.mustache * Update samples bin/openapi3/php-petstore.sh * Update namespace of PHPUnit ("tests" folder) * `setExpectedException` is deleted in PHPUnit 7.4 * Update namespace of "Assert" class * The attribute 'name' is required * Add anotation to exclude the test from risky testcheck * Update samples (samples/client/petstore/php) * Apply updates to "test" in openapi2 folder (samples/client/petstore/php)b3495ecbfe
15e00ae89d
2fc6917d13
0d016c00ed
* Install php7.1 * Switch to php7 * Update samples (security) bin/security/php-petstore.sh
64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace OpenAPI\Client;
|
|
|
|
use OpenAPI\Client\Api\FakeApi;
|
|
use OpenAPI\Client\Api\PetApi;
|
|
use OpenAPI\Client\Model\Pet;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
require_once __DIR__ . '/FakeHttpClient.php';
|
|
|
|
class AuthTest extends 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']);
|
|
}
|
|
}
|