-
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.
Merge pull request #1 from dealnews/next
Next
- Loading branch information
Showing
20 changed files
with
58 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 |
---|---|---|
|
@@ -8,10 +8,13 @@ | |
* @author Brian Moon <[email protected]> | ||
* @copyright 1997-Present DealNews.com, Inc | ||
* @package DealNews\TestHelpers | ||
* | ||
* @phan-suppress PhanUnreferencedClass | ||
*/ | ||
trait CatchErrors { | ||
|
||
public function setUp(): void { | ||
// @phan-suppress-next-line PhanTraitParentReference | ||
parent::setUp(); | ||
set_error_handler( | ||
static function ($errno, $errstr) { | ||
|
@@ -22,6 +25,7 @@ static function ($errno, $errstr) { | |
} | ||
|
||
public function tearDown(): void { | ||
// @phan-suppress-next-line PhanTraitParentReference | ||
parent::tearDown(); | ||
restore_error_handler(); | ||
} | ||
|
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
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 . '/' . hash('sha256', (random_bytes(32))); | ||
if (!file_exists($dir)) { | ||
$success = mkdir($dir, recursive: true); | ||
} | ||
} 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($dir2)); | ||
|
||
rmdir($dir2); | ||
rmdir($dir); | ||
} | ||
} |