Skip to content

Commit 4a4abeb

Browse files
chore: add conformance test coverage for typed function signature (#151)
Co-authored-by: Kayla Nguyen <[email protected]>
1 parent 2a99824 commit 4a4abeb

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

.github/workflows/conformance.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,51 +48,58 @@ jobs:
4848
- name: Setup Go
4949
uses: actions/setup-go@bfdd3570ce990073878bf10f6b2d79082de49492 # v2.2.0
5050
with:
51-
go-version: '1.15'
51+
go-version: '1.20'
5252

5353
- name: Run HTTP conformance tests
54-
uses: GoogleCloudPlatform/functions-framework-conformance/action@e42b1533877f1b639f508ec7fbcfb5be31aca663 # v1.2.1
54+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
5555
env:
5656
FUNCTION_TARGET: 'httpFunc'
5757
FUNCTION_SIGNATURE_TYPE: 'http'
5858
FUNCTION_SOURCE: ${{ github.workspace }}/tests/conformance/index.php
5959
with:
60-
version: 'v1.2.1'
6160
functionType: 'http'
6261
useBuildpacks: false
6362
cmd: "'php -S localhost:8080 router.php'"
6463

6564
- name: Run Declarative HTTP conformance tests
66-
uses: GoogleCloudPlatform/functions-framework-conformance/action@e42b1533877f1b639f508ec7fbcfb5be31aca663 # v1.2.1
65+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
6766
env:
6867
FUNCTION_TARGET: 'declarativeHttpFunc'
6968
FUNCTION_SOURCE: ${{ github.workspace }}/tests/conformance/index.php
7069
with:
71-
version: 'v1.2.1'
7270
functionType: 'http'
7371
useBuildpacks: false
7472
cmd: "'php -S localhost:8080 router.php'"
73+
74+
- name: Run Declarative Typed conformance tests
75+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
76+
env:
77+
FUNCTION_TARGET: 'declarativeTypedFunc'
78+
FUNCTION_SOURCE: ${{ github.workspace }}/tests/conformance/index.php
79+
with:
80+
functionType: 'http'
81+
declarativeType: 'typed'
82+
useBuildpacks: false
83+
cmd: "'php -S localhost:8080 router.php'"
7584

7685
- name: Run CloudEvent conformance tests
77-
uses: GoogleCloudPlatform/functions-framework-conformance/action@e42b1533877f1b639f508ec7fbcfb5be31aca663 # v1.2.1
86+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
7887
env:
7988
FUNCTION_TARGET: 'cloudEventFunc'
8089
FUNCTION_SIGNATURE_TYPE: 'cloudevent'
8190
FUNCTION_SOURCE: ${{ github.workspace }}/tests/conformance/index.php
8291
with:
83-
version: 'v1.2.1'
8492
functionType: 'cloudevent'
8593
useBuildpacks: false
8694
validateMapping: true
8795
cmd: "'php -S localhost:8080 router.php'"
8896

8997
- name: Run Declarative CloudEvent conformance tests
90-
uses: GoogleCloudPlatform/functions-framework-conformance/action@e42b1533877f1b639f508ec7fbcfb5be31aca663 # v1.2.1
98+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.2.1
9199
env:
92100
FUNCTION_TARGET: 'declarativeCloudEventFunc'
93101
FUNCTION_SOURCE: ${{ github.workspace }}/tests/conformance/index.php
94102
with:
95-
version: 'v1.2.1'
96103
functionType: 'cloudevent'
97104
useBuildpacks: false
98105
validateMapping: true

tests/conformance/index.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,37 @@ function httpFunc(ServerRequestInterface $request)
1616
return "ok" . PHP_EOL;
1717
}
1818

19+
FunctionsFramework::typed('declarativeTypedFunc', 'typedFunc');
20+
21+
function typedFunc(ConformanceRequest $request)
22+
{
23+
$resp = new ConformanceResponse();
24+
$resp->payload = $request;
25+
return $resp;
26+
}
27+
28+
class ConformanceRequest
29+
{
30+
/** @var string */
31+
public $message;
32+
33+
public function mergeFromJsonString(string $body): void
34+
{
35+
$this->message = json_decode($body)->message;
36+
}
37+
}
38+
39+
class ConformanceResponse
40+
{
41+
/** @var ConformanceRequest */
42+
public $payload;
43+
44+
public function serializeToJsonString()
45+
{
46+
return json_encode(get_object_vars($this));
47+
}
48+
}
49+
1950
// PHP cannot distinguish between an empty array and an empty map because they
2051
// are represented by the same type. This means that when a JSON object
2152
// containing either an empty array or an empty map is decoded the type

tests/conformance/run_conformance_tests.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ print_header "HTTP CONFORMANCE TESTS"
4949
FUNCTION_TARGET='httpFunc' FUNCTION_SIGNATURE_TYPE='http' FUNCTION_SOURCE=$(realpath tests/conformance/index.php) client -buildpacks=false -type=http -cmd='php -S localhost:8080 router.php' -start-delay 5 -validate-mapping=true
5050

5151
print_header "DECLARATIVE HTTP CONFORMANCE TESTS"
52-
FUNCTION_TARGET='declarativeHttpFunc' FUNCTION_SIGNATURE_TYPE= FUNCTION_SOURCE=$(realpath tests/conformance/index.php) client -buildpacks=false -type=http -cmd='php -S localhost:8080 router.php' -start-delay 5 -validate-mapping=true
52+
FUNCTION_TARGET='declarativeHttpFunc' FUNCTION_SIGNATURE_TYPE= FUNCTION_SOURCE=$(realpath tests/conformance/index.php) client -buildpacks=false -type=http -cmd='php -S localhost:8080 router.php' -start-delay 5 -validate-mapping=true
53+
54+
print_header "DECLARATIVE TYPED CONFORMANCE TESTS"
55+
FUNCTION_TARGET='declarativeTypedFunc' FUNCTION_SIGNATURE_TYPE=http FUNCTION_SOURCE=$(realpath tests/conformance/index.php) client -buildpacks=false -type=http -declarative-type=typed -cmd='php -S localhost:8080 router.php' -start-delay 5 -validate-mapping=true
5356

5457
print_header "CLOUDEVENT CONFORMANCE TESTS"
5558
FUNCTION_TARGET='cloudEventFunc' FUNCTION_SIGNATURE_TYPE='cloudevent' FUNCTION_SOURCE=$(realpath tests/conformance/index.php) client -buildpacks=false -type=cloudevent -cmd='php -S localhost:8080 router.php' -start-delay 5 -validate-mapping=true

0 commit comments

Comments
 (0)