File tree Expand file tree Collapse file tree 2 files changed +63
-0
lines changed 
src/Illuminate/Foundation/Testing/Concerns 
tests/Foundation/Testing/Concerns Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 55use  Closure ;
66use  Illuminate \Foundation \Mix ;
77use  Illuminate \Foundation \Vite ;
8+ use  Illuminate \Support \Defer \DeferredCallbackCollection ;
89use  Illuminate \Support \Facades \Facade ;
910use  Illuminate \Support \HtmlString ;
1011use  Mockery ;
@@ -25,6 +26,13 @@ trait InteractsWithContainer
2526     */ 
2627    protected  $ originalMix
2728
29+     /** 
30+      * The original deferred callbacks collection. 
31+      * 
32+      * @var \Illuminate\Support\Defer\DeferredCallbackCollection|null 
33+      */ 
34+     protected  $ originalDeferredCallbacksCollection
35+ 
2836    /** 
2937     * Register an instance of an object in the container. 
3038     * 
@@ -234,4 +242,38 @@ protected function withMix()
234242
235243        return  $ this 
236244    }
245+ 
246+     /** 
247+      * Execute deferred functions immediately. 
248+      * 
249+      * @return $this 
250+      */ 
251+     protected  function  withoutDefer ()
252+     {
253+         if  ($ this originalDeferredCallbacksCollection  == null ) {
254+             $ this originalDeferredCallbacksCollection  = $ this app ->make (DeferredCallbackCollection::class);
255+         }
256+ 
257+         $ this swap (DeferredCallbackCollection::class, new  class  extends  DeferredCallbackCollection
258+         {
259+             public  function  offsetSet (mixed  $ offsetmixed  $ valuevoid 
260+             {
261+                 $ value
262+             }
263+         });
264+     }
265+ 
266+     /** 
267+      * Restore deferred functions. 
268+      * 
269+      * @return $this 
270+      */ 
271+     protected  function  withDefer ()
272+     {
273+         if  ($ this originalDeferredCallbacksCollection ) {
274+             $ this app ->instance (DeferredCallbackCollection::class, $ this originalDeferredCallbacksCollection );
275+         }
276+ 
277+         return  $ this 
278+     }
237279}
Original file line number Diff line number Diff line change 44
55use  Illuminate \Foundation \Mix ;
66use  Illuminate \Foundation \Vite ;
7+ use  Illuminate \Support \Defer \DeferredCallbackCollection ;
78use  Orchestra \Testbench \TestCase ;
89use  stdClass ;
910
@@ -73,6 +74,26 @@ public function testWithMixRestoresOriginalHandlerAndReturnsInstance()
7374        $ this assertSame ($ this $ instance
7475    }
7576
77+     public  function  testWithoutDefer ()
78+     {
79+         $ called
80+         defer (function  () use  (&$ called
81+             $ called1 ;
82+         });
83+         $ this assertSame ([], $ called
84+ 
85+         $ this withoutDefer ();
86+         defer (function  () use  (&$ called
87+             $ called2 ;
88+         });
89+         $ this assertSame ([2 ], $ called
90+ 
91+         $ this withDefer ();
92+         $ this assertSame ([2 ], $ called
93+         $ this app [DeferredCallbackCollection::class]->invoke ();
94+         $ this assertSame ([2 , 1 ], $ called
95+     }
96+ 
7697    public  function  testForgetMock ()
7798    {
7899        $ this mock (InstanceStub::class)
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments