Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hydephp/develop into 2.x-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Apr 30, 2024
2 parents d6295f5 + 53019fe commit a954901
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/testing/src/CreatesTemporaryFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Hyde\Facades\Filesystem;
use Hyde\Framework\Actions\ConvertsArrayToFrontMatter;

use function is_dir;
use function dirname;
use function in_array;

trait CreatesTemporaryFiles
Expand All @@ -15,10 +17,15 @@ trait CreatesTemporaryFiles

/**
* Create a temporary file in the project directory.
* The TestCase will automatically remove the file when the test is completed.
*
* The test case will automatically remove the file when the test is completed.
*/
protected function file(string $path, ?string $contents = null): void
{
if (! is_dir(dirname($path))) {
$this->directory(dirname($path));
}

if ($contents) {
Filesystem::put($path, $contents);
} else {
Expand All @@ -30,7 +37,8 @@ protected function file(string $path, ?string $contents = null): void

/**
* Create a temporary directory in the project directory.
* The TestCase will automatically remove the entire directory when the test is completed.
*
* The test case will automatically remove the entire directory when the test is completed.
*/
protected function directory(string $path): void
{
Expand All @@ -40,13 +48,16 @@ protected function directory(string $path): void
}

/**
* Create a temporary Markdown+FrontMatter file in the project directory.
* Create a temporary Markdown file with front matter in the project directory.
*/
protected function markdown(string $path, string $contents = '', array $matter = []): void
{
$this->file($path, (new ConvertsArrayToFrontMatter())->execute($matter).$contents);
}

/**
* Clean up the filesystem after the test has completed.
*/
protected function cleanUpFilesystem(): void
{
if (sizeof($this->fileMemory) > 0) {
Expand Down

0 comments on commit a954901

Please sign in to comment.