-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added TestUtil class and fixed path issue on Windows
- Loading branch information
Showing
4 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the webmozart/glob package. | ||
* | ||
* (c) Bernhard Schussek <bschussek@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Webmozart\Glob\Test; | ||
|
||
/** | ||
* Contains utility methods for testing. | ||
* | ||
* @since 3.1 | ||
* | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
*/ | ||
final class TestUtil | ||
{ | ||
/** | ||
* Creates a temporary directory. | ||
* | ||
* @param string $namespace The directory path in the system's temporary | ||
* directory. | ||
* @param string $className 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 | ||
$basePath = realpath(sys_get_temp_dir()).'/'.$namespace.'/'.$shortClass; | ||
|
||
while (false === @mkdir($tempDir = $basePath.rand(10000, 99999), 0777, true)) { | ||
// Run until we are able to create a directory | ||
} | ||
|
||
return $tempDir; | ||
} | ||
|
||
private function __construct() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters