-
Notifications
You must be signed in to change notification settings - Fork 89
ServiceManager returns that service does not exist with has() but can create with get() #50
Comments
Regarding your tests: The first one passes because after calling "get", the service is added to your invokable services (autoAddInvokableClass). Your second case fails, because the service has not been added to your invokables when you call "has" |
@demichl68 the point is that service manager does not allow to check if it can create instance has() return false but get() can create |
also if service manager implements container-interop then this https://github.com/container-interop/container-interop/blob/master/src/Interop/Container/ContainerInterface.php#L29 states that has() should return true if it can create instance with given identifier
|
This bug also breaks a test of
public function setUp()
{
Cache\StorageFactory::resetAdapterPluginManager();
Cache\StorageFactory::resetPluginManager();
$this->sm = new ServiceManager([
'services' => [
'config' => [
'caches' => [
'Memory' => [
'adapter' => 'Memory',
'plugins' => ['Serializer', 'ClearExpiredByFactor'],
],
'Foo' => [
'adapter' => 'Memory',
'plugins' => ['Serializer', 'ClearExpiredByFactor'],
],
]
],
],
'abstract_factories' => [
'Zend\Cache\Service\StorageCacheAbstractServiceFactory'
]
]);
}
// ...
public function testCanLookupCacheByName()
{
// Since these are delivered by abstract factory, by default, `has()`
// should return false, as it doesn't consult abstract factories by
// default.
$this->assertFalse($this->sm->has('Memory'));
$this->assertFalse($this->sm->has('Foo'));
// Passing the boolean true to the second argument forces a lookup
// via abstract factory.
$this->assertTrue($this->sm->has('Memory', true));
$this->assertTrue($this->sm->has('Foo', true));
} |
@marc-mabe — make sure all adapters that zend-cache provides are registered by their FQCN, with short name aliases to the FQCN. That's the approach we can and should take with all components. @svycka as noted on #51, this is intended behavior. I note a way to get the behavior you request in a comment on that patch request, but we will not be implementing any changes to the existing behavior at this time. |
@weierophinney but this is against container-interop no? there was discussion about this here container-interop/container-interop#37 @Ocramius what do you think? |
@svycka yes, that is an inconsistency with container-interop, but I think we can't do much about it atm (except documenting it) |
Note this has been fixed on V3. Exactly since #49 |
@Maks3w thanks for pointing it out! |
Of course this won't be fixed on V2.
|
I created service manager like this:
I am using like this:
when I sow this I thought maybe I doing it wrong so checked other zend modules like zend-filter and wrote some tests:
First pass second fails.
order of has() and get() is important?
The text was updated successfully, but these errors were encountered: