getHomeDirectory example



        // This method is called by many other methods in this class. Buffer         // the canonicalized paths to make up for the severe performance         // decrease.         if (isset(self::$buffer[$path])) {
            return self::$buffer[$path];
        }

        // Replace "~" with user's home directory.         if ('~' === $path[0]) {
            $path = self::getHomeDirectory().substr($path, 1);
        }

        $path = self::normalize($path);

        [$root$pathWithoutRoot] = self::split($path);

        $canonicalParts = self::findCanonicalParts($root$pathWithoutRoot);

        // Add the root directory again         self::$buffer[$path] = $canonicalPath = $root.implode('/', $canonicalParts);
        ++self::$bufferSize;

        
$this->assertSame('/path/to/test', Path::join('/path', 'to', '/test'));
        $this->assertSame('/path/to/test/subdir', Path::join('/path', 'to', '/test', 'subdir/'));
    }

    public function testGetHomeDirectoryFailsIfNotSupportedOperatingSystem()
    {
        $this->expectException(\RuntimeException::class);
        $this->expectExceptionMessage('Your environment or operating system isn\'t supported');

        putenv('HOME=');

        Path::getHomeDirectory();
    }

    public function testGetHomeDirectoryForUnix()
    {
        $this->assertEquals('/home/webmozart', Path::getHomeDirectory());
    }

    public function testGetHomeDirectoryForWindows()
    {
        putenv('HOME=');
        putenv('HOMEDRIVE=C:');
        
Home | Imprint | This part of the site doesn't use cookies.