public static function setUpBeforeClass() { static::$popBackTo = getcwd(); static::$fs = new Filesystem(); $crypto = new Cryptography(); $workDirPath = static::$popBackTo . '/____tmp____'; static::$fs->mkdir($workDirPath); chdir($workDirPath); static::$dir = new Directory($workDirPath); // Generate some random directories and files with random levels of depth foreach (range(0, 100) as $i) { $rand = $crypto->random(0, 1); $depths = range(2, $crypto->random(1, 6)); $type = 'file'; if ($rand === 0) { $type = 'dir'; } $name = $crypto->randomString($crypto->random(5, 20), 'alpha'); $ext = $crypto->randomString(3, 'alpha'); $name = static::$fs->makeUniqueName(strtolower($name . ($type !== 'dir' ? '.' . $ext : ''))); // Split the name into chunks $names = array_chunk(str_split($name), count($depths)); foreach ($names as $k => $pieces) { $names[$k] = join('', $pieces); } $filename =& $names[count($names) - 1]; // If the last piece doesn't have something usable for a filename, then take pieces before it till the name is good if ($type === 'file' && !preg_match('/^\\w+\\.\\w{3}$/', $filename)) { for ($i = count($names) - 2, $good = false; $i > 0 && !$good; $i--) { $filename = $names[$i] . $filename; $good = (bool) preg_match('/^\\w+\\.\\w{3}$/', $filename); } } $fullPath = $workDirPath . '/' . str_replace('./', '/', join('/', $names)); $dir = dirname($fullPath); if ($dir === $workDirPath) { continue; } static::$fs->mkdir($dir); static::$fs->touch($fullPath); static::$dirs[] = new Directory($dir, true); } // Sort directories by how many levels they go descending usort(static::$dirs, function ($a, $b) { $a = count(explode('/', (string) $a)); $b = count(explode('/', (string) $b)); if ($a === $b) { return 0; } return $a > $b ? -1 : 1; }); }
/** * Lazily loads Filesytem object. */ protected static function initializeFilesystem() { if (!static::$fs) { static::$fs = new Filesystem(); } }
protected static function initFilesystem() { static::$fs = new Filesystem(); }