Skip to content

Commit

Permalink
Fix error on static factory with associative array
Browse files Browse the repository at this point in the history
  • Loading branch information
ogizanagi committed Apr 14, 2017
1 parent 056f173 commit 16505e2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
15 changes: 15 additions & 0 deletions tests/Loader/LoaderIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,21 @@ public function provideFixturesToInstantiate()
DummyWithNamedConstructorAndRequiredParameters::namedConstruct(100),
];

yield 'with named constructor and required parameters with named parameters - use factory function' => [
[
DummyWithNamedConstructorAndRequiredParameters::class => [
'dummy' => [
'__construct' => [
'namedConstruct' => [
'param' => 100,
],
],
],
],
],
DummyWithNamedConstructorAndRequiredParameters::namedConstruct(100),
];

yield 'with unknown named constructor' => [
[
DummyWithDefaultConstructor::class => [
Expand Down

0 comments on commit 16505e2

Please sign in to comment.