Skip to content

Commit

Permalink
Reset the application only once
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Apr 28, 2022
1 parent 7e291ce commit 8d2dec7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
23 changes: 23 additions & 0 deletions tests/ResetsApplication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Tests;

use Hyde\Framework\Actions\CreatesDefaultDirectories;
use Hyde\Framework\Hyde;
use Hyde\Framework\Services\StarterFileService;
use Illuminate\Support\Facades\File;

trait ResetsApplication
{
public function resetApplication()
{
File::deleteDirectory(Hyde::path('_pages'));
File::deleteDirectory(Hyde::path('_posts'));
File::deleteDirectory(Hyde::path('_media'));
File::deleteDirectory(Hyde::path('_docs'));
File::deleteDirectory(Hyde::path('_site'));

(new CreatesDefaultDirectories)->__invoke();
StarterFileService::publish();
}
}
34 changes: 7 additions & 27 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

namespace Tests;

use Hyde\Framework\Actions\CreatesDefaultDirectories;
use Hyde\Framework\Hyde;
use Hyde\Framework\Services\StarterFileService;
use Illuminate\Support\Facades\File;
use LaravelZero\Framework\Testing\TestCase as BaseTestCase;

/**
* @todo make the directory resets more granular to speed up testing.
*/
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
use ResetsApplication;

protected static bool $booted = false;

/**
* Setup the test environment.
Expand All @@ -24,16 +20,11 @@ protected function setUp(): void
{
parent::setUp();

File::deleteDirectories([
Hyde::path('_pages'),
Hyde::path('_posts'),
Hyde::path('_media'),
Hyde::path('_docs'),
Hyde::path('_site'),
]);
if (!self::$booted) {
$this->resetApplication();

(new CreatesDefaultDirectories)->__invoke();
StarterFileService::publish();
self::$booted = true;
}
}

/**
Expand All @@ -43,17 +34,6 @@ protected function setUp(): void
*/
protected function tearDown(): void
{
File::deleteDirectories([
Hyde::path('_pages'),
Hyde::path('_posts'),
Hyde::path('_media'),
Hyde::path('_docs'),
Hyde::path('_site'),
]);

(new CreatesDefaultDirectories)->__invoke();
StarterFileService::publish();

parent::tearDown();
}
}

0 comments on commit 8d2dec7

Please sign in to comment.