Introduce trait to conditionally interact with settings

This commit is contained in:
Marcus Moore 2023-04-12 17:28:47 -07:00
parent cd0796ddda
commit 7c95e45178
No known key found for this signature in database
4 changed files with 18 additions and 1 deletions

View file

@ -6,10 +6,13 @@ use App\Models\Asset;
use App\Models\User;
use Illuminate\Testing\Fluent\AssertableJson;
use Laravel\Passport\Passport;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class AssetIndexTest extends TestCase
{
use InteractsWithSettings;
public function testAssetIndexReturnsExpectedAssets()
{
Asset::factory()->count(3)->create();

View file

@ -6,10 +6,13 @@ use App\Models\Company;
use App\Models\User;
use Illuminate\Testing\Fluent\AssertableJson;
use Laravel\Passport\Passport;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
class UsersForSelectListTest extends TestCase
{
use InteractsWithSettings;
public function testUsersAreReturned()
{
$users = User::factory()->superuser()->count(3)->create();

View file

@ -0,0 +1,8 @@
<?php
namespace Tests\Support;
trait InteractsWithSettings
{
}

View file

@ -5,6 +5,7 @@ namespace Tests;
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
@ -24,6 +25,8 @@ abstract class TestCase extends BaseTestCase
$this->withoutMiddleware($this->globallyDisabledMiddleware);
$this->settings = Settings::initialize();
if (in_array(InteractsWithSettings::class, class_uses_recursive($this))) {
$this->settings = Settings::initialize();
}
}
}