Skip to content

Commit

Permalink
Return the bound instance when using Container::instance (#19442)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan authored and taylorotwell committed Jun 1, 2017
1 parent fd39889 commit 1ca7c23
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Illuminate/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public function extend($abstract, Closure $closure)
*
* @param string $abstract
* @param mixed $instance
* @return void
* @return mixed
*/
public function instance($abstract, $instance)
{
Expand All @@ -373,6 +373,8 @@ public function instance($abstract, $instance)
if ($isBound) {
$this->rebound($abstract);
}

return $instance;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Contracts/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function extend($abstract, Closure $closure);
*
* @param string $abstract
* @param mixed $instance
* @return void
* @return mixed
*/
public function instance($abstract, $instance);

Expand Down
10 changes: 10 additions & 0 deletions tests/Container/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ public function testMultipleExtends()
$this->assertEquals('foobarbaz', $container->make('foo'));
}

public function testBindingAnInstanceReturnsTheInstance()
{
$container = new Container;

$bound = new StdClass;
$resolved = $container->instance('foo', $bound);

$this->assertSame($bound, $resolved);
}

public function testExtendInstancesArePreserved()
{
$container = new Container;
Expand Down

0 comments on commit 1ca7c23

Please sign in to comment.