@@ -58,8 +58,8 @@ public function testCacheBreadcrumbIsNotRecordedWhenDisabled(): void
5858 public function testCacheBreadcrumbReplacesSessionKeyWithPlaceholder (): void
5959 {
6060 // Start a session properly in the test environment
61- $ this ->withSession ([ ' test ' => ' value ' ] );
62-
61+ $ this ->ensureRequestIsBound ( );
62+ $ this -> startSession ();
6363 $ sessionId = $ this ->app ['session ' ]->getId ();
6464
6565 // Use the session ID as a cache key
@@ -183,8 +183,8 @@ public function testCacheSpanReplacesSessionKeyWithPlaceholder(): void
183183 $ this ->markSkippedIfTracingEventsNotAvailable ();
184184
185185 // Start a session properly in the test environment
186- $ this ->withSession ([ ' test ' => ' value ' ] );
187-
186+ $ this ->ensureRequestIsBound ( );
187+ $ this -> startSession ();
188188 $ sessionId = $ this ->app ['session ' ]->getId ();
189189
190190 $ span = $ this ->executeAndReturnMostRecentSpan (function () use ($ sessionId ) {
@@ -201,17 +201,17 @@ public function testCacheSpanReplacesMultipleSessionKeysWithPlaceholder(): void
201201 $ this ->markSkippedIfTracingEventsNotAvailable ();
202202
203203 // Start a session properly in the test environment
204- $ this ->withSession ([ ' test ' => ' value ' ] );
205-
204+ $ this ->ensureRequestIsBound ( );
205+ $ this -> startSession ();
206206 $ sessionId = $ this ->app ['session ' ]->getId ();
207207
208208 $ span = $ this ->executeAndReturnMostRecentSpan (function () use ($ sessionId ) {
209209 Cache::get ([$ sessionId , 'regular-key ' , $ sessionId . '_another ' ]);
210210 });
211211
212212 $ this ->assertEquals ('cache.get ' , $ span ->getOp ());
213- $ this ->assertEquals ('{sessionKey}, regular-key, {sessionKey} ' , $ span ->getDescription ());
214- $ this ->assertEquals (['{sessionKey} ' , 'regular-key ' , ' {sessionKey} ' ], $ span ->getData ()['cache.key ' ]);
213+ $ this ->assertEquals ('{sessionKey}, regular-key, ' . $ sessionId . ' _another ' , $ span ->getDescription ());
214+ $ this ->assertEquals (['{sessionKey} ' , 'regular-key ' , $ sessionId . ' _another ' ], $ span ->getData ()['cache.key ' ]);
215215 }
216216
217217 public function testCacheOperationDoesNotStartSessionPrematurely (): void
@@ -252,4 +252,22 @@ private function executeAndReturnMostRecentSpan(callable $callable): Span
252252
253253 return array_pop ($ spans );
254254 }
255+
256+ private function ensureRequestIsBound (): void
257+ {
258+ // Ensure we have a request instance
259+ if (!$ this ->app ->bound ('request ' )) {
260+ $ this ->app ->instance ('request ' , $ this ->app ->make (\Illuminate \Http \Request::class));
261+ }
262+ }
263+
264+ private function startSession (): void
265+ {
266+ // Start the session
267+ $ session = $ this ->app ['session ' ];
268+ $ session ->start ();
269+
270+ // Set the session on the request
271+ $ this ->app ['request ' ]->setLaravelSession ($ session );
272+ }
255273}
0 commit comments