William Cheng 6434c86afd
[php-nextgen] add php-nextgen client generator (#16480)
* php-nextgen first commit

* [php] Set minimal PHP version to ^8.0 (#14500)

* Set minimal PHP version to ^8.0

* Fix php-nextgen config

* Change stability to BETA

* Add phplint package (#15054)

* [php-nextgen] Rename folders to follow PDS skeleton (#15102)

* Change lib -> src, test -> tests folder

This will make build compliant to PHP-PDS skeleton.
Ref: https://github.com/php-pds/skeleton

* Refresh samples

* Exclude composer.lock from codebase (#15105)

Since client generator is library and not a project it makes sense
to exclude composer.lock from codebase by default.

Ref: http://getcomposer.org/doc/02-libraries.md#lock-file

* Add @generated tag to DocBlocks (#15106)

This tag in draft status right now(PSR-19), but I think we can leverage
from it already.

Ref: https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc-tags.md#55-generated

* update samples, doc

* update samples

---------

Co-authored-by: Yuriy Belenko <yura-bely@mail.ru>
2023-09-03 16:16:58 +08:00

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']);
}
}