Skip to content

Commit 3453c7b

Browse files
authored
Test PHP clients in Github workflow (#21643)
* test php clients in github workflow * trigger build failure * update workflow * Revert "trigger build failure" This reverts commit 572a69f. * update tests * update tests * update test * fix tests * fix async test * update tests
1 parent a60d3d4 commit 3453c7b

File tree

12 files changed

+116
-20
lines changed

12 files changed

+116
-20
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Samples PHP clients
2+
3+
on:
4+
push:
5+
paths:
6+
- samples/client/petstore/php/OpenAPIClient-php/**
7+
pull_request:
8+
paths:
9+
- samples/client/petstore/php/OpenAPIClient-php/**
10+
jobs:
11+
build:
12+
name: Build PHP projects
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
php:
18+
- "8.1"
19+
- "8.2"
20+
- "8.3"
21+
- "8.4"
22+
sample:
23+
# clients
24+
- samples/client/petstore/php/OpenAPIClient-php/
25+
services:
26+
petstore-api:
27+
image: swaggerapi/petstore
28+
ports:
29+
- 80:8080
30+
env:
31+
SWAGGER_HOST: http://petstore.swagger.io
32+
SWAGGER_BASE_PATH: /v2
33+
steps:
34+
- uses: actions/checkout@v4
35+
- name: Setup PHP with tools
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: "${{ matrix.php }}"
39+
tools: php-cs-fixer, phpunit
40+
- name: composer install
41+
working-directory: ${{ matrix.sample }}
42+
run: composer install
43+
- name: phpunit
44+
working-directory: ${{ matrix.sample }}
45+
run: vendor/bin/phpunit tests

modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ paths:
3131
$ref: '#/components/schemas/Foo'
3232
/pet:
3333
servers:
34+
- url: 'http://localhost/v2'
3435
- url: 'http://petstore.swagger.io/v2'
3536
- url: 'http://path-server-test.petstore.local/v2'
3637
- url: 'http://{server}.swagger.io:{port}/v2'

modules/openapi-generator/src/test/resources/3_0/php/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ paths:
3131
$ref: '#/components/schemas/Foo'
3232
/pet:
3333
servers:
34+
- url: 'http://localhost/v2'
3435
- url: 'http://petstore.swagger.io/v2'
3536
- url: 'http://path-server-test.petstore.local/v2'
3637
- url: 'http://{server}.swagger.io:{port}/v2'

samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Api/PetApi.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ All URIs are relative to http://petstore.swagger.io:80/v2, except if the operati
2121
addPet($pet)
2222
```
2323
### URI(s):
24-
- http://petstore.swagger.io/v2 - http://path-server-test.petstore.local/v2 - http://{server}.swagger.io:{port}/v2 test server with variables
24+
- http://localhost/v2 - http://petstore.swagger.io/v2 - http://path-server-test.petstore.local/v2 - http://{server}.swagger.io:{port}/v2 test server with variables
2525
- Variables:
2626
- server: target server
2727
- Allowed values:
@@ -80,6 +80,7 @@ try {
8080

8181

8282

83+
8384
### Return type
8485

8586
void (empty response body)
@@ -346,7 +347,7 @@ try {
346347
updatePet($pet)
347348
```
348349
### URI(s):
349-
- http://petstore.swagger.io/v2 - http://path-server-test.petstore.local/v2 - http://{server}.swagger.io:{port}/v2 test server with variables
350+
- http://localhost/v2 - http://petstore.swagger.io/v2 - http://path-server-test.petstore.local/v2 - http://{server}.swagger.io:{port}/v2 test server with variables
350351
- Variables:
351352
- server: target server
352353
- Allowed values:
@@ -405,6 +406,7 @@ try {
405406

406407

407408

409+
408410
### Return type
409411

410412
void (empty response body)

samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Api/PetApi.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public function getConfig(): Configuration
158158
*
159159
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
160160
* if needed, use the 'variables' parameter to pass variables to the host.
161+
* URL: http://localhost/v2
161162
* URL: http://petstore.swagger.io/v2
162163
* URL: http://path-server-test.petstore.local/v2
163164
* URL: http://{server}.swagger.io:{port}/v2
@@ -198,6 +199,7 @@ public function addPet(
198199
*
199200
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
200201
* if needed, use the 'variables' parameter to pass variables to the host.
202+
* URL: http://localhost/v2
201203
* URL: http://petstore.swagger.io/v2
202204
* URL: http://path-server-test.petstore.local/v2
203205
* URL: http://{server}.swagger.io:{port}/v2
@@ -269,6 +271,7 @@ public function addPetWithHttpInfo(
269271
*
270272
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
271273
* if needed, use the 'variables' parameter to pass variables to the host.
274+
* URL: http://localhost/v2
272275
* URL: http://petstore.swagger.io/v2
273276
* URL: http://path-server-test.petstore.local/v2
274277
* URL: http://{server}.swagger.io:{port}/v2
@@ -313,6 +316,7 @@ function ($response) {
313316
*
314317
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
315318
* if needed, use the 'variables' parameter to pass variables to the host.
319+
* URL: http://localhost/v2
316320
* URL: http://petstore.swagger.io/v2
317321
* URL: http://path-server-test.petstore.local/v2
318322
* URL: http://{server}.swagger.io:{port}/v2
@@ -373,6 +377,7 @@ function ($exception) {
373377
*
374378
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
375379
* if needed, use the 'variables' parameter to pass variables to the host.
380+
* URL: http://localhost/v2
376381
* URL: http://petstore.swagger.io/v2
377382
* URL: http://path-server-test.petstore.local/v2
378383
* URL: http://{server}.swagger.io:{port}/v2
@@ -504,6 +509,10 @@ public function addPetRequest(
504509
protected function getHostSettingsForaddPet(): array
505510
{
506511
return [
512+
[
513+
"url" => "http://localhost/v2",
514+
"description" => "No description provided",
515+
],
507516
[
508517
"url" => "http://petstore.swagger.io/v2",
509518
"description" => "No description provided",
@@ -1656,6 +1665,7 @@ public function getPetByIdRequest(
16561665
*
16571666
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
16581667
* if needed, use the 'variables' parameter to pass variables to the host.
1668+
* URL: http://localhost/v2
16591669
* URL: http://petstore.swagger.io/v2
16601670
* URL: http://path-server-test.petstore.local/v2
16611671
* URL: http://{server}.swagger.io:{port}/v2
@@ -1696,6 +1706,7 @@ public function updatePet(
16961706
*
16971707
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
16981708
* if needed, use the 'variables' parameter to pass variables to the host.
1709+
* URL: http://localhost/v2
16991710
* URL: http://petstore.swagger.io/v2
17001711
* URL: http://path-server-test.petstore.local/v2
17011712
* URL: http://{server}.swagger.io:{port}/v2
@@ -1767,6 +1778,7 @@ public function updatePetWithHttpInfo(
17671778
*
17681779
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
17691780
* if needed, use the 'variables' parameter to pass variables to the host.
1781+
* URL: http://localhost/v2
17701782
* URL: http://petstore.swagger.io/v2
17711783
* URL: http://path-server-test.petstore.local/v2
17721784
* URL: http://{server}.swagger.io:{port}/v2
@@ -1811,6 +1823,7 @@ function ($response) {
18111823
*
18121824
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
18131825
* if needed, use the 'variables' parameter to pass variables to the host.
1826+
* URL: http://localhost/v2
18141827
* URL: http://petstore.swagger.io/v2
18151828
* URL: http://path-server-test.petstore.local/v2
18161829
* URL: http://{server}.swagger.io:{port}/v2
@@ -1871,6 +1884,7 @@ function ($exception) {
18711884
*
18721885
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
18731886
* if needed, use the 'variables' parameter to pass variables to the host.
1887+
* URL: http://localhost/v2
18741888
* URL: http://petstore.swagger.io/v2
18751889
* URL: http://path-server-test.petstore.local/v2
18761890
* URL: http://{server}.swagger.io:{port}/v2
@@ -2002,6 +2016,10 @@ public function updatePetRequest(
20022016
protected function getHostSettingsForupdatePet(): array
20032017
{
20042018
return [
2019+
[
2020+
"url" => "http://localhost/v2",
2021+
"description" => "No description provided",
2022+
],
20052023
[
20062024
"url" => "http://petstore.swagger.io/v2",
20072025
"description" => "No description provided",

samples/client/petstore/php/OpenAPIClient-php/docs/Api/PetApi.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ All URIs are relative to http://petstore.swagger.io:80/v2, except if the operati
2323
addPet($pet)
2424
```
2525
### URI(s):
26-
- http://petstore.swagger.io/v2 - http://path-server-test.petstore.local/v2 - http://{server}.swagger.io:{port}/v2 test server with variables
26+
- http://localhost/v2 - http://petstore.swagger.io/v2 - http://path-server-test.petstore.local/v2 - http://{server}.swagger.io:{port}/v2 test server with variables
2727
- Variables:
2828
- server: target server
2929
- Allowed values:
@@ -82,6 +82,7 @@ try {
8282

8383

8484

85+
8586
### Return type
8687

8788
void (empty response body)
@@ -348,7 +349,7 @@ try {
348349
updatePet($pet)
349350
```
350351
### URI(s):
351-
- http://petstore.swagger.io/v2 - http://path-server-test.petstore.local/v2 - http://{server}.swagger.io:{port}/v2 test server with variables
352+
- http://localhost/v2 - http://petstore.swagger.io/v2 - http://path-server-test.petstore.local/v2 - http://{server}.swagger.io:{port}/v2 test server with variables
352353
- Variables:
353354
- server: target server
354355
- Allowed values:
@@ -407,6 +408,7 @@ try {
407408

408409

409410

411+
410412
### Return type
411413

412414
void (empty response body)

samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public function getConfig()
164164
*
165165
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
166166
* if needed, use the 'variables' parameter to pass variables to the host.
167+
* URL: http://localhost/v2
167168
* URL: http://petstore.swagger.io/v2
168169
* URL: http://path-server-test.petstore.local/v2
169170
* URL: http://{server}.swagger.io:{port}/v2
@@ -199,6 +200,7 @@ public function addPet($pet, ?int $hostIndex = null, array $variables = [], stri
199200
*
200201
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
201202
* if needed, use the 'variables' parameter to pass variables to the host.
203+
* URL: http://localhost/v2
202204
* URL: http://petstore.swagger.io/v2
203205
* URL: http://path-server-test.petstore.local/v2
204206
* URL: http://{server}.swagger.io:{port}/v2
@@ -266,6 +268,7 @@ public function addPetWithHttpInfo($pet, ?int $hostIndex = null, array $variable
266268
*
267269
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
268270
* if needed, use the 'variables' parameter to pass variables to the host.
271+
* URL: http://localhost/v2
269272
* URL: http://petstore.swagger.io/v2
270273
* URL: http://path-server-test.petstore.local/v2
271274
* URL: http://{server}.swagger.io:{port}/v2
@@ -305,6 +308,7 @@ function ($response) {
305308
*
306309
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
307310
* if needed, use the 'variables' parameter to pass variables to the host.
311+
* URL: http://localhost/v2
308312
* URL: http://petstore.swagger.io/v2
309313
* URL: http://path-server-test.petstore.local/v2
310314
* URL: http://{server}.swagger.io:{port}/v2
@@ -360,6 +364,7 @@ function ($exception) {
360364
*
361365
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
362366
* if needed, use the 'variables' parameter to pass variables to the host.
367+
* URL: http://localhost/v2
363368
* URL: http://petstore.swagger.io/v2
364369
* URL: http://path-server-test.petstore.local/v2
365370
* URL: http://{server}.swagger.io:{port}/v2
@@ -486,6 +491,10 @@ public function addPetRequest($pet, ?int $hostIndex = null, array $variables = [
486491
protected function getHostSettingsForaddPet(): array
487492
{
488493
return [
494+
[
495+
"url" => "http://localhost/v2",
496+
"description" => "No description provided",
497+
],
489498
[
490499
"url" => "http://petstore.swagger.io/v2",
491500
"description" => "No description provided",
@@ -1583,6 +1592,7 @@ public function getPetByIdRequest($pet_id, string $contentType = self::contentTy
15831592
*
15841593
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
15851594
* if needed, use the 'variables' parameter to pass variables to the host.
1595+
* URL: http://localhost/v2
15861596
* URL: http://petstore.swagger.io/v2
15871597
* URL: http://path-server-test.petstore.local/v2
15881598
* URL: http://{server}.swagger.io:{port}/v2
@@ -1618,6 +1628,7 @@ public function updatePet($pet, ?int $hostIndex = null, array $variables = [], s
16181628
*
16191629
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
16201630
* if needed, use the 'variables' parameter to pass variables to the host.
1631+
* URL: http://localhost/v2
16211632
* URL: http://petstore.swagger.io/v2
16221633
* URL: http://path-server-test.petstore.local/v2
16231634
* URL: http://{server}.swagger.io:{port}/v2
@@ -1685,6 +1696,7 @@ public function updatePetWithHttpInfo($pet, ?int $hostIndex = null, array $varia
16851696
*
16861697
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
16871698
* if needed, use the 'variables' parameter to pass variables to the host.
1699+
* URL: http://localhost/v2
16881700
* URL: http://petstore.swagger.io/v2
16891701
* URL: http://path-server-test.petstore.local/v2
16901702
* URL: http://{server}.swagger.io:{port}/v2
@@ -1724,6 +1736,7 @@ function ($response) {
17241736
*
17251737
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
17261738
* if needed, use the 'variables' parameter to pass variables to the host.
1739+
* URL: http://localhost/v2
17271740
* URL: http://petstore.swagger.io/v2
17281741
* URL: http://path-server-test.petstore.local/v2
17291742
* URL: http://{server}.swagger.io:{port}/v2
@@ -1779,6 +1792,7 @@ function ($exception) {
17791792
*
17801793
* This operation contains host(s) defined in the OpenAPI spec. Use 'hostIndex' to select the host.
17811794
* if needed, use the 'variables' parameter to pass variables to the host.
1795+
* URL: http://localhost/v2
17821796
* URL: http://petstore.swagger.io/v2
17831797
* URL: http://path-server-test.petstore.local/v2
17841798
* URL: http://{server}.swagger.io:{port}/v2
@@ -1905,6 +1919,10 @@ public function updatePetRequest($pet, ?int $hostIndex = null, array $variables
19051919
protected function getHostSettingsForupdatePet(): array
19061920
{
19071921
return [
1922+
[
1923+
"url" => "http://localhost/v2",
1924+
"description" => "No description provided",
1925+
],
19081926
[
19091927
"url" => "http://petstore.swagger.io/v2",
19101928
"description" => "No description provided",

samples/client/petstore/php/OpenAPIClient-php/tests/AsyncTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class AsyncTest extends TestCase
1616

1717
public function setUp(): void
1818
{
19-
$this->api = new Api\PetApi();
19+
$config = (new Configuration())->setHost('http://localhost/v2');
20+
$this->api = new Api\PetApi(null, $config);
2021

2122
$this->petId = 10005;
2223
$pet = new Model\Pet;

samples/client/petstore/php/OpenAPIClient-php/tests/DebugTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ public static function setUpBeforeClass(): void
1111
parent::setUpBeforeClass();
1212
$newPet = new Model\Pet;
1313
$newPet->setId(1);
14-
$newPet->setName("PHP Unit Test");
15-
(new Api\PetApi())->addPetWithHttpInfo($newPet);
14+
$newPet->setName("PHP Unit Test");
15+
$config = (new Configuration())->setHost('http://localhost/v2');
16+
(new Api\PetApi(null, $config))->addPetWithHttpInfo($newPet);
1617
}
1718

1819
public function testEnableDebugOutput()
1920
{
2021
$this->expectOutputRegex('#GET /v2/pet/1 HTTP/1.1#');
2122

22-
$config = new Configuration();
23+
$config = (new Configuration())->setHost('http://localhost/v2');
2324
$config->setDebug(true);
2425
$api = new Api\PetApi(null, $config);
2526
$api->getPetById(1);
@@ -29,7 +30,7 @@ public function testEnableDebugOutputAsync()
2930
{
3031
$this->expectOutputRegex('#GET /v2/pet/1 HTTP/1.1#');
3132

32-
$config = new Configuration();
33+
$config = (new Configuration())->setHost('http://localhost/v2');
3334
$config->setDebug(true);
3435
$api = new Api\PetApi(null, $config);
3536
$promise = $api->getPetByIdAsync(1);

samples/client/petstore/php/OpenAPIClient-php/tests/PetApiTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,12 @@ public static function setUpBeforeClass(): void
4141

4242
$newPet->setTags(array($tag));
4343
$newPet->setCategory($category);
44-
45-
$config = new Configuration();
46-
$petApi = new Api\PetApi(null, $config);
47-
4844
}
4945

5046
public function setUp(): void
5147
{
52-
$this->api = new Api\PetApi();
48+
$config = (new Configuration())->setHost('http://localhost/v2');
49+
$this->api = new Api\PetApi(null, $config);
5350
}
5451

5552
public function testGetPetById()

0 commit comments

Comments
 (0)