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

59 lines
1.9 KiB
PHP

<?php
namespace OpenAPI\Client;
use InvalidArgumentException;
use OpenAPI\Client\Api\PetApi;
use PHPUnit\Framework\TestCase;
require_once __DIR__ . '/FakeHttpClient.php';
/**
* Tests for server variables in operations
*/
class ServerVariablesInOperationTest extends TestCase
{
private FakeHttpClient $fakeHttpClient;
private PetApi $api;
private Model\Pet $pet;
public function setUp(): void
{
$this->fakeHttpClient = new FakeHttpClient();
$this->api = new Api\PetApi($this->fakeHttpClient);
$this->pet = new Model\Pet();
}
public function testServerVariablesInOperation(): void
{
# Test default values (if no variables are set)
$this->api->addPet($this->pet, 2);
$request = $this->fakeHttpClient->getLastRequest();
$this->assertEquals('petstore.swagger.io', $request->getUri()->getHost(), 'Server variable set to default value.');
# Test variables substitution
$this->api->addPet($this->pet, 2, [ 'server' => 'qa-petstore', 'port' => '8080']);
$request = $this->fakeHttpClient->getLastRequest();
$this->assertEquals('qa-petstore.swagger.io', $request->getUri()->getHost(), 'Server set to "qa-petstore"');
$this->assertEquals(8080, $request->getUri()->getPort(), 'Port set to 8080');
}
public function testLegacyServerChoiceInOperation(): void
{
# Test legacy behavior (set server using api->setHostIndex()
$this->api->setHostIndex(1);
$this->api->addPet($this->pet);
$request = $this->fakeHttpClient->getLastRequest();
$this->assertEquals('path-server-test.petstore.local', $request->getUri()->getHost(), 'Server set using legacy behavior');
}
public function testInvalidVariableValueInOperation(): void
{
$this->expectException(InvalidArgumentException::class);
$this->api->addPet($this->pet, 2,['server' => 'invalid-value']);
}
}