@@ -164,4 +164,52 @@ function ($container, $name, $callback) {
164
164
);
165
165
$ this ->assertEquals ('bar ' , $ instance ->foo );
166
166
}
167
+
168
+ public function testWithConfigProperlySetsCreationContextToOriginalCreationContext ()
169
+ {
170
+ $ config = [
171
+ 'factories ' => [
172
+ InvokableObject::class => new InvokableFactory (),
173
+ ],
174
+ ];
175
+
176
+ $ services = new ServiceManager ();
177
+ $ plugins = new SimplePluginManager ($ services );
178
+
179
+ $ revised = $ plugins ->withConfig (['factories ' => [
180
+ 'foo ' => function ($ container , $ name ) {
181
+ },
182
+ ]]);
183
+
184
+ $ this ->assertAttributeSame ($ services , 'creationContext ' , $ revised );
185
+ }
186
+
187
+ /**
188
+ * Overrides test from CommonServiceLocatorBehaviorsTrait
189
+ *
190
+ * Behavior of creation context differs for plugin managers.
191
+ */
192
+ public function testCanCreateNewLocatorWithMergedConfig ()
193
+ {
194
+ $ serviceManager = $ this ->createContainer ([
195
+ 'factories ' => [
196
+ DateTime::class => InvokableFactory::class
197
+ ]
198
+ ]);
199
+
200
+ $ newServiceManager = $ serviceManager ->withConfig ([
201
+ 'factories ' => [
202
+ stdClass::class => InvokableFactory::class
203
+ ]
204
+ ]);
205
+
206
+ $ this ->assertTrue ($ serviceManager ->has (DateTime::class));
207
+ $ this ->assertFalse ($ serviceManager ->has (stdClass::class));
208
+
209
+ $ this ->assertTrue ($ newServiceManager ->has (DateTime::class));
210
+ $ this ->assertTrue ($ newServiceManager ->has (stdClass::class));
211
+
212
+ // Make sure the context has been updated for the new container
213
+ $ this ->assertAttributeSame ($ this ->creationContext , 'creationContext ' , $ newServiceManager );
214
+ }
167
215
}
0 commit comments