Skip to content

Commit

Permalink
Merge pull request #17 from bycosta/master
Browse files Browse the repository at this point in the history
Fix unpack error for arrays with string keys.
  • Loading branch information
Harrison Heck authored Apr 4, 2017
2 parents 44eb9dd + 5fa2f63 commit 13238df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Instantiator/ConstructInstantiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class ConstructInstantiator implements InstantiatorInterface
{
public function instantiate(string $class, array $data)
{
return new $class(...$data);
return new $class(...array_values($data));
}
}
9 changes: 9 additions & 0 deletions tests/Instantiator/ConstructInstantiatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Linio\Component\Input\Instantiator;

use Linio\Component\Input\Constraint\Enum;

class ConstructInstantiatorTest extends \PHPUnit_Framework_TestCase
{
public function testIsCreatingInstances()
Expand All @@ -12,4 +14,11 @@ public function testIsCreatingInstances()
$this->assertInstanceOf('ErrorException', $instance);
$this->assertEquals(new \ErrorException('foobar'), $instance);
}

public function testIsHandlingArraysWithStringKeys()
{
$instantiator = new ConstructInstantiator();
$instance = $instantiator->instantiate(Enum::class, ['foo' => [1, 2], 'bar' => 'message']);
$this->assertEquals(new Enum([1, 2], 'message'), $instance);
}
}

0 comments on commit 13238df

Please sign in to comment.