diff --git a/ClassLoader.php b/ClassLoader.php index 6fcbb06..1343bdb 100644 --- a/ClassLoader.php +++ b/ClassLoader.php @@ -91,12 +91,16 @@ public function addPrefix($prefix, $paths) return; } if (isset($this->prefixes[$prefix])) { - $this->prefixes[$prefix] = array_merge( - $this->prefixes[$prefix], - (array) $paths - ); + if (is_array($paths)) { + $this->prefixes[$prefix] = array_unique(array_merge( + $this->prefixes[$prefix], + $paths + )); + } else if (!in_array($paths, $this->prefixes[$prefix])) { + $this->prefixes[$prefix][] = $paths; + } } else { - $this->prefixes[$prefix] = (array) $paths; + $this->prefixes[$prefix] = array_unique((array) $paths); } } diff --git a/Tests/ClassLoaderTest.php b/Tests/ClassLoaderTest.php index a870935..09eea04 100644 --- a/Tests/ClassLoaderTest.php +++ b/Tests/ClassLoaderTest.php @@ -76,14 +76,36 @@ public function getLoadNonexistentClassTests() ); } - public function testAddPrefix() + public function testAddPrefixSingle() { $loader = new ClassLoader(); $loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); $loader->addPrefix('Foo', __DIR__.DIRECTORY_SEPARATOR.'Fixtures'); $prefixes = $loader->getPrefixes(); $this->assertArrayHasKey('Foo', $prefixes); + $this->assertCount(1, $prefixes['Foo']); + } + + public function testAddPrefixesSingle() + { + $loader = new ClassLoader(); + $loader->addPrefixes(array('Foo' => array('foo', 'foo'))); + $loader->addPrefixes(array('Foo' => array('foo'))); + $prefixes = $loader->getPrefixes(); + $this->assertArrayHasKey('Foo', $prefixes); + $this->assertCount(1, $prefixes['Foo'], print_r($prefixes, true)); + } + + public function testAddPrefixMulti() + { + $loader = new ClassLoader(); + $loader->addPrefix('Foo', 'foo'); + $loader->addPrefix('Foo', 'bar'); + $prefixes = $loader->getPrefixes(); + $this->assertArrayHasKey('Foo', $prefixes); $this->assertCount(2, $prefixes['Foo']); + $this->assertContains('foo', $prefixes['Foo']); + $this->assertContains('bar', $prefixes['Foo']); } public function testUseIncludePath()