Skip to content

Commit a25de95

Browse files
feat: Add OTEL testsuite to PHPUnit and check if Laravel app is still available before logging
1 parent 011d982 commit a25de95

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

app/Services/Utils/RedisCacheService.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,25 @@ public function __destruct()
6363
if (is_resource($res)) $metadata = @stream_get_meta_data($res);
6464
}
6565
} catch (\Throwable $ignored) {}
66-
Log::error
67-
(
68-
sprintf
66+
// Check if Laravel app is still available before logging
67+
if (app()->bound('config')) {
68+
Log::error
6969
(
70-
"RedisCacheService::__destruct %s %s %s",
71-
$ex->getCode(),
72-
$ex->getMessage(),
73-
var_export($metadata, true)
74-
)
75-
);
70+
sprintf
71+
(
72+
"RedisCacheService::__destruct %s %s %s",
73+
$ex->getCode(),
74+
$ex->getMessage(),
75+
var_export($metadata, true)
76+
)
77+
);
78+
}
7679
}
7780
catch(\Exception $ex){
78-
Log::warning($ex);
81+
// Check if Laravel app is still available before logging
82+
if (app()->bound('config')) {
83+
Log::warning($ex);
84+
}
7985
}
8086
}
8187

@@ -324,4 +330,4 @@ public function ttl($key)
324330
return (int)$conn->ttl($key);
325331
}, 0);
326332
}
327-
}
333+
}

phpunit.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
<testsuites>
44
<testsuite name="Application Test Suite">
55
<directory>./tests/</directory>
6+
<exclude>./tests/OpenTelemetry/</exclude>
7+
<exclude>./tests/TestCase.php</exclude>
8+
</testsuite>
9+
<testsuite name="OTEL">
10+
<directory>./tests/OpenTelemetry/</directory>
11+
<exclude>./tests/OpenTelemetry/ExampleTest.php</exclude>
612
</testsuite>
713
</testsuites>
814
<php>

tests/OpenTelemetry/.gitkeep

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Tests\OpenTelemetry;
4+
5+
use Tests\TestCase;
6+
class ExampleTest extends TestCase
7+
{
8+
/**
9+
* A basic test example.
10+
*
11+
* @return void
12+
*/
13+
public function testBasicTest()
14+
{
15+
$this->assertTrue(true);
16+
}
17+
}

0 commit comments

Comments
 (0)