public function testAddPrefix() { $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(2, $prefixes['Foo']); }
/** * Finds file to store a class. * * @param string $class * * @return string * * @throws ContextNotFoundException If class file could not be determined */ private function findClassFile($class) { list($classpath, $classname) = $this->findClasspathAndClass($class); $classpath .= str_replace('_', DIRECTORY_SEPARATOR, $classname) . '.php'; foreach ($this->autoloader->getPrefixes() as $prefix => $dirs) { if (0 === strpos($class, $prefix)) { return current($dirs) . DIRECTORY_SEPARATOR . $classpath; } } if ($dirs = $this->autoloader->getFallbackDirs()) { return current($dirs) . DIRECTORY_SEPARATOR . $classpath; } throw new ContextNotFoundException(sprintf('Could not find where to put "%s" class. Have you configured autoloader properly?', $class), $class); }
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']); }