Skip to content

Commit

Permalink
Cover #24 with a test
Browse files Browse the repository at this point in the history
This is currently a weird behavior, but we'll keep it for now because it makes sense logically.

See PHP-DI/PHP-DI#628 (comment) for more details.
  • Loading branch information
mnapoli committed May 24, 2020
1 parent 0fcb7c4 commit 3357ef3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/InvokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,29 @@ public function should_resolve_callable_from_container_with_class_name_in_scope_
$this->assertTrue($fixture->wasCalled);
}

/**
* Mixing named parameters with positioned parameters is a really bad idea.
* When that happens, the positioned parameters have the highest priority and will
* override named parameters in case of conflicts.
*
* Note that numeric array indexes ignore string indexes. In our example, the
* 'bar' value has the position `0`, which overrides the 'foo' value.
*
* @test
*/
public function positioned_parameters_have_the_highest_priority()
{
$factory = function ($foo, $bar = 300) {
return [$foo, $bar];
};
$result = $this->invoker->call($factory, [
'foo' => 'foo',
'bar',
]);

$this->assertEquals(['bar', 300], $result);
}

/**
* @test
*/
Expand Down

0 comments on commit 3357ef3

Please sign in to comment.