Skip to content

Commit faeca18

Browse files
authored
chore(functions): miscellaneous changes (GoogleCloudPlatform#1314)
1 parent 7ff5022 commit faeca18

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

functions/helloworld_http/SampleUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testFunction(): void
4040
$request = new ServerRequest('POST', '/', [], json_encode(['name' => $name]));
4141
$expected = sprintf('Hello, %s!', $name);
4242
$actual = helloHttp($request);
43-
$this->assertStringContainsString($expected, $actual);
43+
$this->assertEquals($expected, $actual);
4444
}
4545
}
4646

functions/helloworld_pubsub/index.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,18 @@
1919

2020
use Google\CloudFunctions\CloudEvent;
2121

22-
function helloworldPubsub(CloudEvent $event): string
22+
function helloworldPubsub(CloudEvent $event): void
2323
{
2424
$log = fopen(getenv('LOGGER_OUTPUT') ?: 'php://stderr', 'wb');
25-
26-
$data = $event->getData();
27-
if (isset($data['data'])) {
28-
$name = htmlspecialchars(base64_decode($data['data']));
25+
26+
$cloudEventData = $event->getData();
27+
if (isset($cloudEventData['data'])) {
28+
$name = htmlspecialchars(base64_decode($cloudEventData['data']));
2929
} else {
3030
$name = 'World';
3131
}
3232

3333
$result = 'Hello, ' . $name . '!';
3434
fwrite($log, $result . PHP_EOL);
35-
return $result;
3635
}
3736
// [END functions_helloworld_pubsub]

functions/tips_infinite_retries/index.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
use Google\CloudFunctions\CloudEvent;
2929

30-
function avoidInfiniteRetries(CloudEvent $event): string
30+
function avoidInfiniteRetries(CloudEvent $event): void
3131
{
3232
$log = fopen(getenv('LOGGER_OUTPUT') ?: 'php://stderr', 'wb');
3333

@@ -42,7 +42,7 @@ function avoidInfiniteRetries(CloudEvent $event): string
4242
// Ignore events that are too old
4343
if ($eventAge > $maxAge) {
4444
fwrite($log, 'Dropping event ' . $eventId . ' with age ' . $eventAge . ' seconds' . PHP_EOL);
45-
return '';
45+
return;
4646
}
4747

4848
// Do what the function is supposed to do
@@ -53,7 +53,5 @@ function avoidInfiniteRetries(CloudEvent $event): string
5353
if ($failed) {
5454
throw new Exception('Event ' . $eventId . ' failed; retrying...');
5555
}
56-
57-
return '';
5856
}
5957
// [END functions_tips_infinite_retries]

functions/tips_retry/index.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
use Google\CloudFunctions\CloudEvent;
2121

22-
function tipsRetry(CloudEvent $event): string
22+
function tipsRetry(CloudEvent $event): void
2323
{
2424
$data = $event->getData()['data'];
2525
$data = json_decode(base64_decode($data), true);
@@ -35,15 +35,13 @@ function tipsRetry(CloudEvent $event): string
3535
* invocation to be re-sent.
3636
*/
3737
throw new Exception('Intermittent failure occurred; retrying...');
38-
} else {
39-
/**
40-
* If a function with retries enabled encounters a non-retriable
41-
* failure, it should return *without* throwing an exception.
42-
*/
43-
$log = fopen(getenv('LOGGER_OUTPUT') ?: 'php://stderr', 'wb');
44-
fwrite($log, "Not retrying" . PHP_EOL);
45-
46-
return "";
4738
}
39+
40+
/**
41+
* If a function with retries enabled encounters a non-retriable
42+
* failure, it should return *without* throwing an exception.
43+
*/
44+
$log = fopen(getenv('LOGGER_OUTPUT') ?: 'php://stderr', 'wb');
45+
fwrite($log, "Not retrying" . PHP_EOL);
4846
}
4947
// [END functions_tips_retry]

0 commit comments

Comments
 (0)