diff --git a/app/Http/Controllers/Api/ComponentsController.php b/app/Http/Controllers/Api/ComponentsController.php index ddf412a44..9306cefb8 100644 --- a/app/Http/Controllers/Api/ComponentsController.php +++ b/app/Http/Controllers/Api/ComponentsController.php @@ -46,7 +46,7 @@ class ComponentsController extends Controller $components = Company::scopeCompanyables(Component::select('components.*') - ->with('company', 'location', 'category', 'assets')); + ->with('company', 'location', 'category', 'assets', 'supplier')); if ($request->filled('search')) { $components = $components->TextSearch($request->input('search')); @@ -64,6 +64,10 @@ class ComponentsController extends Controller $components->where('category_id', '=', $request->input('category_id')); } + if ($request->filled('supplier_id')) { + $components->where('supplier_id', '=', $request->input('supplier_id')); + } + if ($request->filled('location_id')) { $components->where('location_id', '=', $request->input('location_id')); } @@ -90,6 +94,9 @@ class ComponentsController extends Controller case 'company': $components = $components->OrderCompany($order); break; + case 'supplier': + $components = $components->OrderSupplier($order); + break; default: $components = $components->orderBy($column_sort, $order); break; diff --git a/app/Http/Controllers/Api/ConsumablesController.php b/app/Http/Controllers/Api/ConsumablesController.php index a075fce56..927c9d29f 100644 --- a/app/Http/Controllers/Api/ConsumablesController.php +++ b/app/Http/Controllers/Api/ConsumablesController.php @@ -75,6 +75,10 @@ class ConsumablesController extends Controller $consumables->where('manufacturer_id', '=', $request->input('manufacturer_id')); } + if ($request->filled('supplier_id')) { + $consumables->where('supplier_id', '=', $request->input('supplier_id')); + } + if ($request->filled('location_id')) { $consumables->where('location_id','=',$request->input('location_id')); } @@ -109,6 +113,9 @@ class ConsumablesController extends Controller case 'company': $consumables = $consumables->OrderCompany($order); break; + case 'supplier': + $components = $consumables->OrderSupplier($order); + break; default: $consumables = $consumables->orderBy($column_sort, $order); break; diff --git a/app/Http/Controllers/Api/SuppliersController.php b/app/Http/Controllers/Api/SuppliersController.php index 0a1710d18..a342e5583 100644 --- a/app/Http/Controllers/Api/SuppliersController.php +++ b/app/Http/Controllers/Api/SuppliersController.php @@ -23,11 +23,30 @@ class SuppliersController extends Controller public function index(Request $request) { $this->authorize('view', Supplier::class); - $allowed_columns = ['id', 'name', 'address', 'phone', 'contact', 'fax', 'email', 'image', 'assets_count', 'licenses_count', 'accessories_count', 'url']; + $allowed_columns = [' + id', + 'name', + 'address', + 'phone', + 'contact', + 'fax', + 'email', + 'image', + 'assets_count', + 'licenses_count', + 'accessories_count', + 'components_count', + 'consumables_count', + 'url', + ]; $suppliers = Supplier::select( - ['id', 'name', 'address', 'address2', 'city', 'state', 'country', 'fax', 'phone', 'email', 'contact', 'created_at', 'updated_at', 'deleted_at', 'image', 'notes'] - )->withCount('assets as assets_count')->withCount('licenses as licenses_count')->withCount('accessories as accessories_count'); + ['id', 'name', 'address', 'address2', 'city', 'state', 'country', 'fax', 'phone', 'email', 'contact', 'created_at', 'updated_at', 'deleted_at', 'image', 'notes']) + ->withCount('assets as assets_count') + ->withCount('licenses as licenses_count') + ->withCount('accessories as accessories_count') + ->withCount('components as components_count') + ->withCount('consumables as consumables_count'); if ($request->filled('search')) { diff --git a/app/Http/Controllers/Components/ComponentsController.php b/app/Http/Controllers/Components/ComponentsController.php index f943a71a2..2ada97361 100644 --- a/app/Http/Controllers/Components/ComponentsController.php +++ b/app/Http/Controllers/Components/ComponentsController.php @@ -71,6 +71,7 @@ class ComponentsController extends Controller $component = new Component(); $component->name = $request->input('name'); $component->category_id = $request->input('category_id'); + $component->supplier_id = $request->input('supplier_id'); $component->location_id = $request->input('location_id'); $component->company_id = Company::getIdForCurrentUser($request->input('company_id')); $component->order_number = $request->input('order_number', null); @@ -145,6 +146,7 @@ class ComponentsController extends Controller // Update the component data $component->name = $request->input('name'); $component->category_id = $request->input('category_id'); + $component->supplier_id = $request->input('supplier_id'); $component->location_id = $request->input('location_id'); $component->company_id = Company::getIdForCurrentUser($request->input('company_id')); $component->order_number = $request->input('order_number'); diff --git a/app/Http/Controllers/Consumables/ConsumablesController.php b/app/Http/Controllers/Consumables/ConsumablesController.php index f068e9868..0a40c0bb3 100644 --- a/app/Http/Controllers/Consumables/ConsumablesController.php +++ b/app/Http/Controllers/Consumables/ConsumablesController.php @@ -68,6 +68,7 @@ class ConsumablesController extends Controller $consumable = new Consumable(); $consumable->name = $request->input('name'); $consumable->category_id = $request->input('category_id'); + $consumable->supplier_id = $request->input('supplier_id'); $consumable->location_id = $request->input('location_id'); $consumable->company_id = Company::getIdForCurrentUser($request->input('company_id')); $consumable->order_number = $request->input('order_number'); @@ -144,6 +145,7 @@ class ConsumablesController extends Controller $consumable->name = $request->input('name'); $consumable->category_id = $request->input('category_id'); + $consumable->supplier_id = $request->input('supplier_id'); $consumable->location_id = $request->input('location_id'); $consumable->company_id = Company::getIdForCurrentUser($request->input('company_id')); $consumable->order_number = $request->input('order_number'); diff --git a/app/Http/Transformers/ComponentsTransformer.php b/app/Http/Transformers/ComponentsTransformer.php index 1610c3da5..97677af28 100644 --- a/app/Http/Transformers/ComponentsTransformer.php +++ b/app/Http/Transformers/ComponentsTransformer.php @@ -37,6 +37,7 @@ class ComponentsTransformer 'id' => (int) $component->category->id, 'name' => e($component->category->name), ] : null, + 'supplier' => ($component->supplier) ? ['id' => $component->supplier->id, 'name'=> e($component->supplier->name)] : null, 'order_number' => e($component->order_number), 'purchase_date' => Helper::getFormattedDateObject($component->purchase_date, 'date'), 'purchase_cost' => Helper::formatCurrencyOutput($component->purchase_cost), diff --git a/app/Http/Transformers/ConsumablesTransformer.php b/app/Http/Transformers/ConsumablesTransformer.php index 5079b2896..b92f843b7 100644 --- a/app/Http/Transformers/ConsumablesTransformer.php +++ b/app/Http/Transformers/ConsumablesTransformer.php @@ -31,6 +31,7 @@ class ConsumablesTransformer 'item_no' => e($consumable->item_no), 'location' => ($consumable->location) ? ['id' => (int) $consumable->location->id, 'name' => e($consumable->location->name)] : null, 'manufacturer' => ($consumable->manufacturer) ? ['id' => (int) $consumable->manufacturer->id, 'name' => e($consumable->manufacturer->name)] : null, + 'supplier' => ($consumable->supplier) ? ['id' => $consumable->supplier->id, 'name'=> e($consumable->supplier->name)] : null, 'min_amt' => (int) $consumable->min_amt, 'model_number' => ($consumable->model_number != '') ? e($consumable->model_number) : null, 'remaining' => $consumable->numRemaining(), diff --git a/app/Http/Transformers/SuppliersTransformer.php b/app/Http/Transformers/SuppliersTransformer.php index 71307a750..e7546bfd1 100644 --- a/app/Http/Transformers/SuppliersTransformer.php +++ b/app/Http/Transformers/SuppliersTransformer.php @@ -41,6 +41,8 @@ class SuppliersTransformer 'assets_count' => (int) $supplier->assets_count, 'accessories_count' => (int) $supplier->accessories_count, 'licenses_count' => (int) $supplier->licenses_count, + 'consumables_count' => (int) $supplier->consumables_count, + 'components_count' => (int) $supplier->components_count, 'notes' => ($supplier->notes) ? e($supplier->notes) : null, 'created_at' => Helper::getFormattedDateObject($supplier->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($supplier->updated_at, 'datetime'), diff --git a/app/Models/Component.php b/app/Models/Component.php index 98230132b..052ec1219 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -33,7 +33,8 @@ class Component extends SnipeModel 'name' => 'required|min:3|max:255', 'qty' => 'required|integer|min:1', 'category_id' => 'required|integer|exists:categories,id', - 'company_id' => 'integer|nullable', + 'supplier_id' => 'nullable|integer|exists:suppliers,id', + 'company_id' => 'integer|nullable|exists:companies,id', 'min_amt' => 'integer|min:0|nullable', 'purchase_date' => 'date_format:Y-m-d|nullable', 'purchase_cost' => 'numeric|nullable|gte:0', @@ -57,6 +58,7 @@ class Component extends SnipeModel protected $fillable = [ 'category_id', 'company_id', + 'supplier_id', 'location_id', 'name', 'purchase_cost', @@ -86,6 +88,7 @@ class Component extends SnipeModel 'category' => ['name'], 'company' => ['name'], 'location' => ['name'], + 'supplier' => ['name'], ]; @@ -168,6 +171,18 @@ class Component extends SnipeModel return $this->belongsTo(\App\Models\Category::class, 'category_id'); } + /** + * Establishes the item -> supplier relationship + * + * @author [A. Gianotto] [] + * @since [v6.1.1] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function supplier() + { + return $this->belongsTo(\App\Models\Supplier::class, 'supplier_id'); + } + /** * Establishes the component -> action logs relationship * @@ -247,4 +262,17 @@ class Component extends SnipeModel { return $query->leftJoin('companies', 'components.company_id', '=', 'companies.id')->orderBy('companies.name', $order); } + + /** + * Query builder scope to order on supplier + * + * @param \Illuminate\Database\Query\Builder $query Query builder instance + * @param text $order Order + * + * @return \Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeOrderSupplier($query, $order) + { + return $query->leftJoin('suppliers', 'components.supplier_id', '=', 'suppliers.id')->orderBy('suppliers.name', $order); + } } diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php index ea4ac6086..a3a0d5917 100644 --- a/app/Models/Consumable.php +++ b/app/Models/Consumable.php @@ -27,6 +27,7 @@ class Consumable extends SnipeModel 'requestable' => 'boolean', 'category_id' => 'integer', 'company_id' => 'integer', + 'supplier_id', 'qty' => 'integer', 'min_amt' => 'integer', ]; @@ -95,6 +96,7 @@ class Consumable extends SnipeModel 'company' => ['name'], 'location' => ['name'], 'manufacturer' => ['name'], + 'supplier' => ['name'], ]; @@ -249,6 +251,18 @@ class Consumable extends SnipeModel return $this->belongsToMany(\App\Models\User::class, 'consumables_users', 'consumable_id', 'assigned_to')->withPivot('user_id')->withTrashed()->withTimestamps(); } + /** + * Establishes the item -> supplier relationship + * + * @author [A. Gianotto] [] + * @since [v6.1.1] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function supplier() + { + return $this->belongsTo(\App\Models\Supplier::class, 'supplier_id'); + } + /** * Determine whether to send a checkin/checkout email based on @@ -376,4 +390,17 @@ class Consumable extends SnipeModel { return $query->leftJoin('companies', 'consumables.company_id', '=', 'companies.id')->orderBy('companies.name', $order); } + + /** + * Query builder scope to order on supplier + * + * @param \Illuminate\Database\Query\Builder $query Query builder instance + * @param text $order Order + * + * @return \Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeOrderSupplier($query, $order) + { + return $query->leftJoin('suppliers', 'consumables.supplier_id', '=', 'suppliers.id')->orderBy('suppliers.name', $order); + } } diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index 393e7ddb2..d60d3c42f 100755 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -121,6 +121,30 @@ class Supplier extends SnipeModel return $this->hasMany(\App\Models\Accessory::class, 'supplier_id'); } + /** + * Establishes the supplier -> component relationship + * + * @author A. Gianotto + * @since [v6.1.1] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function components() + { + return $this->hasMany(\App\Models\Component::class, 'supplier_id'); + } + + /** + * Establishes the supplier -> component relationship + * + * @author A. Gianotto + * @since [v6.1.1] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function consumables() + { + return $this->hasMany(\App\Models\Consumable::class, 'supplier_id'); + } + /** * Establishes the supplier -> asset maintenances relationship * diff --git a/app/Presenters/ComponentPresenter.php b/app/Presenters/ComponentPresenter.php index 16a96f3c4..c7468911a 100644 --- a/app/Presenters/ComponentPresenter.php +++ b/app/Presenters/ComponentPresenter.php @@ -59,6 +59,15 @@ class ComponentPresenter extends Presenter 'title' => trans('general.category'), 'formatter' => 'categoriesLinkObjFormatter', ], [ + 'field' => 'supplier', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.supplier'), + 'visible' => false, + 'formatter' => 'suppliersLinkObjFormatter', + ], + [ 'field' => 'qty', 'searchable' => false, 'sortable' => true, diff --git a/app/Presenters/ConsumablePresenter.php b/app/Presenters/ConsumablePresenter.php index e931fc122..abb599de4 100644 --- a/app/Presenters/ConsumablePresenter.php +++ b/app/Presenters/ConsumablePresenter.php @@ -53,6 +53,14 @@ class ConsumablePresenter extends Presenter 'sortable' => true, 'title' => trans('general.category'), 'formatter' => 'categoriesLinkObjFormatter', + ], [ + 'field' => 'supplier', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.supplier'), + 'visible' => false, + 'formatter' => 'suppliersLinkObjFormatter', ], [ 'field' => 'model_number', 'searchable' => true, diff --git a/database/factories/ComponentFactory.php b/database/factories/ComponentFactory.php index 6db9ef24f..caac70078 100644 --- a/database/factories/ComponentFactory.php +++ b/database/factories/ComponentFactory.php @@ -7,6 +7,7 @@ use App\Models\Company; use App\Models\Component; use App\Models\Location; use Illuminate\Database\Eloquent\Factories\Factory; +use App\Models\Supplier; class ComponentFactory extends Factory { @@ -35,6 +36,7 @@ class ComponentFactory extends Factory 'purchase_cost' => $this->faker->randomFloat(2), 'min_amt' => $this->faker->numberBetween($min = 1, $max = 2), 'company_id' => Company::factory(), + 'supplier_id' => Supplier::factory(), ]; } diff --git a/database/factories/ConsumableFactory.php b/database/factories/ConsumableFactory.php index 8dd56229e..544499971 100644 --- a/database/factories/ConsumableFactory.php +++ b/database/factories/ConsumableFactory.php @@ -8,6 +8,7 @@ use App\Models\Consumable; use App\Models\Manufacturer; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; +use App\Models\Supplier; class ConsumableFactory extends Factory { @@ -36,6 +37,7 @@ class ConsumableFactory extends Factory 'qty' => $this->faker->numberBetween(5, 10), 'min_amt' => $this->faker->numberBetween($min = 1, $max = 2), 'company_id' => Company::factory(), + 'supplier_id' => Supplier::factory(), ]; } diff --git a/database/factories/SettingFactory.php b/database/factories/SettingFactory.php index 970d00cd6..1655bd335 100644 --- a/database/factories/SettingFactory.php +++ b/database/factories/SettingFactory.php @@ -34,13 +34,4 @@ class SettingFactory extends Factory 'email_domain' => 'test.com', ]; } - - public function withMultipleFullCompanySupport() - { - return $this->state(function () { - return [ - 'full_multiple_companies_support' => 1, - ]; - }); - } } diff --git a/database/migrations/2023_04_12_135822_add_supplier_to_components.php b/database/migrations/2023_04_12_135822_add_supplier_to_components.php new file mode 100644 index 000000000..447c7850a --- /dev/null +++ b/database/migrations/2023_04_12_135822_add_supplier_to_components.php @@ -0,0 +1,48 @@ +integer('supplier_id')->after('user_id')->nullable()->default(null); + } + }); + + Schema::table('consumables', function (Blueprint $table) { + if (!Schema::hasColumn('consumables', 'supplier_id')) { + $table->integer('supplier_id')->after('user_id')->nullable()->default(null); + } + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('components', function (Blueprint $table) { + if (Schema::hasColumn('components', 'supplier_id')) { + $table->dropColumn('supplier_id'); + } + }); + + Schema::table('consumables', function (Blueprint $table) { + if (Schema::hasColumn('consumables', 'supplier_id')) { + $table->dropColumn('supplier_id'); + } + }); + } +} diff --git a/resources/views/components/edit.blade.php b/resources/views/components/edit.blade.php index 1567ec5a8..5279f0399 100644 --- a/resources/views/components/edit.blade.php +++ b/resources/views/components/edit.blade.php @@ -17,6 +17,7 @@ @include ('partials.forms.edit.serial', ['fieldname' => 'serial']) @include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id']) @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id']) +@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id']) @include ('partials.forms.edit.order_number') @include ('partials.forms.edit.purchase_date') @include ('partials.forms.edit.purchase_cost') diff --git a/resources/views/consumables/edit.blade.php b/resources/views/consumables/edit.blade.php index 6217aab3f..f32e74b19 100644 --- a/resources/views/consumables/edit.blade.php +++ b/resources/views/consumables/edit.blade.php @@ -11,6 +11,7 @@ @include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id']) @include ('partials.forms.edit.name', ['translated_name' => trans('admin/consumables/table.title')]) @include ('partials.forms.edit.category-select', ['translated_name' => trans('general.category'), 'fieldname' => 'category_id', 'required' => 'true', 'category_type' => 'consumable']) +@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id']) @include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id']) @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id']) @include ('partials.forms.edit.model_number') diff --git a/resources/views/partials/forms/edit/category-select.blade.php b/resources/views/partials/forms/edit/category-select.blade.php index 402c959cc..ba84dc7e7 100644 --- a/resources/views/partials/forms/edit/category-select.blade.php +++ b/resources/views/partials/forms/edit/category-select.blade.php @@ -3,7 +3,7 @@ {{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }} -
+
@if ($supplier_id = old($fieldname, (isset($item)) ? $item->{$fieldname} : '')) - @else - + @endif
diff --git a/resources/views/suppliers/index.blade.php b/resources/views/suppliers/index.blade.php index 894a6f459..aa1577a37 100755 --- a/resources/views/suppliers/index.blade.php +++ b/resources/views/suppliers/index.blade.php @@ -54,6 +54,8 @@ {{ trans('admin/suppliers/table.assets') }} {{ trans('general.accessories') }} {{ trans('admin/suppliers/table.licenses') }} + {{ trans('general.components') }} + {{ trans('general.consumables') }} {{ trans('table.actions') }} diff --git a/resources/views/suppliers/view.blade.php b/resources/views/suppliers/view.blade.php index 1cf95cfe4..9024bd927 100755 --- a/resources/views/suppliers/view.blade.php +++ b/resources/views/suppliers/view.blade.php @@ -65,6 +65,30 @@ +
  • + + + + +
  • + +
  • + + + + +
  • +
  • +
    +

    {{ trans('general.components') }}

    +
    + +
    +
    +
    + +
    +

    {{ trans('general.consumables') }}

    +
    + +
    +
    +
    + +

    {{ trans('admin/asset_maintenances/general.asset_maintenances') }}

    diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php index 2190c791f..3618c6e01 100644 --- a/tests/Feature/Api/Assets/AssetIndexTest.php +++ b/tests/Feature/Api/Assets/AssetIndexTest.php @@ -3,18 +3,18 @@ namespace Tests\Feature\Api\Assets; use App\Models\Asset; -use App\Models\Setting; 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() { - Setting::factory()->create(); - Asset::factory()->count(3)->create(); Passport::actingAs(User::factory()->superuser()->create()); diff --git a/tests/Feature/Api/Users/UsersForSelectListTest.php b/tests/Feature/Api/Users/UsersForSelectListTest.php index 8b2c01bcf..6ab5bf9a8 100644 --- a/tests/Feature/Api/Users/UsersForSelectListTest.php +++ b/tests/Feature/Api/Users/UsersForSelectListTest.php @@ -3,18 +3,18 @@ namespace Tests\Feature\Api\Users; use App\Models\Company; -use App\Models\Setting; 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() { - Setting::factory()->create(); - $users = User::factory()->superuser()->count(3)->create(); Passport::actingAs($users->first()); @@ -32,7 +32,7 @@ class UsersForSelectListTest extends TestCase public function testUsersScopedToCompanyWhenMultipleFullCompanySupportEnabled() { - Setting::factory()->withMultipleFullCompanySupport()->create(); + $this->settings->enableMultipleFullCompanySupport(); $jedi = Company::factory()->has(User::factory()->count(3)->sequence( ['first_name' => 'Luke', 'last_name' => 'Skywalker', 'username' => 'lskywalker'], @@ -60,7 +60,7 @@ class UsersForSelectListTest extends TestCase public function testUsersScopedToCompanyDuringSearchWhenMultipleFullCompanySupportEnabled() { - Setting::factory()->withMultipleFullCompanySupport()->create(); + $this->settings->enableMultipleFullCompanySupport(); $jedi = Company::factory()->has(User::factory()->count(3)->sequence( ['first_name' => 'Luke', 'last_name' => 'Skywalker', 'username' => 'lskywalker'], diff --git a/tests/Support/InteractsWithSettings.php b/tests/Support/InteractsWithSettings.php new file mode 100644 index 000000000..1de9e7bc1 --- /dev/null +++ b/tests/Support/InteractsWithSettings.php @@ -0,0 +1,13 @@ +settings = Settings::initialize(); + } +} diff --git a/tests/Support/Settings.php b/tests/Support/Settings.php new file mode 100644 index 000000000..ccf50c3ce --- /dev/null +++ b/tests/Support/Settings.php @@ -0,0 +1,41 @@ +setting = Setting::factory()->create(); + } + + public static function initialize(): Settings + { + return new self(); + } + + public function enableMultipleFullCompanySupport(): Settings + { + return $this->update(['full_multiple_companies_support' => 1]); + } + + /** + * @param array $attributes Attributes to modify in the application's settings. + */ + public function set(array $attributes): Settings + { + return $this->update($attributes); + } + + private function update(array $attributes): Settings + { + Setting::unguarded(fn() => $this->setting->update($attributes)); + Setting::$_cache = null; + + return $this; + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index efa533b8c..e3fd8a7aa 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,9 +3,9 @@ namespace Tests; use App\Http\Middleware\SecurityHeaders; -use App\Models\Setting; use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; +use Tests\Support\InteractsWithSettings; abstract class TestCase extends BaseTestCase { @@ -20,8 +20,10 @@ abstract class TestCase extends BaseTestCase { parent::setUp(); - $this->beforeApplicationDestroyed(fn() => Setting::$_cache = null); - $this->withoutMiddleware($this->globallyDisabledMiddleware); + + if (collect(class_uses_recursive($this))->contains(InteractsWithSettings::class)) { + $this->setUpSettings(); + } } }