Skip to content

Commit 8277aac

Browse files
add return method value types
1 parent 8c4d4fc commit 8277aac

21 files changed

+54
-62
lines changed

src/bref/src/ConsoleApplicationHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(Application $application)
2323
$this->application->setAutoExit(false);
2424
}
2525

26-
public function handle($event, Context $context)
26+
public function handle($event, Context $context): array
2727
{
2828
$args = \Clue\Arguments\split((string) $event);
2929
array_unshift($args, 'command');

src/bref/src/Runtime.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function getRunner(?object $application): RunnerInterface
4646
}
4747
}
4848

49-
private function tryToFindRunner(?object $application)
49+
private function tryToFindRunner(?object $application): RunnerInterface
5050
{
5151
if ($application instanceof ContainerInterface) {
5252
$handler = explode(':', $_SERVER['_HANDLER']);

src/bref/tests/Lambda/LambdaClientTest.php

+16-16
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ protected function tearDown(): void
3131
ob_end_clean();
3232
}
3333

34-
public function test basic behavior()
34+
public function test basic behavior(): void
3535
{
3636
$this->givenAnEvent(['Hello' => 'world!']);
3737

3838
$output = $this->lambda->processNextEvent(new class implements Handler {
39-
public function handle($event, Context $context)
39+
public function handle($event, Context $context): array
4040
{
4141
return ['hello' => 'world'];
4242
}
@@ -46,12 +46,12 @@ public function handle($event, Context $context)
4646
$this->assertInvocationResult(['hello' => 'world']);
4747
}
4848

49-
public function test handler receives context()
49+
public function test handler receives context(): void
5050
{
5151
$this->givenAnEvent(['Hello' => 'world!']);
5252

5353
$this->lambda->processNextEvent(new class implements Handler {
54-
public function handle($event, Context $context)
54+
public function handle($event, Context $context): array
5555
{
5656
return ['hello' => 'world', 'received-function-arn' => $context->getInvokedFunctionArn()];
5757
}
@@ -63,7 +63,7 @@ public function handle($event, Context $context)
6363
]);
6464
}
6565

66-
public function test exceptions in the handler result in an invocation error()
66+
public function test exceptions in the handler result in an invocation error(): void
6767
{
6868
$this->givenAnEvent(['Hello' => 'world!']);
6969

@@ -79,7 +79,7 @@ public function handle($event, Context $context)
7979
$this->assertErrorInLogs('RuntimeException', 'This is an exception');
8080
}
8181

82-
public function test nested exceptions in the handler result in an invocation error()
82+
public function test nested exceptions in the handler result in an invocation error(): void
8383
{
8484
$this->givenAnEvent(['Hello' => 'world!']);
8585

@@ -98,7 +98,7 @@ public function handle($event, Context $context)
9898
]);
9999
}
100100

101-
public function test an error is thrown if the runtime API returns a wrong response()
101+
public function test an error is thrown if the runtime API returns a wrong response(): void
102102
{
103103
$this->expectExceptionMessage('Failed to fetch next Lambda invocation: The requested URL returned error: 404');
104104
Server::enqueue([
@@ -118,7 +118,7 @@ public function handle($event, Context $context)
118118
});
119119
}
120120

121-
public function test an error is thrown if the invocation id is missing()
121+
public function test an error is thrown if the invocation id is missing(): void
122122
{
123123
$this->expectExceptionMessage('Failed to determine the Lambda invocation ID');
124124
Server::enqueue([
@@ -136,7 +136,7 @@ public function handle($event, Context $context)
136136
});
137137
}
138138

139-
public function test an error is thrown if the invocation body is empty()
139+
public function test an error is thrown if the invocation body is empty(): void
140140
{
141141
$this->expectExceptionMessage('Empty Lambda runtime API response');
142142
Server::enqueue([
@@ -155,7 +155,7 @@ public function handle($event, Context $context)
155155
});
156156
}
157157

158-
public function test a wrong response from the runtime API turns the invocation into an error()
158+
public function test a wrong response from the runtime API turns the invocation into an error(): void
159159
{
160160
Server::enqueue([
161161
new Response( // lambda event
@@ -193,12 +193,12 @@ public function handle($event, Context $context)
193193
$this->assertErrorInLogs('Exception', 'Error while calling the Lambda runtime API: The requested URL returned error: 400');
194194
}
195195

196-
public function test function results that cannot be encoded are reported as invocation errors()
196+
public function test function results that cannot be encoded are reported as invocation errors(): void
197197
{
198198
$this->givenAnEvent(['hello' => 'world!']);
199199

200200
$this->lambda->processNextEvent(new class implements Handler {
201-
public function handle($event, Context $context)
201+
public function handle($event, Context $context): string
202202
{
203203
return "\xB1\x31";
204204
}
@@ -213,7 +213,7 @@ public function handle($event, Context $context)
213213
$this->assertErrorInLogs('Exception', $message);
214214
}
215215

216-
public function test generic event handler()
216+
public function test generic event handler(): void
217217
{
218218
$handler = new class implements Handler {
219219
public function handle($event, Context $context)
@@ -244,7 +244,7 @@ private function givenAnEvent($event): void
244244
]);
245245
}
246246

247-
private function assertInvocationResult($result)
247+
private function assertInvocationResult($result): void
248248
{
249249
$requests = Server::received();
250250
$this->assertCount(2, $requests);
@@ -257,7 +257,7 @@ private function assertInvocationResult($result)
257257
$this->assertEquals($result, json_decode($eventResponse->getBody()->__toString(), true));
258258
}
259259

260-
private function assertInvocationErrorResult(string $errorClass, string $errorMessage)
260+
private function assertInvocationErrorResult(string $errorClass, string $errorMessage): void
261261
{
262262
$requests = Server::received();
263263
$this->assertCount(2, $requests);
@@ -304,7 +304,7 @@ private function assertErrorInLogs(string $errorClass, string $errorMessage): vo
304304
$this->assertIsArray($invocationResult['stack']);
305305
}
306306

307-
private function assertPreviousErrorsInLogs(array $previousErrors)
307+
private function assertPreviousErrorsInLogs(array $previousErrors): void
308308
{
309309
// Decode the logs from stdout
310310
$stdout = $this->getActualOutput();

src/bref/tests/SymfonyRequestBridgeTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class SymfonyRequestBridgeTest extends TestCase
1313
{
14-
public function testClientIpFromForwardedFor()
14+
public function testClientIpFromForwardedFor(): void
1515
{
1616
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
1717
'requestContext' => ['http' => ['method' => 'GET']],
@@ -23,7 +23,7 @@ public function testClientIpFromForwardedFor()
2323
/**
2424
* Raw content should only exist when there is no multipart content.
2525
*/
26-
public function testRawContent()
26+
public function testRawContent(): void
2727
{
2828
// No content type
2929
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
@@ -67,7 +67,7 @@ public function testRawContent()
6767
$this->assertSame('', $request->getContent());
6868
}
6969

70-
public function testUploadedFile()
70+
public function testUploadedFile(): void
7171
{
7272
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
7373
'requestContext' => ['http' => ['method' => 'POST']],
@@ -107,7 +107,7 @@ public function testUploadedFile()
107107
$this->assertSame('bar', $post['foo']);
108108
}
109109

110-
public function testEmptyUploadedFile()
110+
public function testEmptyUploadedFile(): void
111111
{
112112
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
113113
'requestContext' => ['http' => ['method' => 'POST']],
@@ -136,7 +136,7 @@ public function testEmptyUploadedFile()
136136
$this->assertSame('bar', $post['foo']);
137137
}
138138

139-
public function testLambdaContext()
139+
public function testLambdaContext(): void
140140
{
141141
$requestContext = ['http' => ['method' => 'GET']];
142142
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
@@ -149,7 +149,7 @@ public function testLambdaContext()
149149
$this->assertSame(json_encode($requestContext), $request->server->get('LAMBDA_REQUEST_CONTEXT'));
150150
}
151151

152-
private function getContext()
152+
private function getContext(): Context
153153
{
154154
// this is set in LaravelHttpHandler and SymfonyHttpHandler to allow overwrite of this value
155155
Request::setTrustedProxies(['127.0.0.1'], Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO);

src/google-cloud/google/CloudEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function getData()
8080
return $this->data;
8181
}
8282

83-
public static function fromArray(array $arr)
83+
public static function fromArray(array $arr): static
8484
{
8585
$args = [];
8686
$argKeys = [

src/google-cloud/google/Context.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function getResourceName(): ?string
5454
return $this->resource['name'] ?? null;
5555
}
5656

57-
public static function fromArray(array $arr)
57+
public static function fromArray(array $arr): static
5858
{
5959
// When "resource" is defined in the root (instead of in "context") it
6060
// is a string representing the resource name

src/google-cloud/src/Runtime.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected function createCloudEvent(): ?CloudEvent
9090
}
9191
}
9292

93-
protected function sendHttpResponseAndExit(int $status, string $body, array $headers)
93+
protected function sendHttpResponseAndExit(int $status, string $body, array $headers): void
9494
{
9595
error_log($body);
9696
header('HTTP/1.1 '.$status);

src/google-cloud/tests/google/CloudEventTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
class CloudEventTest extends TestCase
2828
{
29-
public function testJsonSerialize()
29+
public function testJsonSerialize(): void
3030
{
3131
$event = new CloudEvent(
3232
'1413058901901494',

src/google-cloud/tests/google/ContextTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
class ContextTest extends TestCase
2828
{
29-
public function testFromArray()
29+
public function testFromArray(): void
3030
{
3131
$context = Context::fromArray([
3232
'eventId' => 'abc',
@@ -45,7 +45,7 @@ public function testFromArray()
4545
$this->assertEquals('mno', $context->getService());
4646
}
4747

48-
public function testFromEmptyArray()
48+
public function testFromEmptyArray(): void
4949
{
5050
$context = Context::fromArray([]);
5151
$this->assertEquals(null, $context->getEventId());

src/google-cloud/tests/google/LegacyEventMapperTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
class LegacyEventMapperTest extends TestCase
2828
{
29-
public function testWithContextProperty()
29+
public function testWithContextProperty(): void
3030
{
3131
$mapper = new LegacyEventMapper();
3232
$jsonData = [
@@ -61,7 +61,7 @@ public function testWithContextProperty()
6161
$this->assertEquals(['message' => 'foo'], $cloudevent->getData());
6262
}
6363

64-
public function testWithoutContextProperty()
64+
public function testWithoutContextProperty(): void
6565
{
6666
$mapper = new LegacyEventMapper();
6767
$jsonData = [
@@ -95,7 +95,7 @@ public function testWithoutContextProperty()
9595
$this->assertEquals(['message' => 'foo'], $cloudevent->getData());
9696
}
9797

98-
public function testResourceAsString()
98+
public function testResourceAsString(): void
9999
{
100100
$mapper = new LegacyEventMapper();
101101
$jsonData = [
@@ -126,7 +126,7 @@ public function testResourceAsString()
126126
$this->assertEquals(['message' => 'foo'], $cloudevent->getData());
127127
}
128128

129-
public function testCloudStorage()
129+
public function testCloudStorage(): void
130130
{
131131
$mapper = new LegacyEventMapper();
132132
$jsonData = [
@@ -163,7 +163,7 @@ public function testCloudStorage()
163163
$this->assertEquals('foo', $cloudevent->getData());
164164
}
165165

166-
public function testFirebaseAuth()
166+
public function testFirebaseAuth(): void
167167
{
168168
$mapper = new LegacyEventMapper();
169169
$jsonData = [

src/google-cloud/tests/runtime/AutoDiscoverTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class AutoDiscoverTest extends TestCase
99
{
10-
public function testAutoDiscoverClasses()
10+
public function testAutoDiscoverClasses(): void
1111
{
1212
$classes = [
1313
'Symfony\Runtime\Google\CloudFunctions\CloudEventRuntime',

src/google-cloud/tests/runtime/RuntimeTest.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
namespace Runtime\GoogleCloud\Tests;
44

55
use Google\CloudFunctions\CloudEvent;
6+
use PHPUnit\Framework\MockObject\MockObject;
67
use PHPUnit\Framework\TestCase;
78
use Runtime\GoogleCloud\Runtime;
89
use Symfony\Component\Runtime\RuntimeInterface;
910

1011
class RuntimeTest extends TestCase
1112
{
12-
public function testStructuredType()
13+
public function testStructuredType(): void
1314
{
1415
$input = [
1516
'id' => '1234567890',
@@ -28,7 +29,7 @@ public function testStructuredType()
2829
$this->assertSame('com.google.cloud.pubsub.topic.publish', $output->getType());
2930
}
3031

31-
public function testLegacyType()
32+
public function testLegacyType(): void
3233
{
3334
$input = [
3435
'data' => 'foo',
@@ -54,7 +55,7 @@ public function testLegacyType()
5455
$this->assertSame('google.cloud.pubsub.topic.v1.messagePublished', $output->getType());
5556
}
5657

57-
public function testValidateJsonWithJsonContentType()
58+
public function testValidateJsonWithJsonContentType(): void
5859
{
5960
$runtime = $this->getRuntimeMock();
6061
$runtime->method('getBody')->willReturn('not json');
@@ -64,7 +65,7 @@ public function testValidateJsonWithJsonContentType()
6465
$this->invokeCreateCloudEvent($runtime);
6566
}
6667

67-
public function testValidateJsonWithStructuredType()
68+
public function testValidateJsonWithStructuredType(): void
6869
{
6970
$runtime = $this->getRuntimeMock();
7071
$runtime->method('getBody')->willReturn('not json');
@@ -74,7 +75,7 @@ public function testValidateJsonWithStructuredType()
7475
$this->invokeCreateCloudEvent($runtime);
7576
}
7677

77-
public function testValidateJsonWithLegacyType()
78+
public function testValidateJsonWithLegacyType(): void
7879
{
7980
$runtime = $this->getRuntimeMock();
8081
$runtime->method('getBody')->willReturn('not json');
@@ -84,7 +85,7 @@ public function testValidateJsonWithLegacyType()
8485
$this->invokeCreateCloudEvent($runtime);
8586
}
8687

87-
public function testNoValidateJsonWithBinaryType()
88+
public function testNoValidateJsonWithBinaryType(): void
8889
{
8990
$runtime = $this->getRuntimeMock();
9091
$runtime->method('getBody')->willReturn('not json');
@@ -110,9 +111,9 @@ private function invokeCreateCloudEvent(RuntimeInterface $runtime): ?CloudEvent
110111
}
111112

112113
/**
113-
* @return \PHPUnit\Framework\MockObject\MockObject|Runtime
114+
* @return MockObject&Runtime
114115
*/
115-
private function getRuntimeMock()
116+
private function getRuntimeMock(): mixed
116117
{
117118
$runtime = $this->getMockBuilder(Runtime::class)
118119
->disableOriginalConstructor()

src/psr-17/src/Runtime.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ protected static function register(GenericRuntime $runtime): GenericRuntime
6868
return $self;
6969
}
7070

71-
/**
72-
* @return ServerRequestInterface
73-
*/
74-
private function createRequest()
71+
private function createRequest(): ServerRequestInterface
7572
{
7673
if (null === $this->requestCreator) {
7774
$creatorClass = $this->options['server_request_creator'] ?? ServerRequestCreator::class;

0 commit comments

Comments
 (0)