Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/Di.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ public function get($name, array $params = array())
return $im->getSharedInstance($name, $params);
}
}
$instance = $this->newInstance($name, $params);
$config = $im->getConfig($name);
$instance = $this->newInstance($name, $params, $config['shared']);
array_pop($this->instanceContext);

return $instance;
Expand Down
34 changes: 25 additions & 9 deletions test/DiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ public function testDiConstructorCanTakeDependencies()
$this->assertSame($im, $di->instanceManager());
}

public function testPassingInvalidDefinitionRaisesException()
{
$di = new Di();

$this->setExpectedException('PHPUnit_Framework_Error');
$di->setDefinitionList(array('foo'));
}

public function testGetRetrievesObjectWithMatchingClassDefinition()
{
$di = new Di();
Expand All @@ -65,14 +57,38 @@ public function testGetRetrievesObjectWithMatchingClassDefinition()

public function testGetRetrievesSameInstanceOnSubsequentCalls()
{
$di = new Di();
$config = new Config(array(
'instance' => array(
'ZendTest\Di\TestAsset\BasicClass' => array(
'shared' => true,
),
),
));
$di = new Di(null, null, $config);
$obj1 = $di->get('ZendTest\Di\TestAsset\BasicClass');
$obj2 = $di->get('ZendTest\Di\TestAsset\BasicClass');
$this->assertInstanceOf('ZendTest\Di\TestAsset\BasicClass', $obj1);
$this->assertInstanceOf('ZendTest\Di\TestAsset\BasicClass', $obj2);
$this->assertSame($obj1, $obj2);
}

public function testGetRetrievesDifferentInstanceOnSubsequentCallsIfSharingDisabled()
{
$config = new Config(array(
'instance' => array(
'ZendTest\Di\TestAsset\BasicClass' => array(
'shared' => false,
),
),
));
$di = new Di(null, null, $config);
$obj1 = $di->get('ZendTest\Di\TestAsset\BasicClass');
$obj2 = $di->get('ZendTest\Di\TestAsset\BasicClass');
$this->assertInstanceOf('ZendTest\Di\TestAsset\BasicClass', $obj1);
$this->assertInstanceOf('ZendTest\Di\TestAsset\BasicClass', $obj2);
$this->assertNotSame($obj1, $obj2);
}

public function testGetThrowsExceptionWhenUnknownClassIsUsed()
{
$di = new Di();
Expand Down

0 comments on commit e8c20f9

Please sign in to comment.