@@ -323,6 +323,33 @@ public function testFindLogByIndexUsesLoadedLogsRelation(): void
323323 $ this ->assertCount (0 , DB ::getQueryLog ());
324324 }
325325
326+ public function testFindLogByIndexDoesNotUseFirstWhereForLoadedLogsRelation (): void
327+ {
328+ $ workflow = StoredWorkflow::create ([
329+ 'class ' => 'TestWorkflow ' ,
330+ 'status ' => 'running ' ,
331+ ]);
332+
333+ $ log = $ workflow ->logs ()
334+ ->create ([
335+ 'index ' => 0 ,
336+ 'now ' => now (),
337+ 'class ' => 'test ' ,
338+ ]);
339+
340+ $ workflow ->setRelation ('logs ' , new class ([$ log ]) extends \Illuminate \Database \Eloquent \Collection {
341+ public function firstWhere ($ key , $ operator = null , $ value = null )
342+ {
343+ throw new \BadMethodCallException ('Loaded log lookup should not rely on firstWhere. ' );
344+ }
345+ });
346+
347+ $ foundLog = $ workflow ->findLogByIndex (0 );
348+
349+ $ this ->assertNotNull ($ foundLog );
350+ $ this ->assertSame ($ log ->id , $ foundLog ->id );
351+ }
352+
326353 public function testCreateLogSyncsLoadedLogsRelation (): void
327354 {
328355 $ workflow = StoredWorkflow::create ([
@@ -372,6 +399,33 @@ public function testFindTimerByIndexUsesLoadedTimersRelation(): void
372399 $ this ->assertCount (0 , DB ::getQueryLog ());
373400 }
374401
402+ public function testFindTimerByIndexDoesNotUseFirstWhereForLoadedTimersRelation (): void
403+ {
404+ $ workflow = StoredWorkflow::create ([
405+ 'class ' => 'TestWorkflow ' ,
406+ 'status ' => 'running ' ,
407+ ]);
408+
409+ $ timer = $ workflow ->timers ()
410+ ->create ([
411+ 'index ' => 3 ,
412+ 'stop_at ' => now ()
413+ ->addSecond (),
414+ ]);
415+
416+ $ workflow ->setRelation ('timers ' , new class ([$ timer ]) extends \Illuminate \Database \Eloquent \Collection {
417+ public function firstWhere ($ key , $ operator = null , $ value = null )
418+ {
419+ throw new \BadMethodCallException ('Loaded timer lookup should not rely on firstWhere. ' );
420+ }
421+ });
422+
423+ $ foundTimer = $ workflow ->findTimerByIndex (3 );
424+
425+ $ this ->assertNotNull ($ foundTimer );
426+ $ this ->assertSame ($ timer ->id , $ foundTimer ->id );
427+ }
428+
375429 public function testFindTimerByIndexQueriesWhenTimersRelationIsNotLoaded (): void
376430 {
377431 $ workflow = StoredWorkflow::create ([
0 commit comments