Skip to content
Permalink
Browse files

Merge pull request #653 from Aijoona/missing-factory-resolver-parameters

Fixes FactoryResolver#resolve ignoring passed parameters
  • Loading branch information...
mnapoli committed Apr 21, 2019
2 parents a634876 + 7e674e6 commit 65987ec266d587e9c3c3fca081d9778ca18303f9
@@ -75,7 +75,7 @@ public function resolve(Definition $definition, array $parameters = [])
try {
$providedParams = [$this->container, $definition];
$extraParams = $this->resolveExtraParams($definition->getParameters());
$providedParams = array_merge($providedParams, $extraParams);
$providedParams = array_merge($providedParams, $extraParams, $parameters);
return $this->invoker->call($callable, $providedParams);
} catch (NotCallableException $e) {
@@ -170,6 +170,25 @@ public function testMakeWithDecorator(ContainerBuilder $builder)
]);
$this->assertEquals('baz', $result->bar);
}
/**
* Test that factory method can access to the values provided to the make call
* @dataProvider provideContainer
*/
public function testFactoryFunctionForwardsPassedParameters(ContainerBuilder $builder)
{
$builder->addDefinitions([
'some_alias' => function ($bar) {
return new Fixture\Foo($bar . ' + local_manipulation');
},
]);
$container = $builder->build();
$result = $container->make('some_alias', [
'bar' => 'baz'
]);
$this->assertEquals('baz + local_manipulation', $result->bar);
}
}
namespace DI\Test\IntegrationTest\Fixture;
@@ -99,14 +99,15 @@ public function should_inject_parameters()
$resolver = new FactoryResolver($container, $this->easyMock(DefinitionResolver::class));
$testCase = $this;
$definition = new FactoryDefinition('foo', function ($c, $par1, $par2) use ($testCase) {
$definition = new FactoryDefinition('foo', function ($c, $par1, $par2, $baz) use ($testCase) {
$testCase->assertEquals('Parameter 1', $par1);
$testCase->assertEquals(2, $par2);
$testCase->assertEquals('bar', $baz);
return $c;
}, ['par1' => 'Parameter 1', 'par2' => 2]);
$value = $resolver->resolve($definition);
$value = $resolver->resolve($definition, ['baz' => 'bar']);
$this->assertInstanceOf(ContainerInterface::class, $value);
}

0 comments on commit 65987ec

Please sign in to comment.
You can’t perform that action at this time.