Skip to content

Commit

Permalink
bugfix regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rasmus Schultz committed Jan 13, 2016
1 parent b3392dc commit f6ae510
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 268,7 @@ public function alias($name, $ref_name)
*
* @throws NotFoundException
*/
public function configure($name_or_func, $func_or_map = null, $map = null)
public function configure($name_or_func, $func_or_map = null, $map = [])
{
if (is_callable($name_or_func)) {
$func = $name_or_func;
Expand All @@ -292,6 292,10 @@ public function configure($name_or_func, $func_or_map = null, $map = null)
} else {
$name = $name_or_func;
$func = $func_or_map;

if (!array_key_exists(0, $map)) {
$map[0] = $this->ref($name);
}
}

$this->config[$name][] = $func;
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,9 @@ public function __invoke($foo) {
}
}

class Bar {}
class Bar {
public $value = 1;
}

abstract class AbstractClass
{
Expand Down
15 changes: 15 additions & 0 deletions test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 188,21 @@ function (Foo $foo, Bar $bar) use (&$ok) {
}
);

test(
'configure("name", function (T $o))',
function () {
$container = new Container();

$container->register('name', Bar::class);

$container->configure('name', function (Bar $bar) {
$bar->value = 1;
});

eq($container->get('name')->value, 2, 'can configure named component');
}
);

test(
'named components take precedence over type-hints',
function () {
Expand Down

0 comments on commit f6ae510

Please sign in to comment.