Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add return method value types
  • Loading branch information
guillaume-sainthillier committed Mar 10, 2025
commit 8277aac7d22f61f865f68ad608868d11b92f2f7f
2 changes: 1 addition & 1 deletion src/bref/src/ConsoleApplicationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(Application $application)
$this->application->setAutoExit(false);
}

public function handle($event, Context $context)
public function handle($event, Context $context): array
{
$args = \Clue\Arguments\split((string) $event);
array_unshift($args, 'command');
Expand Down
2 changes: 1 addition & 1 deletion src/bref/src/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getRunner(?object $application): RunnerInterface
}
}

private function tryToFindRunner(?object $application)
private function tryToFindRunner(?object $application): RunnerInterface
{
if ($application instanceof ContainerInterface) {
$handler = explode(':', $_SERVER['_HANDLER']);
Expand Down
32 changes: 16 additions & 16 deletions src/bref/tests/Lambda/LambdaClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ protected function tearDown(): void
ob_end_clean();
}

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

$output = $this->lambda->processNextEvent(new class implements Handler {
public function handle($event, Context $context)
public function handle($event, Context $context): array
{
return ['hello' => 'world'];
}
Expand All @@ -46,12 +46,12 @@ public function handle($event, Context $context)
$this->assertInvocationResult(['hello' => 'world']);
}

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

$this->lambda->processNextEvent(new class implements Handler {
public function handle($event, Context $context)
public function handle($event, Context $context): array
{
return ['hello' => 'world', 'received-function-arn' => $context->getInvokedFunctionArn()];
}
Expand All @@ -63,7 +63,7 @@ public function handle($event, Context $context)
]);
}

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

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

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

Expand All @@ -98,7 +98,7 @@ public function handle($event, Context $context)
]);
}

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

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

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

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

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

$this->lambda->processNextEvent(new class implements Handler {
public function handle($event, Context $context)
public function handle($event, Context $context): string
{
return "\xB1\x31";
}
Expand All @@ -213,7 +213,7 @@ public function handle($event, Context $context)
$this->assertErrorInLogs('Exception', $message);
}

public function test generic event handler()
public function test generic event handler(): void
{
$handler = new class implements Handler {
public function handle($event, Context $context)
Expand Down Expand Up @@ -244,7 +244,7 @@ private function givenAnEvent($event): void
]);
}

private function assertInvocationResult($result)
private function assertInvocationResult($result): void
{
$requests = Server::received();
$this->assertCount(2, $requests);
Expand All @@ -257,7 +257,7 @@ private function assertInvocationResult($result)
$this->assertEquals($result, json_decode($eventResponse->getBody()->__toString(), true));
}

private function assertInvocationErrorResult(string $errorClass, string $errorMessage)
private function assertInvocationErrorResult(string $errorClass, string $errorMessage): void
{
$requests = Server::received();
$this->assertCount(2, $requests);
Expand Down Expand Up @@ -304,7 +304,7 @@ private function assertErrorInLogs(string $errorClass, string $errorMessage): vo
$this->assertIsArray($invocationResult['stack']);
}

private function assertPreviousErrorsInLogs(array $previousErrors)
private function assertPreviousErrorsInLogs(array $previousErrors): void
{
// Decode the logs from stdout
$stdout = $this->getActualOutput();
Expand Down
12 changes: 6 additions & 6 deletions src/bref/tests/SymfonyRequestBridgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class SymfonyRequestBridgeTest extends TestCase
{
public function testClientIpFromForwardedFor()
public function testClientIpFromForwardedFor(): void
{
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
'requestContext' => ['http' => ['method' => 'GET']],
Expand All @@ -23,7 +23,7 @@ public function testClientIpFromForwardedFor()
/**
* Raw content should only exist when there is no multipart content.
*/
public function testRawContent()
public function testRawContent(): void
{
// No content type
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
Expand Down Expand Up @@ -67,7 +67,7 @@ public function testRawContent()
$this->assertSame('', $request->getContent());
}

public function testUploadedFile()
public function testUploadedFile(): void
{
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
'requestContext' => ['http' => ['method' => 'POST']],
Expand Down Expand Up @@ -107,7 +107,7 @@ public function testUploadedFile()
$this->assertSame('bar', $post['foo']);
}

public function testEmptyUploadedFile()
public function testEmptyUploadedFile(): void
{
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
'requestContext' => ['http' => ['method' => 'POST']],
Expand Down Expand Up @@ -136,7 +136,7 @@ public function testEmptyUploadedFile()
$this->assertSame('bar', $post['foo']);
}

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

private function getContext()
private function getContext(): Context
{
// this is set in LaravelHttpHandler and SymfonyHttpHandler to allow overwrite of this value
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);
Expand Down
2 changes: 1 addition & 1 deletion src/google-cloud/google/CloudEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getData()
return $this->data;
}

public static function fromArray(array $arr)
public static function fromArray(array $arr): static
{
$args = [];
$argKeys = [
Expand Down
2 changes: 1 addition & 1 deletion src/google-cloud/google/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getResourceName(): ?string
return $this->resource['name'] ?? null;
}

public static function fromArray(array $arr)
public static function fromArray(array $arr): static
{
// When "resource" is defined in the root (instead of in "context") it
// is a string representing the resource name
Expand Down
2 changes: 1 addition & 1 deletion src/google-cloud/src/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected function createCloudEvent(): ?CloudEvent
}
}

protected function sendHttpResponseAndExit(int $status, string $body, array $headers)
protected function sendHttpResponseAndExit(int $status, string $body, array $headers): void
{
error_log($body);
header('HTTP/1.1 '.$status);
Expand Down
2 changes: 1 addition & 1 deletion src/google-cloud/tests/google/CloudEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
class CloudEventTest extends TestCase
{
public function testJsonSerialize()
public function testJsonSerialize(): void
{
$event = new CloudEvent(
'1413058901901494',
Expand Down
4 changes: 2 additions & 2 deletions src/google-cloud/tests/google/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
class ContextTest extends TestCase
{
public function testFromArray()
public function testFromArray(): void
{
$context = Context::fromArray([
'eventId' => 'abc',
Expand All @@ -45,7 +45,7 @@ public function testFromArray()
$this->assertEquals('mno', $context->getService());
}

public function testFromEmptyArray()
public function testFromEmptyArray(): void
{
$context = Context::fromArray([]);
$this->assertEquals(null, $context->getEventId());
Expand Down
10 changes: 5 additions & 5 deletions src/google-cloud/tests/google/LegacyEventMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
class LegacyEventMapperTest extends TestCase
{
public function testWithContextProperty()
public function testWithContextProperty(): void
{
$mapper = new LegacyEventMapper();
$jsonData = [
Expand Down Expand Up @@ -61,7 +61,7 @@ public function testWithContextProperty()
$this->assertEquals(['message' => 'foo'], $cloudevent->getData());
}

public function testWithoutContextProperty()
public function testWithoutContextProperty(): void
{
$mapper = new LegacyEventMapper();
$jsonData = [
Expand Down Expand Up @@ -95,7 +95,7 @@ public function testWithoutContextProperty()
$this->assertEquals(['message' => 'foo'], $cloudevent->getData());
}

public function testResourceAsString()
public function testResourceAsString(): void
{
$mapper = new LegacyEventMapper();
$jsonData = [
Expand Down Expand Up @@ -126,7 +126,7 @@ public function testResourceAsString()
$this->assertEquals(['message' => 'foo'], $cloudevent->getData());
}

public function testCloudStorage()
public function testCloudStorage(): void
{
$mapper = new LegacyEventMapper();
$jsonData = [
Expand Down Expand Up @@ -163,7 +163,7 @@ public function testCloudStorage()
$this->assertEquals('foo', $cloudevent->getData());
}

public function testFirebaseAuth()
public function testFirebaseAuth(): void
{
$mapper = new LegacyEventMapper();
$jsonData = [
Expand Down
2 changes: 1 addition & 1 deletion src/google-cloud/tests/runtime/AutoDiscoverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class AutoDiscoverTest extends TestCase
{
public function testAutoDiscoverClasses()
public function testAutoDiscoverClasses(): void
{
$classes = [
'Symfony\Runtime\Google\CloudFunctions\CloudEventRuntime',
Expand Down
17 changes: 9 additions & 8 deletions src/google-cloud/tests/runtime/RuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Runtime\GoogleCloud\Tests;

use Google\CloudFunctions\CloudEvent;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Runtime\GoogleCloud\Runtime;
use Symfony\Component\Runtime\RuntimeInterface;

class RuntimeTest extends TestCase
{
public function testStructuredType()
public function testStructuredType(): void
{
$input = [
'id' => '1234567890',
Expand All @@ -28,7 +29,7 @@ public function testStructuredType()
$this->assertSame('com.google.cloud.pubsub.topic.publish', $output->getType());
}

public function testLegacyType()
public function testLegacyType(): void
{
$input = [
'data' => 'foo',
Expand All @@ -54,7 +55,7 @@ public function testLegacyType()
$this->assertSame('google.cloud.pubsub.topic.v1.messagePublished', $output->getType());
}

public function testValidateJsonWithJsonContentType()
public function testValidateJsonWithJsonContentType(): void
{
$runtime = $this->getRuntimeMock();
$runtime->method('getBody')->willReturn('not json');
Expand All @@ -64,7 +65,7 @@ public function testValidateJsonWithJsonContentType()
$this->invokeCreateCloudEvent($runtime);
}

public function testValidateJsonWithStructuredType()
public function testValidateJsonWithStructuredType(): void
{
$runtime = $this->getRuntimeMock();
$runtime->method('getBody')->willReturn('not json');
Expand All @@ -74,7 +75,7 @@ public function testValidateJsonWithStructuredType()
$this->invokeCreateCloudEvent($runtime);
}

public function testValidateJsonWithLegacyType()
public function testValidateJsonWithLegacyType(): void
{
$runtime = $this->getRuntimeMock();
$runtime->method('getBody')->willReturn('not json');
Expand All @@ -84,7 +85,7 @@ public function testValidateJsonWithLegacyType()
$this->invokeCreateCloudEvent($runtime);
}

public function testNoValidateJsonWithBinaryType()
public function testNoValidateJsonWithBinaryType(): void
{
$runtime = $this->getRuntimeMock();
$runtime->method('getBody')->willReturn('not json');
Expand All @@ -110,9 +111,9 @@ private function invokeCreateCloudEvent(RuntimeInterface $runtime): ?CloudEvent
}

/**
* @return \PHPUnit\Framework\MockObject\MockObject|Runtime
* @return MockObject&Runtime
*/
private function getRuntimeMock()
private function getRuntimeMock(): mixed
{
$runtime = $this->getMockBuilder(Runtime::class)
->disableOriginalConstructor()
Expand Down
5 changes: 1 addition & 4 deletions src/psr-17/src/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ protected static function register(GenericRuntime $runtime): GenericRuntime
return $self;
}

/**
* @return ServerRequestInterface
*/
private function createRequest()
private function createRequest(): ServerRequestInterface
{
if (null === $this->requestCreator) {
$creatorClass = $this->options['server_request_creator'] ?? ServerRequestCreator::class;
Expand Down
Loading
Loading