Skip to content

Commit 4852a3d

Browse files
authored
Merge pull request #136 from php-api-clients/generate-tests
Generate Operation tests
2 parents 97423a4 + bc2dd02 commit 4852a3d

40 files changed

+12136
-2338
lines changed

.github/workflows/single-client.yaml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Continuous Integration
2+
on:
3+
push:
4+
branches:
5+
- 'main'
6+
- 'master'
7+
- 'refs/heads/v[0-9]+.[0-9]+.[0-9]+'
8+
pull_request:
9+
jobs:
10+
generate-and-test-client:
11+
runs-on: ubuntu-latest
12+
name: Generate and test client
13+
container:
14+
image: ghcr.io/wyrihaximusnet/php:8.2-nts-alpine-dev-root
15+
steps:
16+
- uses: actions/checkout@v3
17+
with:
18+
fetch-depth: '0'
19+
persist-credentials: 'false'
20+
- uses: "ramsey/composer-install@v2"
21+
- run: make generate-example-client-one
22+
- name: Tar example files
23+
run: tar -czf example.tar ./example
24+
- name: Upload Generated Client
25+
uses: actions/upload-artifact@v3
26+
with:
27+
name: example-single-client
28+
path: ./example.tar
29+
supported-versions-matrix:
30+
name: Supported Versions Matrix
31+
runs-on: ubuntu-latest
32+
outputs:
33+
version: ${{ steps.supported-versions-matrix.outputs.version }}
34+
upcoming: ${{ steps.supported-versions-matrix.outputs.upcoming }}
35+
steps:
36+
- uses: actions/checkout@v3
37+
- id: supported-versions-matrix
38+
uses: WyriHaximus/github-action-composer-php-versions-in-range@v1
39+
with:
40+
upcomingReleases: true
41+
supported-checks-matrix:
42+
name: Supported Checks Matrix
43+
runs-on: ubuntu-latest
44+
needs:
45+
- generate-and-test-client
46+
outputs:
47+
check: ${{ steps.supported-checks-matrix.outputs.check }}
48+
steps:
49+
- uses: actions/checkout@v3
50+
- name: Download Generated Client
51+
uses: actions/download-artifact@v3
52+
with:
53+
name: example-single-client
54+
path: ./
55+
- name: UnTar example files
56+
run: tar -xzf example.tar
57+
- id: supported-checks-matrix
58+
name: Generate check
59+
run: |
60+
cd example/generated
61+
printf "Checks found: %s\r\n" $(make task-list-ci)
62+
printf "::set-output name=check::%s" $(make task-list-ci)
63+
qa:
64+
name: Run ${{ matrix.check }} on PHP ${{ matrix.php }} with ${{ matrix.composer }} dependency preference
65+
strategy:
66+
fail-fast: false
67+
matrix:
68+
php: ${{ fromJson(needs.supported-versions-matrix.outputs.version) }}
69+
composer: [lowest, locked, highest]
70+
check: ${{ fromJson(needs.supported-checks-matrix.outputs.check) }}
71+
needs:
72+
- supported-checks-matrix
73+
- supported-versions-matrix
74+
- generate-and-test-client
75+
runs-on: ubuntu-latest
76+
container:
77+
image: ghcr.io/wyrihaximusnet/php:${{ matrix.php }}-nts-alpine-dev-root
78+
steps:
79+
- uses: actions/checkout@v3
80+
with:
81+
fetch-depth: 0 # Required due to the way Git works, without it this action won't be able to find any or the correct tags
82+
- run: git config --global --add safe.directory $GITHUB_WORKSPACE # Do this ourself because `actions/checkout@v3 doesn't succeed in doing this
83+
- name: Download Generated Client
84+
uses: actions/download-artifact@v3
85+
with:
86+
name: example-single-client
87+
path: ./
88+
- name: UnTar example files
89+
run: tar -xzf example.tar
90+
- uses: ramsey/composer-install@v2
91+
with:
92+
working-directory: "example/generated/"
93+
ignore-cache: "yes"
94+
- run: |
95+
cd example/generated
96+
make ${{ matrix.check }} || true
97+
if: needs.supported-versions-matrix.outputs.upcoming == matrix.php
98+
env:
99+
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
100+
COVERALLS_RUN_LOCALLY: ${{ secrets.COVERALLS_RUN_LOCALLY }}
101+
- run: |
102+
cd example/generated
103+
make ${{ matrix.check }}
104+
if: needs.supported-versions-matrix.outputs.upcoming != matrix.php
105+
env:
106+
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
107+
COVERALLS_RUN_LOCALLY: ${{ secrets.COVERALLS_RUN_LOCALLY }}
108+
check-mark:
109+
name: ✔️
110+
needs:
111+
- qa
112+
runs-on: ubuntu-latest
113+
steps:
114+
- run: echo "✔️"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
bin/openapi-client-generator
2+
example/etc
23
example/generated
34
example/generated-subsplit
45
vendor

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,10 @@ help: ## Show this help ###
7070
@printf "\033[33mUsage:\033[0m\n make [target]\n\n\033[33mTargets:\033[0m\n"
7171
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-32s\033[0m %s\n", $$1, $$2}' | tr -d '#'
7272

73-
generate-example-client:
74-
$(DOCKER_RUN) php ./bin/openapi-client-generator ./example/openapi-client.yaml
73+
generate-example-clients: generate-example-client-one generate-example-client-subsplit
74+
75+
generate-example-client-one:
76+
$(DOCKER_RUN) php ./bin/openapi-client-generator ./example/openapi-client-one.yaml
77+
78+
generate-example-client-subsplit:
79+
$(DOCKER_RUN) php ./bin/openapi-client-generator ./example/openapi-client-subsplit.yaml

bin/openapi-client-generator.source

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ use Symfony\Component\Yaml\Yaml;
2222
(new Generator(
2323
$configuration->spec
2424
))->generate(
25-
$configuration->namespace . '\\',
26-
dirname($configurationFile) . DIRECTORY_SEPARATOR . $configuration->destination->root . DIRECTORY_SEPARATOR,
25+
$configuration->namespace->source . '\\',
26+
$configuration->namespace->test . '\\',
27+
dirname($configurationFile) . DIRECTORY_SEPARATOR,
2728
$configuration,
2829
);
2930

composer.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
"ckr/arraymerger": "^3.0",
3939
"ramsey/uuid": "^4.7",
4040
"wyrihaximus/subsplit-tools": "dev-main",
41-
"wyrihaximus/simple-twig": "^2.1"
41+
"wyrihaximus/simple-twig": "^2.1",
42+
"wyrihaximus/async-test-utilities": "^6.1",
43+
"api-clients/github": "^0.2@dev",
44+
"delight-im/random": "^1.0"
4245
},
4346
"autoload": {
4447
"psr-4": {
@@ -54,17 +57,20 @@
5457
"external_files/thephpleague/Type.php"
5558
]
5659
},
60+
"autoload-dev": {
61+
"psr-4": {
62+
"ApiClients\\Tests\\Tools\\OpenApiClientGenerator\\": "tests/"
63+
}
64+
},
5765
"config": {
5866
"platform": {
5967
"php": "8.2.13"
6068
},
6169
"allow-plugins": {
62-
"wyrihaximus/composer-update-bin-autoload-path": true
63-
}
64-
},
65-
"autoload-dev": {
66-
"psr-4": {
67-
"ApiClients\\Tests\\Tools\\OpenApiClientGenerator\\": "tests/"
70+
"wyrihaximus/composer-update-bin-autoload-path": true,
71+
"infection/extension-installer": true,
72+
"dealerdirect/phpcodesniffer-composer-installer": true,
73+
"ergebnis/composer-normalize": true
6874
}
6975
}
7076
}

0 commit comments

Comments
 (0)