File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -136,13 +136,13 @@ public static function swapMock(): Mockery\MockInterface
136136 {
137137 $ accessor = static ::getFacadeAccessor ();
138138 $ mock = static ::createMock ();
139- self ::$ resolvedInstances [$ accessor ] = $ mock ;
139+ static ::$ resolvedInstances [$ accessor ] = $ mock ;
140140
141141 return $ mock ;
142142 }
143143
144144 /**
145- * Set the container instance.
145+ * Set the container instance. Reset any cache instances in the process.
146146 *
147147 * @codeCoverageIgnore
148148 *
@@ -151,6 +151,8 @@ public static function swapMock(): Mockery\MockInterface
151151 */
152152 public static function setContainer (ContainerInterface $ container ): void
153153 {
154+ static ::clear ();
155+
154156 static ::$ container = $ container ;
155157 }
156158
Original file line number Diff line number Diff line change @@ -161,4 +161,21 @@ public function testSwapMock(): void
161161 $ result = ServiceFacade::greeting ('World ' ); // @phpstan-ignore-line
162162 $ this ->assertEquals ('Hello World! ' , $ result );
163163 }
164+
165+ public function testSettingContainerClearsFacadeCache (): void
166+ {
167+ $ firstService = new Service ();
168+ $ firstContainer = new Container ($ firstService );
169+ ServiceFacade::setContainer ($ firstContainer );
170+ $ firstRoot = ServiceFacade::getFacadeRoot ();
171+ $ this ->assertSame ($ firstRoot , $ firstService );
172+
173+ $ secondService = new Service ();
174+ $ secondContainer = new Container ($ secondService );
175+ ServiceFacade::setContainer ($ secondContainer );
176+ $ secondRoot = ServiceFacade::getFacadeRoot ();
177+ $ this ->assertSame ($ secondRoot , $ secondService );
178+
179+ $ this ->assertNotSame ($ firstRoot , $ secondRoot );
180+ }
164181}
You can’t perform that action at this time.
0 commit comments