From 91cd8639ce99775822fee2975a7ca681be22e171 Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 10:42:24 +0000 Subject: [PATCH 01/17] fix: PHPStan up to level 1 --- phpstan.neon | 7 +++++++ test/unit/StackdriverRequestLoggerTest.php | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 phpstan.neon diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..01f2120 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + level: 1 + paths: + - src + - test + excludePaths: + - test/blackbox/implementation/htdocs/dynamic diff --git a/test/unit/StackdriverRequestLoggerTest.php b/test/unit/StackdriverRequestLoggerTest.php index 3aba2dd..33add54 100644 --- a/test/unit/StackdriverRequestLoggerTest.php +++ b/test/unit/StackdriverRequestLoggerTest.php @@ -9,6 +9,7 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Log\Test\TestLogger; +use RuntimeException; class StackdriverRequestLoggerTest extends TestCase { @@ -119,10 +120,13 @@ protected function getMicrotime(): float return $subject; } + /** + * @return StackdriverApplicationLogger&object{request_log_calls: array} + */ public function makeLoggerSpy(): StackdriverApplicationLogger { return new class extends StackdriverApplicationLogger { - public readonly array $request_log_calls; + public private(set) array $request_log_calls; public function __construct() { @@ -130,6 +134,9 @@ public function __construct() public function logRequest(ServerGlobal $server = new ServerGlobal(), ?float $request_start_time = null): void { + if (isset($this->request_log_calls)) { + throw new RuntimeException('logRequest called more than once'); + } $this->request_log_calls = get_defined_vars(); } }; From 532d15526bb6cb8f52c5fa22d4901fd8bc827f48 Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 10:44:17 +0000 Subject: [PATCH 02/17] fix: PHPStan up to level 2 --- phpstan.neon | 2 +- src/FactoryFunction.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 01f2120..f1edadb 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 1 + level: 2 paths: - src - test diff --git a/src/FactoryFunction.php b/src/FactoryFunction.php index cd87ec5..31bebd3 100644 --- a/src/FactoryFunction.php +++ b/src/FactoryFunction.php @@ -18,13 +18,13 @@ class FactoryFunction * // Whereas this will throw an UnexpectedValueException * $stdclass = FactoryFunction::call(fn() => new DateTimeImmutable, stdClass::class) * - * @psalm-template T + * @template T of object * - * @psalm-param callable():T $callable - * @psalm-param class-string $expect_class - * @psalm-param array $arguments that will be passed to the function + * @param callable():T $factory + * @param class-string $expect_class + * @param array $arguments that will be passed to the function * - * @psalm-return T + * @return T */ public static function call(callable $factory, string $expect_class, array $arguments = []): object { From 2c670f3092bfd138e8faef9e59356dfd28777d58 Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 10:44:40 +0000 Subject: [PATCH 03/17] ci: Run PHPStan at level 3 (no issues) --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index f1edadb..745387a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 2 + level: 3 paths: - src - test From 8ba30aeb1d52acc16a1532ef8138d84dba425049 Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 10:44:51 +0000 Subject: [PATCH 04/17] ci: Run PHPStan at level 4 (no issues) --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 745387a..f9ad561 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 3 + level: 4 paths: - src - test From b9944a69d3da3d92b894566193306eb46238d950 Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 10:50:55 +0000 Subject: [PATCH 05/17] ci: Run PHPStan at level 5 --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index f9ad561..1bbdc04 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 4 + level: 5 paths: - src - test From f6bf35d918abaf17f12b0c6700306e1b8cce56f5 Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 10:54:14 +0000 Subject: [PATCH 06/17] fix!: BREAKING Don't pass unsafe/untyped args through FactoryFunction There is currently no way to tell phpstan how to type a callable that accepts any set of arguments, in the pattern that we previously used. Rather than trying to jump through hoops to support this, it is both cleaner and safer to have FactoryFunction take a plain callable with no args. If there's a user-supplied callable that needs args, it can be wrapped in another callable closer to the original scope - this means that phpstan will be able to analyse it, and runtime TypeError etc will appear nearer to the place where the actual problem arises. --- CHANGELOG.md | 1 + src/FactoryFunction.php | 5 ++--- src/MicroFramework.php | 2 +- test/unit/FactoryFunctionTest.php | 15 --------------- 4 files changed, 4 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5eae076..28785e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ### Unreleased +* [BREAKING]: FactoryFunction::call() no longer accepts or passes arguments to the callable. * [Internal] Bump dev dependencies * Require PHP 8.5 * Require ingenerator/php-utils version 3 diff --git a/src/FactoryFunction.php b/src/FactoryFunction.php index 31bebd3..d926c0f 100644 --- a/src/FactoryFunction.php +++ b/src/FactoryFunction.php @@ -22,13 +22,12 @@ class FactoryFunction * * @param callable():T $factory * @param class-string $expect_class - * @param array $arguments that will be passed to the function * * @return T */ - public static function call(callable $factory, string $expect_class, array $arguments = []): object + public static function call(callable $factory, string $expect_class): object { - $object = $factory(...$arguments); + $object = $factory(); if (!$object instanceof $expect_class) { throw new UnexpectedValueException( diff --git a/src/MicroFramework.php b/src/MicroFramework.php index ba570ea..c84ffb1 100644 --- a/src/MicroFramework.php +++ b/src/MicroFramework.php @@ -78,7 +78,7 @@ public function execute( : ServerRequest::fromGlobals(); // Hand off to the application for execution - $response = FactoryFunction::call($handler_factory, RequestHandler::class, [$logger]) + $response = FactoryFunction::call(fn () => $handler_factory($logger), RequestHandler::class) ->handle($request); // Render the application result diff --git a/test/unit/FactoryFunctionTest.php b/test/unit/FactoryFunctionTest.php index 89d8ee0..95fc8c4 100644 --- a/test/unit/FactoryFunctionTest.php +++ b/test/unit/FactoryFunctionTest.php @@ -3,9 +3,7 @@ namespace test\unit; use DateTimeImmutable; -use DateTimeZone; use Ingenerator\MicroFramework\FactoryFunction; -use Ingenerator\PHPUtils\DateTime\DateString; use PHPUnit\Framework\TestCase; use stdClass; use UnexpectedValueException; @@ -18,19 +16,6 @@ public function testItCallsFunctionAndReturnsResult() $this->assertSame($instance, FactoryFunction::call(fn () => $instance, stdClass::class)); } - public function testItOptionallyCallsFunctionWithProvidedArgs() - { - $result = FactoryFunction::call( - fn ($date, $timezone) => new DateTimeImmutable($date, $timezone), - DateTimeImmutable::class, - [ - '2024-03-01 08:23:20', - new DateTimeZone('Europe/Paris'), - ] - ); - $this->assertSame('2024-03-01T08:23:20.000000+01:00', DateString::isoMS($result)); - } - public function testItAllowsFactoryToReturnSubclass() { $instance = new class extends DateTimeImmutable { }; From 2c4ad6b8bfd8bdd43bf80ed507f61bd266a1f3ea Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 10:55:04 +0000 Subject: [PATCH 07/17] ci: Run phpstan at level 6 --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 1bbdc04..1cb476b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 5 + level: 6 paths: - src - test From 4043ab807ac4f6db76c0a8e116e4ff9fff8d3207 Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 10:56:40 +0000 Subject: [PATCH 08/17] refactor: Apply Rector code quality rules Basically only adds declare strict types where possible. --- rector.php | 3 +++ test/blackbox/BlackboxSmokeTest.php | 2 ++ test/blackbox/EnvironmentConfigurationTest.php | 2 ++ test/blackbox/ErrorHandlingTest.php | 2 ++ test/blackbox/HttpHeadersTest.php | 2 ++ test/blackbox/HttpResponseCodesTest.php | 2 ++ test/blackbox/OutputBufferingTest.php | 2 ++ test/blackbox/implementation/version.php | 2 ++ test/bootstrap-phpunit.php | 2 ++ test/integration/DefaultStackdriverLoggerProviderTest.php | 2 ++ 10 files changed, 21 insertions(+) diff --git a/rector.php b/rector.php index 6b91a68..f973dd3 100644 --- a/rector.php +++ b/rector.php @@ -12,4 +12,7 @@ ->withSkipPath(__DIR__.'/test/blackbox/implementation/htdocs/dynamic') ->withComposerBased(phpunit: true) ->withPhpSets() + ->withPreparedSets( + codeQuality: true + ) ->withImportNames(); diff --git a/test/blackbox/BlackboxSmokeTest.php b/test/blackbox/BlackboxSmokeTest.php index a2a4677..bdcc206 100644 --- a/test/blackbox/BlackboxSmokeTest.php +++ b/test/blackbox/BlackboxSmokeTest.php @@ -1,5 +1,7 @@ Date: Wed, 4 Nov 2026 10:58:03 +0000 Subject: [PATCH 09/17] refactor: Apply Rector type declaration rules to add known types Adds method return types where these are fully known. --- rector.php | 3 ++- test/blackbox/BlackboxSmokeTest.php | 2 +- test/blackbox/EnvironmentConfigurationTest.php | 4 ++-- test/blackbox/ErrorHandlingTest.php | 2 +- test/blackbox/HttpHeadersTest.php | 4 ++-- test/blackbox/HttpResponseCodesTest.php | 4 ++-- test/blackbox/OutputBufferingTest.php | 12 ++++++------ test/blackbox/RequestParsingTest.php | 8 +++++--- test/blackbox/StackdriverLoggingTest.php | 6 +++--- test/blackbox/implementation/htdocs/index.php | 4 ++-- test/bootstrap-phpunit.php | 2 +- .../DefaultStackdriverLoggerProviderTest.php | 4 ++-- test/unit/FactoryFunctionTest.php | 12 ++++++------ test/unit/StackdriverRequestLoggerTest.php | 8 ++++---- 14 files changed, 39 insertions(+), 36 deletions(-) diff --git a/rector.php b/rector.php index f973dd3..21df94b 100644 --- a/rector.php +++ b/rector.php @@ -13,6 +13,7 @@ ->withComposerBased(phpunit: true) ->withPhpSets() ->withPreparedSets( - codeQuality: true + codeQuality: true, + typeDeclarations: true, ) ->withImportNames(); diff --git a/test/blackbox/BlackboxSmokeTest.php b/test/blackbox/BlackboxSmokeTest.php index bdcc206..ac86668 100644 --- a/test/blackbox/BlackboxSmokeTest.php +++ b/test/blackbox/BlackboxSmokeTest.php @@ -6,7 +6,7 @@ class BlackboxSmokeTest extends BaseBlackboxTestCase { - public function testTestSubjectRespondsFromDefaultHandler() + public function testTestSubjectRespondsFromDefaultHandler(): void { $this->assertResponseMatches( 200, diff --git a/test/blackbox/EnvironmentConfigurationTest.php b/test/blackbox/EnvironmentConfigurationTest.php index 02648de..50b9135 100644 --- a/test/blackbox/EnvironmentConfigurationTest.php +++ b/test/blackbox/EnvironmentConfigurationTest.php @@ -6,7 +6,7 @@ class EnvironmentConfigurationTest extends BaseBlackboxTestCase { - public function testCanConfigureCustomTimezoneInBootstrap() + public function testCanConfigureCustomTimezoneInBootstrap(): void { $handler_url = $this->provisionDynamicHandler( <<<'PHP' @@ -43,7 +43,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface { ); } - public function testCanConfigureLocaleInBootstrap() + public function testCanConfigureLocaleInBootstrap(): void { $handler_url = $this->provisionDynamicHandler( <<<'PHP' diff --git a/test/blackbox/ErrorHandlingTest.php b/test/blackbox/ErrorHandlingTest.php index f3e8a9d..3948d9e 100644 --- a/test/blackbox/ErrorHandlingTest.php +++ b/test/blackbox/ErrorHandlingTest.php @@ -75,7 +75,7 @@ private function doThings(string $uhoh): ResponseInterface { } #[DataProvider('provider_error_handling')] - public function testItCapturesErrorsAndExceptions(string $handler_code) + public function testItCapturesErrorsAndExceptions(string $handler_code): void { $handler_url = self::provisionDynamicHandlerFactoryWithDefaultBootstrap($handler_code); diff --git a/test/blackbox/HttpHeadersTest.php b/test/blackbox/HttpHeadersTest.php index fdc183f..452b9c6 100644 --- a/test/blackbox/HttpHeadersTest.php +++ b/test/blackbox/HttpHeadersTest.php @@ -66,7 +66,7 @@ public static function provider_headers(): array } #[DataProvider('provider_headers')] - public function testItReturnsExpectedHeaders(array $specified_headers, array $expected_headers) + public function testItReturnsExpectedHeaders(array $specified_headers, array $expected_headers): void { $response = $this->guzzle->post( self::$handler_url, @@ -84,7 +84,7 @@ public function testItReturnsExpectedHeaders(array $specified_headers, array $ex $this->assertSame($expected_headers, $all_headers); } - public function testItGivesErrorOnUnsupportedUseOfDuplicateOutputHeaders() + public function testItGivesErrorOnUnsupportedUseOfDuplicateOutputHeaders(): void { // We can't support multiples for the same header because we can't reliably guess whether to pass // replace => true or replace => false into the `header()` call and it's more important that we diff --git a/test/blackbox/HttpResponseCodesTest.php b/test/blackbox/HttpResponseCodesTest.php index 30c2eec..338b1bd 100644 --- a/test/blackbox/HttpResponseCodesTest.php +++ b/test/blackbox/HttpResponseCodesTest.php @@ -31,7 +31,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface #[TestWith([404])] #[TestWith([500])] #[TestWith([502])] - public function testItReturnsStatusCodeFromHandler(int $status_code) + public function testItReturnsStatusCodeFromHandler(int $status_code): void { $this->assertResponseMatches( $status_code, @@ -40,7 +40,7 @@ public function testItReturnsStatusCodeFromHandler(int $status_code) ); } - public function testItCanOptionallyUseCustomStatusCodesIfReasonPhraseProvided() + public function testItCanOptionallyUseCustomStatusCodesIfReasonPhraseProvided(): void { $handler_url = self::provisionDynamicHandlerFactoryWithDefaultBootstrap( <<<'PHP' diff --git a/test/blackbox/OutputBufferingTest.php b/test/blackbox/OutputBufferingTest.php index 6c37eb8..1699d0a 100644 --- a/test/blackbox/OutputBufferingTest.php +++ b/test/blackbox/OutputBufferingTest.php @@ -8,7 +8,7 @@ class OutputBufferingTest extends BaseBlackboxTestCase { - public function testItHandlesErrorEvenIfOutputBeganBeforeFramework() + public function testItHandlesErrorEvenIfOutputBeganBeforeFramework(): void { $handler_url = $this->provisionDynamicHandler( <<<'PHP' @@ -46,7 +46,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface ); } - public function testItReturnsErrorWithoutOutputIfAnyCodeWritesOutputDuringRequestHandling() + public function testItReturnsErrorWithoutOutputIfAnyCodeWritesOutputDuringRequestHandling(): void { $handler_url = self::provisionDynamicHandlerFactoryWithDefaultBootstrap( <<<'PHP' @@ -67,7 +67,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface ); } - public function testItTreatsAsErrorIfUserLeavesOutputBuffersOpen() + public function testItTreatsAsErrorIfUserLeavesOutputBuffersOpen(): void { $handler_url = self::provisionDynamicHandlerFactoryWithDefaultBootstrap( <<<'PHP' @@ -89,7 +89,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface ); } - public function testItTreatsAsErrorIfUserFlushesOutputBuffers() + public function testItTreatsAsErrorIfUserFlushesOutputBuffers(): void { $handler_url = self::provisionDynamicHandlerFactoryWithDefaultBootstrap( <<<'PHP' @@ -112,7 +112,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface ); } - public function testItDoesNotTreatAsErrorIfUserHandlesOutputBufferingCorrectly() + public function testItDoesNotTreatAsErrorIfUserHandlesOutputBufferingCorrectly(): void { $handler_url = self::provisionDynamicHandlerFactoryWithDefaultBootstrap( <<<'PHP' @@ -134,7 +134,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface ); } - public function testItDoesNotTreatAsErrorIfUserHandlesOutputBufferingCorrectlyWithoutRendering() + public function testItDoesNotTreatAsErrorIfUserHandlesOutputBufferingCorrectlyWithoutRendering(): void { $handler_url = self::provisionDynamicHandlerFactoryWithDefaultBootstrap( <<<'PHP' diff --git a/test/blackbox/RequestParsingTest.php b/test/blackbox/RequestParsingTest.php index f4b1d45..431762c 100644 --- a/test/blackbox/RequestParsingTest.php +++ b/test/blackbox/RequestParsingTest.php @@ -1,5 +1,7 @@ guzzle->request($method, self::$handler_url, $options); $received_payload = JSON::decodeArray($response->getBody()->getContents()); @@ -153,7 +155,7 @@ public static function provider_request_headers(): array } #[DataProvider('provider_request_headers')] - public function testItCanReceiveIncomingHeaders($send_headers, $expect): void + public function testItCanReceiveIncomingHeaders(array $send_headers, array $expect): void { $response = $this->guzzle->get(self::$handler_url, ['headers' => [ 'User-Agent' => self::class, @@ -163,7 +165,7 @@ public function testItCanReceiveIncomingHeaders($send_headers, $expect): void $this->assertSame($expect, $received_payload['headers']); } - public function testItCanDetectIncomingUrlsWhenRewriting() + public function testItCanDetectIncomingUrlsWhenRewriting(): void { $handler_url = self::provisionDynamicHandlerFactoryWithDefaultBootstrap( <<<'PHP' diff --git a/test/blackbox/StackdriverLoggingTest.php b/test/blackbox/StackdriverLoggingTest.php index 4bc411f..bbfde9a 100644 --- a/test/blackbox/StackdriverLoggingTest.php +++ b/test/blackbox/StackdriverLoggingTest.php @@ -10,7 +10,7 @@ class StackdriverLoggingTest extends BaseBlackboxTestCase // a blackbox test we should be as explicit as we can be about the detail of the log messages that are written - // but the log messages include filenames, line numbers, and other semi-dynamic content. - public function testItLogsRequestsOnCompletionInStackdriverFormat() + public function testItLogsRequestsOnCompletionInStackdriverFormat(): void { $handler_url = self::provisionDynamicHandler( <<<'PHP' @@ -95,7 +95,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface ); } - public function testItLogsUncaughtExceptionsAndRequestInStackdriverFormat() + public function testItLogsUncaughtExceptionsAndRequestInStackdriverFormat(): void { $handler_url = self::provisionDynamicHandler( <<<'PHP' @@ -245,7 +245,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface ); } - public function testItOutputsCustomAppLogsInStackdriverFormat() + public function testItOutputsCustomAppLogsInStackdriverFormat(): void { $handler_url = self::provisionDynamicHandler( <<<'PHP' diff --git a/test/blackbox/implementation/htdocs/index.php b/test/blackbox/implementation/htdocs/index.php index 651c4d1..80da1c5 100644 --- a/test/blackbox/implementation/htdocs/index.php +++ b/test/blackbox/implementation/htdocs/index.php @@ -12,11 +12,11 @@ require_once __DIR__.'/../vendor/autoload.php'; new MicroFramework()->execute( - logger_provider_factory: fn () => new DefaultStackdriverLoggerProvider( + logger_provider_factory: fn (): DefaultStackdriverLoggerProvider => new DefaultStackdriverLoggerProvider( service_name: 'ig-micro', version_file_path: __DIR__.'/../version.php', ), - handler_factory: fn () => new class implements RequestHandler { + handler_factory: fn (): RequestHandler => new class implements RequestHandler { public function handle(ServerRequestInterface $request): ResponseInterface { return new Response(200, body: 'Blackbox is alive'); diff --git a/test/bootstrap-phpunit.php b/test/bootstrap-phpunit.php index 2cb2e2e..682e76b 100644 --- a/test/bootstrap-phpunit.php +++ b/test/bootstrap-phpunit.php @@ -8,7 +8,7 @@ // Currently phpunit's default error handling doesn't properly catch warnings / errors from data providers // https://github.com/sebastianbergmann/phpunit/issues/2449 \set_error_handler( - function ($severity, $message, $file, $line) { + function ($severity, $message, $file, $line): void { throw new ErrorException($message, 0, $severity, $file, $line); } ); diff --git a/test/integration/DefaultStackdriverLoggerProviderTest.php b/test/integration/DefaultStackdriverLoggerProviderTest.php index 4aad7c2..50cbc54 100644 --- a/test/integration/DefaultStackdriverLoggerProviderTest.php +++ b/test/integration/DefaultStackdriverLoggerProviderTest.php @@ -12,12 +12,12 @@ class DefaultStackdriverLoggerProviderTest extends TestCase { - public function testItIsInitialisableLoggerProvider() + public function testItIsInitialisableLoggerProvider(): void { $this->assertInstanceOf(LoggerProvider::class, $this->newSubject()); } - public function testItProvidesExpectedLoggerAndRequestLogger() + public function testItProvidesExpectedLoggerAndRequestLogger(): void { $subject = $this->newSubject(); $this->assertInstanceOf(StackdriverApplicationLogger::class, $subject->getLogger()); diff --git a/test/unit/FactoryFunctionTest.php b/test/unit/FactoryFunctionTest.php index 95fc8c4..f94499d 100644 --- a/test/unit/FactoryFunctionTest.php +++ b/test/unit/FactoryFunctionTest.php @@ -10,21 +10,21 @@ class FactoryFunctionTest extends TestCase { - public function testItCallsFunctionAndReturnsResult() + public function testItCallsFunctionAndReturnsResult(): void { $instance = new stdClass(); - $this->assertSame($instance, FactoryFunction::call(fn () => $instance, stdClass::class)); + $this->assertSame($instance, FactoryFunction::call(fn (): stdClass => $instance, stdClass::class)); } - public function testItAllowsFactoryToReturnSubclass() + public function testItAllowsFactoryToReturnSubclass(): void { $instance = new class extends DateTimeImmutable { }; - $this->assertSame($instance, FactoryFunction::call(fn () => $instance, DateTimeImmutable::class)); + $this->assertSame($instance, FactoryFunction::call(fn (): object => $instance, DateTimeImmutable::class)); } - public function testItThrowsIfReturnedValueIsNotExpectedType() + public function testItThrowsIfReturnedValueIsNotExpectedType(): void { - $fn = fn () => new stdClass(); + $fn = fn (): stdClass => new stdClass(); $this->expectException(UnexpectedValueException::class); $this->expectExceptionMessageIsOrContains('Factory for DateTimeImmutable incorrectly returned stdClass'); FactoryFunction::call($fn, DateTimeImmutable::class); diff --git a/test/unit/StackdriverRequestLoggerTest.php b/test/unit/StackdriverRequestLoggerTest.php index 33add54..6a58bd7 100644 --- a/test/unit/StackdriverRequestLoggerTest.php +++ b/test/unit/StackdriverRequestLoggerTest.php @@ -13,12 +13,12 @@ class StackdriverRequestLoggerTest extends TestCase { - public function testItIsInitialisableRequestLogger() + public function testItIsInitialisableRequestLogger(): void { $this->assertInstanceOf(RequestLogger::class, $this->newSubject()); } - public function testItsLogRequestLogsAnExceptionAndReturnsOnUnknownLoggerType() + public function testItsLogRequestLogsAnExceptionAndReturnsOnUnknownLoggerType(): void { $logger = new TestLogger(); $this->newSubject()->logRequest($logger, 0); @@ -50,7 +50,7 @@ public function testItCalculatesRequestStartTimeFromElapsedHighResTime( int|float $hrtime_now, float $microtime_now, float $expect_start_time, - ) { + ): void { $subject = $this->stubSubjectWithHrTimeAndMicrotime($hrtime_now, $microtime_now); $logger = $this->makeLoggerSpy(); @@ -62,7 +62,7 @@ public function testItCalculatesRequestStartTimeFromElapsedHighResTime( ); } - public function testItLogsSaneValueForRequestTimeWithDefaultImplementation() + public function testItLogsSaneValueForRequestTimeWithDefaultImplementation(): void { $actual_start_microtime = microtime(true); $start_hrtime = hrtime(true); From caa3487a506fe75bfafd3e2c82f85888377956df Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 11:12:23 +0000 Subject: [PATCH 10/17] fix!: BREAKING - Add strict types and array shapes throughout Including to the error handler function. --- CHANGELOG.md | 1 + rector.php | 1 + src/DefaultStackdriverLoggerProvider.php | 4 ++++ src/MicroFramework.php | 2 +- test/blackbox/BaseBlackboxTestCase.php | 3 +++ test/blackbox/ErrorHandlingTest.php | 3 +++ test/blackbox/HttpHeadersTest.php | 7 +++++++ test/blackbox/RequestParsingTest.php | 14 ++++++++++++++ test/bootstrap-phpunit.php | 2 +- test/unit/StackdriverRequestLoggerTest.php | 8 +++++++- 10 files changed, 42 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28785e4..9ee40cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ### Unreleased +* [BREAKING]: Added strict types and array shapes throughout. * [BREAKING]: FactoryFunction::call() no longer accepts or passes arguments to the callable. * [Internal] Bump dev dependencies * Require PHP 8.5 diff --git a/rector.php b/rector.php index 21df94b..7907d00 100644 --- a/rector.php +++ b/rector.php @@ -15,5 +15,6 @@ ->withPreparedSets( codeQuality: true, typeDeclarations: true, + typeDeclarationDocblocks: true, ) ->withImportNames(); diff --git a/src/DefaultStackdriverLoggerProvider.php b/src/DefaultStackdriverLoggerProvider.php index 8ebb841..471108c 100644 --- a/src/DefaultStackdriverLoggerProvider.php +++ b/src/DefaultStackdriverLoggerProvider.php @@ -3,6 +3,7 @@ namespace Ingenerator\MicroFramework; use Ingenerator\PHPUtils\Logging\DefaultLogMetadata; +use Ingenerator\PHPUtils\Logging\LogMetadataProvider; use Ingenerator\PHPUtils\Logging\StackdriverApplicationLogger; use Psr\Log\LoggerInterface; @@ -29,6 +30,9 @@ public function getLogger(): LoggerInterface return StackdriverApplicationLogger::instance(); } + /** + * @return list> + */ protected function getMetadataProviders(): array { return [ diff --git a/src/MicroFramework.php b/src/MicroFramework.php index c84ffb1..a9e1e17 100644 --- a/src/MicroFramework.php +++ b/src/MicroFramework.php @@ -30,7 +30,7 @@ class MicroFramework { - public static function throwingErrorHandler($code, $error, $file = null, $line = null): bool + public static function throwingErrorHandler(int $code, string $error, ?string $file = null, ?int $line = null): bool { if (error_reporting() & $code) { // This error is not suppressed by current error reporting settings diff --git a/test/blackbox/BaseBlackboxTestCase.php b/test/blackbox/BaseBlackboxTestCase.php index 8bccd19..2f34620 100644 --- a/test/blackbox/BaseBlackboxTestCase.php +++ b/test/blackbox/BaseBlackboxTestCase.php @@ -55,6 +55,9 @@ protected function truncateTestSubjectLogs(): void } } + /** + * @return list + */ protected function getTestSubjectLogEntriesDuringTest(): array { // Wait a moment for logs to be written - they aren't always absolutely immediate diff --git a/test/blackbox/ErrorHandlingTest.php b/test/blackbox/ErrorHandlingTest.php index 3948d9e..b7faca8 100644 --- a/test/blackbox/ErrorHandlingTest.php +++ b/test/blackbox/ErrorHandlingTest.php @@ -8,6 +8,9 @@ class ErrorHandlingTest extends BaseBlackboxTestCase { + /** + * @return array> + */ public static function provider_error_handling(): array { return [ diff --git a/test/blackbox/HttpHeadersTest.php b/test/blackbox/HttpHeadersTest.php index 452b9c6..540b925 100644 --- a/test/blackbox/HttpHeadersTest.php +++ b/test/blackbox/HttpHeadersTest.php @@ -27,6 +27,9 @@ public function handle(ServerRequestInterface $request): ResponseInterface ); } + /** + * @return array, array>}> + */ public static function provider_headers(): array { return [ @@ -65,6 +68,10 @@ public static function provider_headers(): array ]; } + /** + * @param array $specified_headers + * @param array> $expected_headers + */ #[DataProvider('provider_headers')] public function testItReturnsExpectedHeaders(array $specified_headers, array $expected_headers): void { diff --git a/test/blackbox/RequestParsingTest.php b/test/blackbox/RequestParsingTest.php index 431762c..d84e9be 100644 --- a/test/blackbox/RequestParsingTest.php +++ b/test/blackbox/RequestParsingTest.php @@ -34,6 +34,9 @@ public function handle(ServerRequestInterface $request): ResponseInterface ); } + /** + * @return array, array{method: string, body: string, parsed_body: array}}> + */ public static function provider_request_bodies(): array { return [ @@ -111,6 +114,10 @@ public static function provider_request_bodies(): array ]; } + /** + * @param array $options + * @param array{method: string, body: string, parsed_body: array} $expect + */ #[DataProvider('provider_request_bodies')] public function testItCanReceiveIncomingRequestBodiesInExpectedFormats(string $method, array $options, array $expect): void { @@ -120,6 +127,9 @@ public function testItCanReceiveIncomingRequestBodiesInExpectedFormats(string $m $this->assertSame($expect, $received_payload); } + /** + * @return array>, array>}> + */ public static function provider_request_headers(): array { return [ @@ -154,6 +164,10 @@ public static function provider_request_headers(): array ]; } + /** + * @param array> $send_headers + * @param array> $expect + */ #[DataProvider('provider_request_headers')] public function testItCanReceiveIncomingHeaders(array $send_headers, array $expect): void { diff --git a/test/bootstrap-phpunit.php b/test/bootstrap-phpunit.php index 682e76b..325f359 100644 --- a/test/bootstrap-phpunit.php +++ b/test/bootstrap-phpunit.php @@ -1,6 +1,6 @@ assertTrue($logger->hasErrorThatContains('Could not log request details - got a '.$logger::class)); } + /** + * @return array> + */ public static function provider_calculate_request_start(): array { return [ @@ -121,11 +124,14 @@ protected function getMicrotime(): float } /** - * @return StackdriverApplicationLogger&object{request_log_calls: array} + * @return StackdriverApplicationLogger&object{request_log_calls: array{server: ServerGlobal, request_start_time: ?float}} */ public function makeLoggerSpy(): StackdriverApplicationLogger { return new class extends StackdriverApplicationLogger { + /** + * @var array{server: ServerGlobal, request_start_time: ?float} + */ public private(set) array $request_log_calls; public function __construct() From d7e57cc8cb90c50db8f0a448449610ffbd4fd7c1 Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 11:12:50 +0000 Subject: [PATCH 11/17] ci: Run phpstan at level 7 --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 1cb476b..766c461 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 6 + level: 7 paths: - src - test From b642569f718d409cbc42b5165c50ccdc6c6ffbfb Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 11:43:21 +0000 Subject: [PATCH 12/17] fix: PHPStan level 7 errors --- test/blackbox/BaseBlackboxTestCase.php | 26 +++++++++++++++++++++--- test/blackbox/RequestParsingTest.php | 4 ++-- test/blackbox/StackdriverLoggingTest.php | 10 ++++----- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/test/blackbox/BaseBlackboxTestCase.php b/test/blackbox/BaseBlackboxTestCase.php index 2f34620..4603d0d 100644 --- a/test/blackbox/BaseBlackboxTestCase.php +++ b/test/blackbox/BaseBlackboxTestCase.php @@ -4,9 +4,9 @@ use GuzzleHttp\Client; use GuzzleHttp\RequestOptions; -use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; +use RuntimeException; use Symfony\Component\Filesystem\Filesystem; use UnexpectedValueException; @@ -40,7 +40,12 @@ protected function setUp(): void private function getTestSubjectBaseUrl(): string { $subject_url = getenv('TEST_SUBJECT_BASE_URI'); - Assert::assertNotEmpty($subject_url, 'Expect an environment variable TEST_SUBJECT_BASE_URI'); + if (!is_string($subject_url)) { + throw new RuntimeException('Expect an environment variable TEST_SUBJECT_BASE_URI as a string'); + } + if (empty($subject_url)) { + throw new RuntimeException('Expect an environment variable TEST_SUBJECT_BASE_URI not to be empty string'); + } return $subject_url; } @@ -70,9 +75,14 @@ protected function getTestSubjectLogEntriesDuringTest(): array // Each line in the file is in syslog RFC3164 format. The details of the message header not relevant to us, we // are only using syslog format to be able to capture the underlying container STDOUT/STDERR in a docker compose // environment. So we just split the lines on the end of the HEADER and return the CONTENT + $lines = file(self::$test_subject_logs_file, FILE_IGNORE_NEW_LINES); + if ($lines === false) { + throw new RuntimeException('Could not read '.self::$test_subject_logs_file); + } + return array_map( self::extractSyslogRFC3164MessageBody(...), - file(self::$test_subject_logs_file, FILE_IGNORE_NEW_LINES), + $lines, ); } @@ -141,4 +151,14 @@ protected static function provisionDynamicHandler(string $code): string return '/dynamic/'.$id.'/'; } + + final protected function getLocalIp(): string + { + $hostname = gethostname(); + if ($hostname === false) { + throw new RuntimeException('Could not get hostname'); + } + + return gethostbyname($hostname); + } } diff --git a/test/blackbox/RequestParsingTest.php b/test/blackbox/RequestParsingTest.php index d84e9be..dd1a72d 100644 --- a/test/blackbox/RequestParsingTest.php +++ b/test/blackbox/RequestParsingTest.php @@ -128,7 +128,7 @@ public function testItCanReceiveIncomingRequestBodiesInExpectedFormats(string $m } /** - * @return array>, array>}> + * @return array>, array>}> */ public static function provider_request_headers(): array { @@ -165,7 +165,7 @@ public static function provider_request_headers(): array } /** - * @param array> $send_headers + * @param array> $send_headers * @param array> $expect */ #[DataProvider('provider_request_headers')] diff --git a/test/blackbox/StackdriverLoggingTest.php b/test/blackbox/StackdriverLoggingTest.php index bbfde9a..f1374cd 100644 --- a/test/blackbox/StackdriverLoggingTest.php +++ b/test/blackbox/StackdriverLoggingTest.php @@ -76,7 +76,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface 'httpRequest' => [ 'requestMethod' => 'GET', 'requestUrl' => parse_url($handler_url, PHP_URL_PATH), - 'remoteIp' => gethostbyname(gethostname()), + 'remoteIp' => $this->getLocalIp(), 'status' => 203, 'userAgent' => 'My Test UA', // 'latency' => '0.002811s', @@ -181,7 +181,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface 'httpRequest' => [ 'requestMethod' => 'POST', 'requestUrl' => parse_url($handler_url, PHP_URL_PATH), - 'remoteIp' => gethostbyname(gethostname()), + 'remoteIp' => $this->getLocalIp(), ], 'reportLocation' => [ 'filePath' => '/var/www/vendor/ingenerator/microframework/src/MicroFramework.php', @@ -226,7 +226,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface 'httpRequest' => [ 'requestMethod' => 'POST', 'requestUrl' => parse_url($handler_url, PHP_URL_PATH), - 'remoteIp' => gethostbyname(gethostname()), + 'remoteIp' => $this->getLocalIp(), 'status' => 500, 'userAgent' => 'My Test UA', // 'latency' => '0.002811s', @@ -334,7 +334,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface 'httpRequest' => [ 'requestMethod' => 'POST', 'requestUrl' => parse_url($handler_url, PHP_URL_PATH), - 'remoteIp' => gethostbyname(gethostname()), + 'remoteIp' => $this->getLocalIp(), ], ], // 'logging.googleapis.com/trace' => '66991537308e16.07573263', @@ -357,7 +357,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface 'httpRequest' => [ 'requestMethod' => 'POST', 'requestUrl' => parse_url($handler_url, PHP_URL_PATH), - 'remoteIp' => gethostbyname(gethostname()), + 'remoteIp' => $this->getLocalIp(), 'status' => 200, 'userAgent' => 'My Test UA', // 'latency' => '0.002811s', From ebf8ef214af898911819933d1789baba4772ea85 Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 11:43:43 +0000 Subject: [PATCH 13/17] ci: Run phpstan at level 8 (no issues) --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 766c461..8d46a5d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 7 + level: 8 paths: - src - test From 85e076592d0dde8fad4f29778cb225b998d14931 Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 11:43:57 +0000 Subject: [PATCH 14/17] ci: Run phpstan at level 9 --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 8d46a5d..60edc2c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 8 + level: 9 paths: - src - test From 82b166de4e8aed0f43dfd3563d4c6c3d64fa0682 Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 12:44:59 +0000 Subject: [PATCH 15/17] fix: Phpstan level 9 issues --- test/blackbox/RequestParsingTest.php | 7 +++++-- test/blackbox/StackdriverLoggingTest.php | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/test/blackbox/RequestParsingTest.php b/test/blackbox/RequestParsingTest.php index dd1a72d..096c952 100644 --- a/test/blackbox/RequestParsingTest.php +++ b/test/blackbox/RequestParsingTest.php @@ -7,6 +7,9 @@ use Ingenerator\PHPUtils\StringEncoding\JSON; use PHPUnit\Framework\Attributes\DataProvider; +/** + * @phpstan-type TGuzzleRequestOptions array{form_params?: array|scalar|null>, json?: mixed} + */ class RequestParsingTest extends BaseBlackboxTestCase { private static string $handler_url; @@ -35,7 +38,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface } /** - * @return array, array{method: string, body: string, parsed_body: array}}> + * @return array}}> */ public static function provider_request_bodies(): array { @@ -115,7 +118,7 @@ public static function provider_request_bodies(): array } /** - * @param array $options + * @param TGuzzleRequestOptions $options * @param array{method: string, body: string, parsed_body: array} $expect */ #[DataProvider('provider_request_bodies')] diff --git a/test/blackbox/StackdriverLoggingTest.php b/test/blackbox/StackdriverLoggingTest.php index f1374cd..27ee568 100644 --- a/test/blackbox/StackdriverLoggingTest.php +++ b/test/blackbox/StackdriverLoggingTest.php @@ -56,16 +56,22 @@ public function handle(ServerRequestInterface $request): ResponseInterface $request_log_msg = JSON::decodeArray($messages[0]); // Assert things that are dynamic and can't be exactly asserted + $this->assertIsArray($request_log_msg['httpRequest']); + $this->assertIsString($request_log_msg['httpRequest']['latency']); $this->assertMatchesRegularExpression('/^0.00\d{4}s$/', $request_log_msg['httpRequest']['latency']); unset($request_log_msg['httpRequest']['latency']); + $this->assertIsArray($request_log_msg['context']); + $this->assertIsString($request_log_msg['context']['req']); $this->assertMatchesRegularExpression('/^\w+\.\w+$/', $request_log_msg['context']['req']); unset($request_log_msg['context']['req']); + $this->assertIsString($request_log_msg['logging.googleapis.com/trace']); $this->assertMatchesRegularExpression('/^\w+\.\w+$/', $request_log_msg['logging.googleapis.com/trace']); unset($request_log_msg['logging.googleapis.com/trace']); // Currently the test handler is taking around 2.1Mb, just assert it's close to that + $this->assertIsFloat($request_log_msg['context']['mem_mb']); $this->assertSame(2.0, round($request_log_msg['context']['mem_mb'])); unset($request_log_msg['context']['mem_mb']); @@ -142,7 +148,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface $request_log_msg = JSON::decodeArray($messages[1]); // Assert the things that vary and can't easily be asserted directly + $this->assertIsArray($error_log_msg['context']); + $this->assertIsString($error_log_msg['context']['req']); $this->assertMatchesRegularExpression('/^\w+\.\w+$/', $error_log_msg['context']['req']); + $this->assertIsArray($request_log_msg['context']); $this->assertSame( $error_log_msg['context']['req'], $request_log_msg['context']['req'], @@ -151,6 +160,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface unset($error_log_msg['context']['req']); unset($request_log_msg['context']['req']); + $this->assertIsString($error_log_msg['logging.googleapis.com/trace']); + $this->assertIsString($request_log_msg['logging.googleapis.com/trace']); $this->assertMatchesRegularExpression('/^\w+\.\w+$/', $request_log_msg['logging.googleapis.com/trace']); $this->assertSame( $error_log_msg['logging.googleapis.com/trace'], @@ -160,10 +171,13 @@ public function handle(ServerRequestInterface $request): ResponseInterface unset($error_log_msg['logging.googleapis.com/trace']); unset($request_log_msg['logging.googleapis.com/trace']); + $this->assertIsArray($request_log_msg['httpRequest']); + $this->assertIsString($request_log_msg['httpRequest']['latency']); $this->assertMatchesRegularExpression('/^0.00\d{4}s$/', $request_log_msg['httpRequest']['latency']); unset($request_log_msg['httpRequest']['latency']); // Currently the test handler is taking around 2.1Mb, just assert it's close to that + $this->assertIsFloat($request_log_msg['context']['mem_mb']); $this->assertSame(2.0, round($request_log_msg['context']['mem_mb'])); unset($request_log_msg['context']['mem_mb']); @@ -295,7 +309,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface $request_log_msg = JSON::decodeArray($messages[1]); // Assert the things that vary and can't easily be asserted directly + $this->assertIsArray($error_log_msg['context']); + $this->assertIsString($error_log_msg['context']['req']); $this->assertMatchesRegularExpression('/^\w+\.\w+$/', $error_log_msg['context']['req']); + $this->assertIsArray($request_log_msg['context']); $this->assertSame( $error_log_msg['context']['req'], $request_log_msg['context']['req'], @@ -304,6 +321,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface unset($error_log_msg['context']['req']); unset($request_log_msg['context']['req']); + $this->assertIsString($error_log_msg['logging.googleapis.com/trace']); + $this->assertIsString($request_log_msg['logging.googleapis.com/trace']); $this->assertMatchesRegularExpression('/^\w+\.\w+$/', $request_log_msg['logging.googleapis.com/trace']); $this->assertSame( $error_log_msg['logging.googleapis.com/trace'], @@ -313,10 +332,13 @@ public function handle(ServerRequestInterface $request): ResponseInterface unset($error_log_msg['logging.googleapis.com/trace']); unset($request_log_msg['logging.googleapis.com/trace']); + $this->assertIsArray($request_log_msg['httpRequest']); + $this->assertIsString($request_log_msg['httpRequest']['latency']); $this->assertMatchesRegularExpression('/^0.00\d{4}s$/', $request_log_msg['httpRequest']['latency']); unset($request_log_msg['httpRequest']['latency']); // Currently the test handler is taking around 2.1Mb, just assert it's close to that + $this->assertIsFloat($request_log_msg['context']['mem_mb']); $this->assertSame(2.0, round($request_log_msg['context']['mem_mb'])); unset($request_log_msg['context']['mem_mb']); From 99fcf697fc00e27069da23a409094d4b0a29f984 Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 12:45:16 +0000 Subject: [PATCH 16/17] ci: Run phpstan at level 10 (no issues) --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 60edc2c..1cf356e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 9 + level: 10 paths: - src - test From 8286d9c0542e92f2514aed9056edbdecabb9e63e Mon Sep 17 00:00:00 2001 From: acoulton Date: Wed, 4 Nov 2026 13:05:10 +0000 Subject: [PATCH 17/17] test: Fix testing mem_mb - it's logged as a string, not a float --- test/blackbox/StackdriverLoggingTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/blackbox/StackdriverLoggingTest.php b/test/blackbox/StackdriverLoggingTest.php index 27ee568..8dc1c23 100644 --- a/test/blackbox/StackdriverLoggingTest.php +++ b/test/blackbox/StackdriverLoggingTest.php @@ -71,8 +71,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface unset($request_log_msg['logging.googleapis.com/trace']); // Currently the test handler is taking around 2.1Mb, just assert it's close to that - $this->assertIsFloat($request_log_msg['context']['mem_mb']); - $this->assertSame(2.0, round($request_log_msg['context']['mem_mb'])); + $this->assertIsNumeric($request_log_msg['context']['mem_mb']); + $this->assertSame(2.0, round((float) $request_log_msg['context']['mem_mb'])); unset($request_log_msg['context']['mem_mb']); $this->assertSame( @@ -177,8 +177,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface unset($request_log_msg['httpRequest']['latency']); // Currently the test handler is taking around 2.1Mb, just assert it's close to that - $this->assertIsFloat($request_log_msg['context']['mem_mb']); - $this->assertSame(2.0, round($request_log_msg['context']['mem_mb'])); + $this->assertIsNumeric($request_log_msg['context']['mem_mb']); + $this->assertSame(2.0, round((float) $request_log_msg['context']['mem_mb'])); unset($request_log_msg['context']['mem_mb']); $this->assertSame( @@ -338,8 +338,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface unset($request_log_msg['httpRequest']['latency']); // Currently the test handler is taking around 2.1Mb, just assert it's close to that - $this->assertIsFloat($request_log_msg['context']['mem_mb']); - $this->assertSame(2.0, round($request_log_msg['context']['mem_mb'])); + $this->assertIsNumeric($request_log_msg['context']['mem_mb']); + $this->assertSame(2.0, round((float) $request_log_msg['context']['mem_mb'])); unset($request_log_msg['context']['mem_mb']); $this->assertSame(