Webmozart\Glob\Test\TestUtil::makeTempDir PHP Method

makeTempDir() public static method

Creates a temporary directory.
public static makeTempDir ( string $namespace, string $className ) : string
$namespace string The directory path in the system's temporary directory.
$className string The name of the test class.
return string The path to the created directory.
    public static function makeTempDir($namespace, $className)
    {
        if (false !== ($pos = strrpos($className, '\\'))) {
            $shortClass = substr($className, $pos + 1);
        } else {
            $shortClass = $className;
        }
        // Usage of realpath() is important if the temporary directory is a
        // symlink to another directory (e.g. /var => /private/var on some Macs)
        // We want to know the real path to avoid comparison failures with
        // code that uses real paths only
        $systemTempDir = Path::normalize(realpath(sys_get_temp_dir()));
        $basePath = $systemTempDir . '/' . $namespace . '/' . $shortClass;
        while (false === @mkdir($tempDir = $basePath . rand(10000, 99999), 0777, true)) {
            // Run until we are able to create a directory
        }
        return $tempDir;
    }

Usage Example

Example #1
0
 protected function setUp()
 {
     $this->tempDir = TestUtil::makeTempDir('puli-manager', __CLASS__);
     $this->storage = new FilesystemStorage();
     $this->path = $this->tempDir . '/test-file';
     file_put_contents($this->path, self::CONTENTS);
 }
All Usage Examples Of Webmozart\Glob\Test\TestUtil::makeTempDir