8
8
namespace ZendTest \ServiceManager ;
9
9
10
10
use DateTime ;
11
- use Interop \Container \Exception \ContainerException ;
12
11
use PHPUnit \Framework \TestCase ;
13
12
use Psr \Container \ContainerInterface ;
14
13
use stdClass ;
15
- use Zend \ServiceManager \Exception \ServiceNotCreatedException ;
16
- use Zend \ServiceManager \Exception \ServiceNotFoundException ;
17
14
use Zend \ServiceManager \Factory \AbstractFactoryInterface ;
18
15
use Zend \ServiceManager \Factory \FactoryInterface ;
19
16
use Zend \ServiceManager \Factory \InvokableFactory ;
@@ -285,18 +282,15 @@ public function testAbstractFactoryShouldBeCheckedForResolvedAliasesInsteadOfAli
285
282
],
286
283
]);
287
284
288
- $ valueMap = [
289
- ['Alias ' , false ],
290
- ['ServiceName ' , true ],
291
- ];
292
-
293
285
$ abstractFactory
294
286
->method ('canCreate ' )
295
287
->withConsecutive (
296
288
[ $ this ->anything (), $ this ->equalTo ('Alias ' ) ],
297
289
[ $ this ->anything (), $ this ->equalTo ('ServiceName ' )]
298
290
)
299
- ->willReturn ($ this ->returnValueMap ($ valueMap ));
291
+ ->willReturnCallback (function ($ context , $ name ) {
292
+ return $ name === 'Alias ' ;
293
+ });
300
294
$ this ->assertTrue ($ serviceManager ->has ('Alias ' ));
301
295
}
302
296
@@ -315,4 +309,56 @@ public function testFactoryMayBeStaticMethodDescribedByCallableString()
315
309
$ serviceManager = new SimpleServiceManager ($ config );
316
310
$ this ->assertEquals (stdClass::class, get_class ($ serviceManager ->get (stdClass::class)));
317
311
}
312
+
313
+ public function testResolvedAliasFromAbstractFactory ()
314
+ {
315
+ $ abstractFactory = $ this ->createMock (AbstractFactoryInterface::class);
316
+
317
+ $ serviceManager = new SimpleServiceManager ([
318
+ 'aliases ' => [
319
+ 'Alias ' => 'ServiceName ' ,
320
+ ],
321
+ 'abstract_factories ' => [
322
+ $ abstractFactory ,
323
+ ],
324
+ ]);
325
+
326
+ $ abstractFactory
327
+ ->expects (self ::any ())
328
+ ->method ('canCreate ' )
329
+ ->withConsecutive (
330
+ [self ::anything (), 'Alias ' ],
331
+ [self ::anything (), 'ServiceName ' ]
332
+ )
333
+ ->will (self ::returnCallback (function ($ context , $ name ) {
334
+ return $ name === 'ServiceName ' ;
335
+ }));
336
+
337
+ self ::assertTrue ($ serviceManager ->has ('Alias ' ));
338
+ }
339
+
340
+ public function testResolvedAliasNoMatchingAbstractFactoryReturnsFalse ()
341
+ {
342
+ $ abstractFactory = $ this ->createMock (AbstractFactoryInterface::class);
343
+
344
+ $ serviceManager = new SimpleServiceManager ([
345
+ 'aliases ' => [
346
+ 'Alias ' => 'ServiceName ' ,
347
+ ],
348
+ 'abstract_factories ' => [
349
+ $ abstractFactory ,
350
+ ],
351
+ ]);
352
+
353
+ $ abstractFactory
354
+ ->expects (self ::any ())
355
+ ->method ('canCreate ' )
356
+ ->withConsecutive (
357
+ [self ::anything (), 'Alias ' ],
358
+ [self ::anything (), 'ServiceName ' ]
359
+ )
360
+ ->willReturn (false );
361
+
362
+ self ::assertFalse ($ serviceManager ->has ('Alias ' ));
363
+ }
318
364
}
0 commit comments