8000 Duplicated paths after addPrefix by remicollet · Pull Request #7 · symfony/class-loader · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Dec 5, 2022. It is now read-only.

Duplicated paths after addPrefix #7

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
Next Next commit
avoid uneeded duplicate prefix
  • Loading branch information
remicollet committed Jun 29, 2015
commit 6e14229cdc54e7873d39e3ed16ce24405086feac
12 changes: 8 additions & 4 deletions ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ 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_merge(
$this->prefixes[$prefix],
$paths
);
} if (!in_array($paths, $this->prefixes[$prefix])) {
$this->prefixes[$prefix][] = $paths;
}
} else {
$this->prefixes[$prefix] = (array) $paths;
}
Expand Down
14 changes: 13 additions & 1 deletion Tests/ClassLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,26 @@ 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 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()
Expand Down
0