-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8c391c
commit 2ae10b0
Showing
17 changed files
with
51 additions
and
66 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,28 @@ | ||
<?php | ||
|
||
namespace DealNews\TestHelpers; | ||
|
||
/** | ||
* Creates a temporary directory with a random name and returns it | ||
* | ||
* @author Brian Moon <[email protected]> | ||
* @copyright 1997-Present DealNews.com, Inc | ||
* @package DealNews\TestHelpers | ||
*/ | ||
trait TmpDir { | ||
|
||
public function tmpDir(?string $base_dir = null): string { | ||
|
||
$base_dir ??= sys_get_temp_dir(); | ||
|
||
do { | ||
$success = false; | ||
$dir = $base_dir . '/' . base64_encode(random_bytes(32)); | ||
if (!file_exists($dir)) { | ||
$success = mkdir($dir); | ||
} | ||
} while (!$success); | ||
|
||
return $dir; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
<?php | ||
|
||
namespace DealNews\TestHelpers\Tests; | ||
|
||
use \DealNews\TestHelpers\TmpDir; | ||
|
||
class TmpDirTest extends \PHPUnit\Framework\TestCase { | ||
|
||
use TmpDir; | ||
|
||
public function testTmpDir() { | ||
$dir = $this->tmpDir(); | ||
|
||
$this->assertTrue(is_dir($dir)); | ||
|
||
$dir2 = $this->tmpDir($dir); | ||
|
||
$this->assertTrue(is_dir($dir)); | ||
|
||
rmdir($dir2); | ||
rmdir($dir); | ||
} | ||
} |