diff --git a/src/Generator/Instantiator/Chainable/StaticFactoryInstantiator.php b/src/Generator/Instantiator/Chainable/StaticFactoryInstantiator.php index eec34bd85..11bcbd7ab 100644 --- a/src/Generator/Instantiator/Chainable/StaticFactoryInstantiator.php +++ b/src/Generator/Instantiator/Chainable/StaticFactoryInstantiator.php @@ -47,7 +47,7 @@ protected function createInstance(FixtureInterface $fixture) $arguments = []; } - $instance = $factory::$method(...$arguments); + $instance = $factory::$method(...array_values($arguments)); if (false === $instance instanceof $class) { throw InstantiationExceptionFactory::createForInvalidInstanceType($fixture, $instance); } diff --git a/tests/Generator/Instantiator/Chainable/StaticFactoryInstantiatorTest.php b/tests/Generator/Instantiator/Chainable/StaticFactoryInstantiatorTest.php index 844db798c..b73dfd7c1 100644 --- a/tests/Generator/Instantiator/Chainable/StaticFactoryInstantiatorTest.php +++ b/tests/Generator/Instantiator/Chainable/StaticFactoryInstantiatorTest.php @@ -137,6 +137,27 @@ public function testInstantiatesObjectWithFactoryAndArguments() $this->assertEquals($expected, $actual); } + public function testInstantiatesObjectWithFactoryAndNamedArguments() + { + $fixture = new SimpleFixture( + 'dummy', + DummyWithNamedConstructorAndOptionalParameters::class, + SpecificationBagFactory::create( + new MethodCallWithReference( + new StaticReference(DummyWithNamedConstructorAndOptionalParameters::class), + 'namedConstruct', + ['param' => 10] + ) + ) + ); + $set = $this->instantiator->instantiate($fixture, ResolvedFixtureSetFactory::create(), new GenerationContext()); + + $expected = DummyWithNamedConstructorAndOptionalParameters::namedConstruct(10); + $actual = $set->getObjects()->get($fixture)->getInstance(); + + $this->assertEquals($expected, $actual); + } + /** * @expectedException \Nelmio\Alice\Throwable\Exception\Generator\Instantiator\InstantiationException * @expectedExceptionMessage Could not instantiate fixture "dummy".