Permalink
Browse files

Return unique dependencies only

- Sorts for unique dependencies
  • Loading branch information...
weierophinney committed Nov 30, 2010
1 parent 7dbd16d commit 50aba0f5507dcb15c6672fafcc7deb54d9cb5cf1
@@ -156,6 +156,9 @@ protected static function parse(array $tokens)
$dependencies[$k] = $segments[0] . '\\' . $segments[1];
}
+ // Sort for uniques
+ $dependencies = array_unique($dependencies);
+
// Return early if we don't have a namespace, or if we didn't find
// any dependencies
if (empty($namespace) || empty($dependencies)) {
@@ -63,4 +63,17 @@ public function testImportAliasesAreIgnored()
$this->assertContains($class, $deps);
}
}
+
+ public function testReturnsUniquesOnly()
+ {
+ $deps = Dependencies::getForFile(__DIR__ . '/_files/TestCase6.php');
+ $expected = array(
+ 'Foo\Bar',
+ 'Baz\Bat',
+ );
+ $this->assertEquals(count($expected), count($deps));
+ foreach ($expected as $class) {
+ $this->assertContains($class, $deps);
+ }
+ }
}
@@ -0,0 +1,10 @@
+<?php
+namespace Bar\Baz\Beef;
+
+use Foo\Bar\Baz as FooBar,
+ Bar\Baz\Bat as BazBat,
+ Foo\Bar\Bat as FooBat,
+ Baz\Bat\Bogus;
+use Baz\Bat as Bazzie;
+
+

0 comments on commit 50aba0f

Please sign in to comment.