Move initialization of settings to trait

This commit is contained in:
Marcus Moore 2023-04-13 16:52:20 -07:00
parent 7c95e45178
commit 473241edca
No known key found for this signature in database
2 changed files with 7 additions and 5 deletions

View file

@ -4,5 +4,10 @@ namespace Tests\Support;
trait InteractsWithSettings
{
protected Settings $settings;
public function setUpSettings()
{
$this->settings = Settings::initialize();
}
}

View file

@ -6,15 +6,12 @@ use App\Http\Middleware\SecurityHeaders;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Tests\Support\InteractsWithSettings;
use Tests\Support\Settings;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
use LazilyRefreshDatabase;
protected Settings $settings;
private array $globallyDisabledMiddleware = [
SecurityHeaders::class,
];
@ -25,8 +22,8 @@ abstract class TestCase extends BaseTestCase
$this->withoutMiddleware($this->globallyDisabledMiddleware);
if (in_array(InteractsWithSettings::class, class_uses_recursive($this))) {
$this->settings = Settings::initialize();
if (collect(class_uses_recursive($this))->contains(InteractsWithSettings::class)) {
$this->setUpSettings();
}
}
}