Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit 37e7268

Browse files
author
fhein
committed
Fixed bug in abstract factory mock in
testAbstractFactoryShouldBeCheckedForResolvedAliasesInsteadOfAliasName. Added check of resolved aliases against abstract factories.
1 parent c40bb38 commit 37e7268

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/ServiceManager.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,16 @@ public function has($name)
267267

268268
// Finally check aliases
269269
$resolvedName = $this->aliases[$name];
270-
return isset($this->services[$resolvedName]) || isset($this->factories[$resolvedName]);
270+
if (isset($this->services[$resolvedName]) || isset($this->factories[$resolvedName])) {
271+
return true;
272+
}
273+
274+
// Check abstract factories on $resolvedName also
275+
foreach ($this->abstractFactories as $abstractFactory) {
276+
if ($abstractFactory->canCreate($this->creationContext, $resolvedName)) {
277+
return true;
278+
}
279+
}
271280
}
272281

273282
/**

test/ServiceManagerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public function testSetAliasShouldWorkWithRecursiveAlias()
272272
self::assertSame($service, $headAlias);
273273
}
274274

275-
public function testAbstractFactoryShouldBeCheckedForResolvedAliasesInsteadOfAliasNameName()
275+
public function testAbstractFactoryShouldBeCheckedForResolvedAliasesInsteadOfAliasName()
276276
{
277277
$abstractFactory = $this->createMock(AbstractFactoryInterface::class);
278278

@@ -288,8 +288,8 @@ public function testAbstractFactoryShouldBeCheckedForResolvedAliasesInsteadOfAli
288288
$abstractFactory
289289
->expects(self::once())
290290
->method('canCreate')
291-
->with(self::anything(), 'ServiceName')
292-
->willReturn(true);
291+
->with($this->anything())
292+
->willReturn($this->equalTo('ServiceName'));
293293

294294
$this->assertTrue($serviceManager->has('Alias'));
295295
}

0 commit comments

Comments
 (0)