@@ -148,7 +148,7 @@ public function testEnvironmentAddsExtensionWithCustomResolver()
148148 $ factory ->getEngineResolver ()->shouldReceive ('register ' )->once ()->with ('bar ' , $ resolver );
149149 $ factory ->getFinder ()->shouldReceive ('find ' )->once ()->with ('view ' )->andReturn ('path.foo ' );
150150 $ factory ->getEngineResolver ()->shouldReceive ('resolve ' )->once ()->with ('bar ' )->andReturn ($ engine = m::mock (Engine::class));
151- $ factory ->getDispatcher ()->shouldReceive ('dispatch ' );
151+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )-> andReturn ( false );
152152
153153 $ factory ->addExtension ('foo ' , 'bar ' , $ resolver );
154154
@@ -185,11 +185,14 @@ public function testPrependedExtensionOverridesExistingExtensions()
185185 public function testCallCreatorsDoesDispatchEventsWhenIsNecessary ()
186186 {
187187 $ factory = $ this ->getFactory ();
188+
188189 $ factory ->getDispatcher ()
189190 ->shouldReceive ('listen ' )
190191 ->with ('creating: name ' , m::type (Closure::class))
191192 ->once ();
192193
194+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )->andReturn (true );
195+
193196 $ factory ->getDispatcher ()
194197 ->shouldReceive ('dispatch ' )
195198 ->with ('creating: name ' , m::type ('array ' ))
@@ -206,11 +209,14 @@ public function testCallCreatorsDoesDispatchEventsWhenIsNecessary()
206209 public function testCallCreatorsDoesDispatchEventsWhenIsNecessaryUsingNamespacedWildcards ()
207210 {
208211 $ factory = $ this ->getFactory ();
212+
209213 $ factory ->getDispatcher ()
210214 ->shouldReceive ('listen ' )
211215 ->with ('creating: namespaced::* ' , m::type (Closure::class))
212216 ->once ();
213217
218+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )->andReturn (true );
219+
214220 $ factory ->getDispatcher ()
215221 ->shouldReceive ('dispatch ' )
216222 ->with ('creating: namespaced::my-package-view ' , m::type ('array ' ))
@@ -227,6 +233,7 @@ public function testCallCreatorsDoesDispatchEventsWhenIsNecessaryUsingNamespaced
227233 public function testCallCreatorsDoesDispatchEventsWhenIsNecessaryUsingNamespacedNestedWildcards ()
228234 {
229235 $ factory = $ this ->getFactory ();
236+
230237 $ factory ->getDispatcher ()
231238 ->shouldReceive ('listen ' )
232239 ->with ('creating: namespaced::* ' , m::type (Closure::class))
@@ -237,6 +244,8 @@ public function testCallCreatorsDoesDispatchEventsWhenIsNecessaryUsingNamespaced
237244 ->with ('creating: welcome ' , m::type (Closure::class))
238245 ->once ();
239246
247+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )->andReturn (true );
248+
240249 $ factory ->getDispatcher ()
241250 ->shouldReceive ('dispatch ' )
242251 ->with ('creating: namespaced::my-package-view ' , m::type ('array ' ))
@@ -253,11 +262,14 @@ public function testCallCreatorsDoesDispatchEventsWhenIsNecessaryUsingNamespaced
253262 public function testCallCreatorsDoesDispatchEventsWhenIsNecessaryUsingWildcards ()
254263 {
255264 $ factory = $ this ->getFactory ();
265+
256266 $ factory ->getDispatcher ()
257267 ->shouldReceive ('listen ' )
258268 ->with ('creating: * ' , m::type (Closure::class))
259269 ->once ();
260270
271+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )->andReturn (true );
272+
261273 $ factory ->getDispatcher ()
262274 ->shouldReceive ('dispatch ' )
263275 ->with ('creating: name ' , m::type ('array ' ))
@@ -274,11 +286,14 @@ public function testCallCreatorsDoesDispatchEventsWhenIsNecessaryUsingWildcards(
274286 public function testCallCreatorsDoesDispatchEventsWhenIsNecessaryUsingNormalizedNames ()
275287 {
276288 $ factory = $ this ->getFactory ();
289+
277290 $ factory ->getDispatcher ()
278291 ->shouldReceive ('listen ' )
279292 ->with ('creating: components.button ' , m::type (Closure::class))
280293 ->once ();
281294
295+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )->andReturn (true );
296+
282297 $ factory ->getDispatcher ()
283298 ->shouldReceive ('dispatch ' )
284299 ->with ('creating: components/button ' , m::type ('array ' ))
@@ -297,11 +312,14 @@ public function testCallCreatorsDoesDispatchEventsWhenIsNecessaryUsingNormalized
297312 public function testCallComposerDoesDispatchEventsWhenIsNecessary ()
298313 {
299314 $ factory = $ this ->getFactory ();
315+
300316 $ factory ->getDispatcher ()
301317 ->shouldReceive ('listen ' )
302318 ->with ('composing: name ' , m::type (Closure::class))
303319 ->once ();
304320
321+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )->andReturn (true );
322+
305323 $ factory ->getDispatcher ()
306324 ->shouldReceive ('dispatch ' )
307325 ->with ('composing: name ' , m::type ('array ' ))
@@ -318,11 +336,14 @@ public function testCallComposerDoesDispatchEventsWhenIsNecessary()
318336 public function testCallComposerDoesDispatchEventsWhenIsNecessaryAndUsingTheArrayFormat ()
319337 {
320338 $ factory = $ this ->getFactory ();
339+
321340 $ factory ->getDispatcher ()
322341 ->shouldReceive ('listen ' )
323342 ->with ('composing: name ' , m::type (Closure::class))
324343 ->once ();
325344
345+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )->andReturn (true );
346+
326347 $ factory ->getDispatcher ()
327348 ->shouldReceive ('dispatch ' )
328349 ->with ('composing: name ' , m::type ('array ' ))
@@ -339,11 +360,14 @@ public function testCallComposerDoesDispatchEventsWhenIsNecessaryAndUsingTheArra
339360 public function testCallComposersDoesDispatchEventsWhenIsNecessaryUsingNamespacedWildcards ()
340361 {
341362 $ factory = $ this ->getFactory ();
363+
342364 $ factory ->getDispatcher ()
343365 ->shouldReceive ('listen ' )
344366 ->with ('composing: namespaced::* ' , m::type (Closure::class))
345367 ->once ();
346368
369+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )->andReturn (true );
370+
347371 $ factory ->getDispatcher ()
348372 ->shouldReceive ('dispatch ' )
349373 ->with ('composing: namespaced::my-package-view ' , m::type ('array ' ))
@@ -370,6 +394,8 @@ public function testCallComposersDoesDispatchEventsWhenIsNecessaryUsingNamespace
370394 ->with ('composing: welcome ' , m::type (Closure::class))
371395 ->once ();
372396
397+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )->andReturn (true );
398+
373399 $ factory ->getDispatcher ()
374400 ->shouldReceive ('dispatch ' )
375401 ->with ('composing: namespaced::my-package-view ' , m::type ('array ' ))
@@ -386,6 +412,9 @@ public function testCallComposersDoesDispatchEventsWhenIsNecessaryUsingNamespace
386412 public function testCallComposersDoesDispatchEventsWhenIsNecessaryUsingWildcards ()
387413 {
388414 $ factory = $ this ->getFactory ();
415+
416+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )->andReturn (true );
417+
389418 $ factory ->getDispatcher ()
390419 ->shouldReceive ('listen ' )
391420 ->with ('composing: * ' , m::type (Closure::class))
@@ -407,6 +436,9 @@ public function testCallComposersDoesDispatchEventsWhenIsNecessaryUsingWildcards
407436 public function testCallComposersDoesDispatchEventsWhenIsNecessaryUsingNormalizedNames ()
408437 {
409438 $ factory = $ this ->getFactory ();
439+
440+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )->andReturn (true );
441+
410442 $ factory ->getDispatcher ()
411443 ->shouldReceive ('listen ' )
412444 ->with ('composing: components.button ' , m::type (Closure::class))
@@ -496,6 +528,7 @@ public function testCallComposerCallsProperEvent()
496528
497529 $ factory ->composer ('name ' , fn () => true );
498530
531+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )->andReturn (true );
499532 $ factory ->getDispatcher ()->shouldReceive ('dispatch ' )->once ()->with ('composing: name ' , [$ view ]);
500533
501534 $ factory ->callComposer ($ view );
@@ -612,7 +645,7 @@ public function testComponentHandling()
612645 $ factory = $ this ->getFactory ();
613646 $ factory ->getFinder ()->shouldReceive ('find ' )->andReturn (__DIR__ .'/fixtures/component.php ' );
614647 $ factory ->getEngineResolver ()->shouldReceive ('resolve ' )->andReturn (new PhpEngine (new Filesystem ));
615- $ factory ->getDispatcher ()->shouldReceive ('dispatch ' );
648+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )-> andReturn ( false );
616649 $ factory ->startComponent ('component ' , ['name ' => 'Taylor ' ]);
617650 $ factory ->slot ('title ' );
618651 $ factory ->slot ('website ' , 'laravel.com ' , []);
@@ -628,7 +661,7 @@ public function testComponentHandlingUsingViewObject()
628661 $ factory = $ this ->getFactory ();
629662 $ factory ->getFinder ()->shouldReceive ('find ' )->andReturn (__DIR__ .'/fixtures/component.php ' );
630663 $ factory ->getEngineResolver ()->shouldReceive ('resolve ' )->andReturn (new PhpEngine (new Filesystem ));
631- $ factory ->getDispatcher ()->shouldReceive ('dispatch ' );
664+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )-> andReturn ( false );
632665 $ factory ->startComponent ($ factory ->make ('component ' ), ['name ' => 'Taylor ' ]);
633666 $ factory ->slot ('title ' );
634667 $ factory ->slot ('website ' , 'laravel.com ' , []);
@@ -644,7 +677,7 @@ public function testComponentHandlingUsingClosure()
644677 $ factory = $ this ->getFactory ();
645678 $ factory ->getFinder ()->shouldReceive ('find ' )->andReturn (__DIR__ .'/fixtures/component.php ' );
646679 $ factory ->getEngineResolver ()->shouldReceive ('resolve ' )->andReturn (new PhpEngine (new Filesystem ));
647- $ factory ->getDispatcher ()->shouldReceive ('dispatch ' );
680+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )-> andReturn ( false );
648681 $ factory ->startComponent (function ($ data ) use ($ factory ) {
649682 $ this ->assertArrayHasKey ('name ' , $ data );
650683 $ this ->assertSame ($ data ['name ' ], 'Taylor ' );
@@ -810,7 +843,7 @@ public function testMakeWithSlashAndDot()
810843 $ factory = $ this ->getFactory ();
811844 $ factory ->getFinder ()->shouldReceive ('find ' )->twice ()->with ('foo.bar ' )->andReturn ('path.php ' );
812845 $ factory ->getEngineResolver ()->shouldReceive ('resolve ' )->twice ()->with ('php ' )->andReturn (m::mock (Engine::class));
813- $ factory ->getDispatcher ()->shouldReceive ('dispatch ' );
846+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )-> andReturn ( false );
814847 $ factory ->make ('foo/bar ' );
815848 $ factory ->make ('foo.bar ' );
816849 }
@@ -820,7 +853,7 @@ public function testNamespacedViewNamesAreNormalizedProperly()
820853 $ factory = $ this ->getFactory ();
821854 $ factory ->getFinder ()->shouldReceive ('find ' )->twice ()->with ('vendor/package::foo.bar ' )->andReturn ('path.php ' );
822855 $ factory ->getEngineResolver ()->shouldReceive ('resolve ' )->twice ()->with ('php ' )->andReturn (m::mock (Engine::class));
823- $ factory ->getDispatcher ()->shouldReceive ('dispatch ' );
856+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )-> andReturn ( false );
824857 $ factory ->make ('vendor/package::foo/bar ' );
825858 $ factory ->make ('vendor/package::foo.bar ' );
826859 }
@@ -848,7 +881,7 @@ public function testExceptionsInSectionsAreThrown()
848881 $ factory ->getEngineResolver ()->shouldReceive ('resolve ' )->twice ()->andReturn ($ engine );
849882 $ factory ->getFinder ()->shouldReceive ('find ' )->once ()->with ('layout ' )->andReturn (__DIR__ .'/fixtures/section-exception-layout.php ' );
850883 $ factory ->getFinder ()->shouldReceive ('find ' )->once ()->with ('view ' )->andReturn (__DIR__ .'/fixtures/section-exception.php ' );
851- $ factory ->getDispatcher ()->shouldReceive ('dispatch ' )->times (4 ); // 2 "creating" + 2 "composing"...
884+ $ factory ->getDispatcher ()->shouldReceive ('hasListeners ' )->times (4 ); // 2 "creating" + 2 "composing"...
852885
853886 $ factory ->make ('view ' )->render ();
854887 }
0 commit comments