public function testGetAutoloadDir() { $dir = dirname(__DIR__) . '/files/config/autoload'; $listener = new ConfigReaderAutoloadListener(); $listener->setAutoloadDir($dir); $this->assertSame(Normalizer::path($dir), $listener->getAutoloadDir()); }
/** * Sets the directory for autoloading of configuration files. * * @param string $dir The path to directory * * @throws \InvalidArgumentException If the received directory is not * non-empty string or if this directory * not exists */ public function setAutoloadDir($dir) { if (!is_string($dir) || empty($dir)) { throw new InvalidArgumentException(sprintf('Invalid directory for autoload of configuration provided; ' . 'must be a non-empty string, "%s" received.', is_object($dir) ? get_class($dir) : gettype($dir))); } $dir = Normalizer::path($dir); if (!file_exists($dir) || !is_dir($dir)) { throw new InvalidArgumentException(sprintf('The directory "%s", specified for autoload of configurations, ' . 'does not exists.', $dir)); } $this->autoloadDir = $dir; }
public function testRegisterPaths() { $paths = ['foo', 'bar/baz', 'bat/ban/banan']; $loader = new ModuleLoader(); $return = $loader->registerPaths($paths); $this->assertSame($return, $loader); $expected = []; foreach ($paths as $path) { $expected[] = Normalizer::path($path); } $this->assertEquals($expected, $loader->getPaths()); }
public function testRegisterPathPrepend() { $config = ['Test\\Foo' => 'Path/To/Foo', 'Test\\Foo\\' => 'OtherPath/To/Foo', 'Test\\Bar' => 'Path/To/Bar', 'Test\\Baz' => 'Path/To/Baz']; $loader = new ClassLoader(); foreach ($config as $namespace => $path) { $return = $loader->registerPath($namespace, $path, true); $this->assertSame($return, $loader); } $expected = []; foreach ($config as $namespace => $path) { $namespace = Normalizer::ns($namespace, true); $path = Normalizer::path($path, true); if (!isset($expected[$namespace])) { $expected[$namespace] = []; } array_unshift($expected[$namespace], $path); } $this->assertEquals($expected, $loader->getPaths()); }
public function testNsWithoutTrailingBackslash() { $class = '\\Foo\\Bar\\Baz\\'; $expected = 'Foo\\Bar\\Baz'; $this->assertEquals($expected, Normalizer::ns($class)); }