From 937b5e3af8099b76728dc21fd518fd102b8a6178 Mon Sep 17 00:00:00 2001 From: Matias Perrone Date: Thu, 25 Sep 2025 12:07:47 -0300 Subject: [PATCH] feat: Add OTEL testsuite to PHPUnit and check if Laravel app is still available before logging --- app/Services/Utils/RedisCacheService.php | 28 ++++++++++++++---------- phpunit.xml | 6 +++++ tests/OpenTelemetry/.gitkeep | 0 tests/OpenTelemetry/ExampleTest.php | 17 ++++++++++++++ 4 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 tests/OpenTelemetry/.gitkeep create mode 100644 tests/OpenTelemetry/ExampleTest.php diff --git a/app/Services/Utils/RedisCacheService.php b/app/Services/Utils/RedisCacheService.php index eccedbf78..4b3646173 100644 --- a/app/Services/Utils/RedisCacheService.php +++ b/app/Services/Utils/RedisCacheService.php @@ -63,19 +63,25 @@ public function __destruct() if (is_resource($res)) $metadata = @stream_get_meta_data($res); } } catch (\Throwable $ignored) {} - Log::error - ( - sprintf + // Check if Laravel app is still available before logging + if (app()->bound('config')) { + Log::error ( - "RedisCacheService::__destruct %s %s %s", - $ex->getCode(), - $ex->getMessage(), - var_export($metadata, true) - ) - ); + sprintf + ( + "RedisCacheService::__destruct %s %s %s", + $ex->getCode(), + $ex->getMessage(), + var_export($metadata, true) + ) + ); + } } catch(\Exception $ex){ - Log::warning($ex); + // Check if Laravel app is still available before logging + if (app()->bound('config')) { + Log::warning($ex); + } } } @@ -324,4 +330,4 @@ public function ttl($key) return (int)$conn->ttl($key); }, 0); } -} \ No newline at end of file +} diff --git a/phpunit.xml b/phpunit.xml index 51f3bf8a1..a2b78a0b5 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -3,6 +3,12 @@ ./tests/ + ./tests/OpenTelemetry/ + ./tests/TestCase.php + + + ./tests/OpenTelemetry/ + ./tests/OpenTelemetry/ExampleTest.php diff --git a/tests/OpenTelemetry/.gitkeep b/tests/OpenTelemetry/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/OpenTelemetry/ExampleTest.php b/tests/OpenTelemetry/ExampleTest.php new file mode 100644 index 000000000..6491fdc48 --- /dev/null +++ b/tests/OpenTelemetry/ExampleTest.php @@ -0,0 +1,17 @@ +assertTrue(true); + } +}