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

88 lines
2.9 KiB
PHP

<?php
namespace OpenAPI\Client;
use OpenAPI\Client\Api\FakeApi;
use OpenAPI\Client\Api\UserApi;
use PHPUnit\Framework\TestCase;
require_once __DIR__ . '/FakeHttpClient.php';
class ParametersTest extends TestCase
{
/** @var FakeHttpClient */
private $fakeHttpClient;
/** @var FakeApi */
private $fakeApi;
/** @var UserApi */
private $userApi;
public function setUp(): void
{
$this->fakeHttpClient = new FakeHttpClient();
$this->fakeApi = new Api\FakeApi($this->fakeHttpClient);
$this->userApi = new Api\UserApi($this->fakeHttpClient);
}
public function testHeaderParam()
{
$this->fakeApi->testEnumParameters([], 'something');
$request = $this->fakeHttpClient->getLastRequest();
$headers = $request->getHeaders();
$this->assertArrayHasKey('enum_header_string', $headers);
$this->assertEquals(['something'], $headers['enum_header_string']);
}
public function testHeaderParamCollection()
{
$this->fakeApi->testEnumParameters(['string1', 'string2']);
$request = $this->fakeHttpClient->getLastRequest();
$headers = $request->getHeaders();
$this->assertArrayHasKey('enum_header_string_array', $headers);
$this->assertEquals(['string1,string2'], $headers['enum_header_string_array']);
}
public function testInlineAdditionalProperties()
{
$param = new \stdClass();
$param->foo = 'bar';
$this->fakeApi->testInlineAdditionalProperties($param);
$request = $this->fakeHttpClient->getLastRequest();
$this->assertSame('{"foo":"bar"}', $request->getBody()->getContents());
}
/**
* @see https://github.com/OpenAPITools/openapi-generator/pull/11225
* @dataProvider provideQueryParameters
*/
public function testQueryParameterCollectionFormatRequest($pipe, $ioutil, $http, $url, $context, $allow_empty, $language, $expected)
{
$request = $this->fakeApi->testQueryParameterCollectionFormatRequest($pipe, $ioutil, $http, $url, $context, $allow_empty, $language);
$this->assertEquals($expected, urldecode($request->getUri()->getQuery()));
}
public function provideQueryParameters()
{
$array = ['blue', 'black', 'brown'];
$object = ['R' => 100, 'G' => 200, 'B' => 150];
return [
[
$array, $array, $array, $array, $array, 'blue', $object, 'pipe=blue|black|brown&ioutil=blue,black,brown&http=blue black brown&url=blue,black,brown&context=blue&context=black&context=brown&R=100&G=200&B=150&allowEmpty=blue',
],
];
}
// missing example for collection path param in config
// public function testPathParamCollection()
// {
// $this->userApi->getUserByNameWithHttpInfo(['aa', 'bb']);
// $request = $this->fakeHttpClient->getLastRequest();
// $this->assertEquals('user/aa,bb', urldecode($request->getUri()->getPath()));
// }
}