Skip to content

Commit

Permalink
Merge pull request #111 from cspray/inspect-tests
Browse files Browse the repository at this point in the history
Adds test for inspecting shares
  • Loading branch information
rdlowrey committed Jul 26, 2015
2 parents 66f9862 + 366d4e3 commit cfce81b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/Injector.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ public function inspect($nameFilter = null, $typeFilter = null)
self::I_ALIASES => "aliases",
self::I_SHARES => "shares"
);

foreach ($types as $type => $source) {
if ($typeFilter & $type) {
$result[$type] = $this->filter($this->{$source}, $name);
Expand All @@ -315,8 +316,8 @@ private function filter($source, $name)
{
if (empty($name)) {
return $source;
} elseif (isset($source[$name])) {
return $source[$name];
} elseif (array_key_exists($name, $source)) {
return array($name => $source[$name]);
} else {
return array();
}
Expand Down
9 changes: 9 additions & 0 deletions test/InjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1000,4 +1000,13 @@ public function testDebugMake()
$this->assertEquals('auryn\test\depinterface', $chain[1]);
}
}

public function testInspectShares()
{
$injector = new Injector();
$injector->share('Auryn\Test\SomeClassName');

$inspection = $injector->inspect('Auryn\Test\SomeClassName', Injector::I_SHARES);
$this->assertArrayHasKey('auryn\test\someclassname', $inspection[Injector::I_SHARES]);
}
}

0 comments on commit cfce81b

Please sign in to comment.