A free open source IT asset/license management system
Rename company_id on users table
snipe115d1a4f5eaf
diff --git a/app/Console/Commands/BulkDelete.php b/app/Console/Commands/BulkDelete.phpindex d3dbc48aef..07bd4515c6 100644--- a/app/Console/Commands/BulkDelete.php+++ b/app/Console/Commands/BulkDelete.php@@ -404,11 +404,11 @@ class BulkDelete extends Command->where('activated', 1)->where(function (Builder $q) use ($companyIds, $includeNull) {if (! empty($companyIds)) {- $q->whereIn('company_id', $companyIds);+ $q->whereHas('companies', fn (Builder $sub) => $sub->whereIn('companies.id', $companyIds));}if ($includeNull) {- $method = ! empty($companyIds) ? 'orWhereNull' : 'whereNull';- $q->{$method}('company_id');+ $method = ! empty($companyIds) ? 'orWhereDoesntHave' : 'whereDoesntHave';+ $q->{$method}('companies');}});}@@ -875,9 +875,10 @@ class BulkDelete extends Command// companies outside the selected scope. If so, only remove the selected-company// associations and skip full deletion to avoid orphaning them from their other companies.if (! empty($companyIds)) {- $allUserCompanyIds = array_unique(array_filter(array_merge(+ // Pivot is the authoritative source of membership; the legacy+ // users.company_id scalar is no longer consulted.+ $allUserCompanyIds = array_values(array_unique(array_filter($user->companies()->pluck('companies.id')->toArray(),- $user->company_id ? [$user->company_id] : [],)));$outsideCompanyIds = array_values(array_diff($allUserCompanyIds, $companyIds));@@ -889,6 +890,7 @@ class BulkDelete extends Command$this->reportLines[] = "Would partially disassociate user {$user->username} — also belongs to: {$outsideNames}";} else {$user->companies()->detach($companyIds);+ $user->syncLegacyCompanyIdMirror();warning(" Skipped full deletion of {$user->username}: they also belong to {$outsideNames}. Removed selected company associations only.");$this->reportLines[] = "Partially disassociated user {$user->username} — also belongs to: {$outsideNames}. Full deletion skipped.";}diff --git a/app/Console/Commands/PurgeEulaPDFs.php b/app/Console/Commands/PurgeEulaPDFs.phpindex b5de61bec1..7760cf79f7 100644--- a/app/Console/Commands/PurgeEulaPDFs.php+++ b/app/Console/Commands/PurgeEulaPDFs.php@@ -71,7 +71,7 @@ class PurgeEulaPDFs extends Command$q->withTrashed()->whereNotNull('deleted_at');if ($companyId) {- $q->where('company_id', $companyId);+ $q->whereHas('companies', fn ($sub) => $sub->where('companies.id', $companyId));}});@@ -80,7 +80,7 @@ class PurgeEulaPDFs extends Command} else {if ($companyId) {$query->whereHas('assignedTo', function ($query) use ($companyId) {- $query->withTrashed()->where('company_id', $companyId);+ $query->withTrashed()->whereHas('companies', fn ($sub) => $sub->where('companies.id', $companyId));});}}diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.phpindex 0f37f6725b..aa812a9979 100644--- a/app/Http/Controllers/Api/UsersController.php+++ b/app/Http/Controllers/Api/UsersController.php@@ -658,6 +658,7 @@ class UsersController extends Controller$filtered = Company::getIdsForCurrentUser([(int) $request->input('company_id')]);if (! empty($filtered)) {$user->companies()->syncWithoutDetaching($filtered);+ $user->syncLegacyCompanyIdMirror();}}diff --git a/app/Http/Controllers/Licenses/LicenseCheckoutController.php b/app/Http/Controllers/Licenses/LicenseCheckoutController.phpindex 4f76a4ccfd..2e8b736e6e 100644--- a/app/Http/Controllers/Licenses/LicenseCheckoutController.php+++ b/app/Http/Controllers/Licenses/LicenseCheckoutController.php@@ -276,7 +276,14 @@ class LicenseCheckoutController extends Controller$usersQuery = User::whereNull('deleted_at')->where('autoassign_licenses', '=', 1)->with('licenses');if (Setting::getSettings()->full_multiple_companies_support && $license->company_id) {- $usersQuery->where('company_id', '=', $license->company_id);+ // Filter to users pivoted to the license's company. The scalar+ // users.company_id column is deprecated; membership lives in the+ // company_user pivot only.+ $usersQuery->whereIn('users.id', function ($sub) use ($license) {+ $sub->select('user_id')+ ->from('company_user')+ ->where('company_id', $license->company_id);+ });}$users = $usersQuery->get();Log::debug($avail_count.' will be assigned');diff --git a/app/Http/Controllers/Users/BulkUsersController.php b/app/Http/Controllers/Users/BulkUsersController.phpindex 825c09d2e7..bf836813fc 100644--- a/app/Http/Controllers/Users/BulkUsersController.php+++ b/app/Http/Controllers/Users/BulkUsersController.php@@ -208,10 +208,6 @@ class BulkUsersController extends Controller$this->update_array['manager_id'] = null;}- if ($request->input('null_company_ids') == '1') {- $this->update_array['company_id'] = null;- }-if ($request->input('null_start_date') == '1') {$this->update_array['start_date'] = null;}@@ -271,15 +267,12 @@ class BulkUsersController extends Controllerif (! $manager_conflict) {$this->conditionallyAddItem('manager_id');}- // Prepare company pivot changes upfront so we can include company_id in the per-user save.$bulkCompanyIds = array_filter(array_map('intval', (array) $request->input('company_ids', [])));$clearCompanies = $request->input('null_company_ids') == '1';$allowedIds = [];if ($bulkCompanyIds || $clearCompanies) {$allowedIds = Company::getIdsForCurrentUser($bulkCompanyIds);- // Include scalar company_id in the update array for display/backward compat.- $this->update_array['company_id'] = $allowedIds[0] ?? null;}// Floater-mode self-elevation guard (#19200). See User::canGrantFloaterStatus.@@ -326,6 +319,7 @@ class BulkUsersController extends Controller$user->companies()->detach(Company::getIdsForCurrentUser($user->companies()->pluck('companies.id')->toArray()));+ $user->syncLegacyCompanyIdMirror();} else {$user->syncCompaniesWithLogging($allowedIds);}@@ -592,6 +586,7 @@ class BulkUsersController extends Controller$mergedCompanyIds = $user_to_merge->companies()->pluck('companies.id')->toArray();if (! empty($mergedCompanyIds)) {$merge_into_user->companies()->syncWithoutDetaching($mergedCompanyIds);+ $merge_into_user->syncLegacyCompanyIdMirror();}$user_to_merge->delete();diff --git a/app/Http/Requests/CreateMultipleAssetRequest.php b/app/Http/Requests/CreateMultipleAssetRequest.phpindex 30e40d4d81..b23b84fe10 100644--- a/app/Http/Requests/CreateMultipleAssetRequest.php+++ b/app/Http/Requests/CreateMultipleAssetRequest.php@@ -32,7 +32,15 @@ class CreateMultipleAssetRequest extends ImageUploadRequest // should I extend f}if (Setting::getSettings()->full_multiple_companies_support == '1' && ! $this->user()->isSuperUser()) {- $this->mergeIfMissing(['company_id' => $this->user()->company_id]);+ // Default the new asset's company to the first company the actor is+ // pivoted to. The pivot is the source of truth for membership; the+ // legacy users.company_id scalar is no longer consulted for scoping.+ $primaryCompanyId = $this->user()->companies()+ ->orderBy('companies.id')+ ->value('companies.id');+ if ($primaryCompanyId) {+ $this->mergeIfMissing(['company_id' => (int) $primaryCompanyId]);+ }}}diff --git a/app/Importer/UserImporter.php b/app/Importer/UserImporter.phpindex f9d54d2fc2..a5b530a299 100644--- a/app/Importer/UserImporter.php+++ b/app/Importer/UserImporter.php@@ -167,6 +167,7 @@ class UserImporter extends ItemImporter// Sync company pivot when companies were specified in this row.if (! empty($companyIds)) {$user->companies()->sync($companyIds);+ $user->syncLegacyCompanyIdMirror();}// Update the location of any assets checked out to this user@@ -230,6 +231,7 @@ class UserImporter extends ItemImporter// for that case and adds any additional companies for multi-company rows.if (! empty($companyIds)) {$user->companies()->sync($companyIds);+ $user->syncLegacyCompanyIdMirror();}if (($user->email) && ($user->activated == '1')) {diff --git a/app/Models/Company.php b/app/Models/Company.phpindex 37b35ca34d..539293c81a 100644--- a/app/Models/Company.php+++ b/app/Models/Company.php@@ -376,11 +376,11 @@ final class Company extends SnipeModel$userCompanyIds = self::getCurrentUserCompanyIds();- // Empty pivot = unrestricted only for true legacy "no-company" users- // (those whose scalar company_id is also null). Users who had their- // pivot cleared via the API retain their scalar company_id, so they- // do NOT qualify for this bypass.- if (empty($userCompanyIds) && is_null(auth()->user()->company_id)) {+ // Empty pivot = unrestricted (legacy no-company users). The pivot+ // is the sole source of truth for membership now that the+ // company_user table migration has run; the old scalar+ // users.company_id column is not consulted here.+ if (empty($userCompanyIds)) {return true;}diff --git a/app/Models/SnipeSCIMConfig.php b/app/Models/SnipeSCIMConfig.phpindex edc9c24f87..62b45a871c 100644--- a/app/Models/SnipeSCIMConfig.php+++ b/app/Models/SnipeSCIMConfig.php@@ -235,8 +235,16 @@ class SCIMCompanyAttribute extends MappedTableif ($object->exists) {$object->companies()->sync($ids);+ if (method_exists($object, 'syncLegacyCompanyIdMirror')) {+ $object->syncLegacyCompanyIdMirror();+ }} else {- $object->saved(fn () => $object->companies()->sync($ids));+ $object->saved(function () use ($object, $ids) {+ $object->companies()->sync($ids);+ if (method_exists($object, 'syncLegacyCompanyIdMirror')) {+ $object->syncLegacyCompanyIdMirror();+ }+ });}}diff --git a/app/Models/Traits/CompanyableTrait.php b/app/Models/Traits/CompanyableTrait.phpindex f31e61f300..3aeaba9151 100644--- a/app/Models/Traits/CompanyableTrait.php+++ b/app/Models/Traits/CompanyableTrait.php@@ -56,7 +56,11 @@ trait CompanyableTrait}if (! $this->company_id) {- if (is_null($target->company_id)) {+ $targetHasNoCompany = $target instanceof User+ ? $target->companies()->count() === 0+ : is_null($target->company_id);++ if ($targetHasNoCompany) {return true;}diff --git a/app/Models/User.php b/app/Models/User.phpindex 8c58a431a1..02cd192f68 100644--- a/app/Models/User.php+++ b/app/Models/User.php@@ -72,7 +72,6 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo'activated','address','city',- 'company_id','country','department_id','email',@@ -106,7 +105,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCoprotected $casts = ['manager_id' => 'integer','location_id' => 'integer',- 'company_id' => 'integer',+ 'legacy_company_id' => 'integer','created_at' => 'datetime','updated_at' => 'datetime','deleted_at' => 'datetime',@@ -253,15 +252,6 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCoprotected static function booted(): void{- // Bridge for factories/seeders that still set company_id directly: ensure- // that company appears in the pivot so FMCS scoping works correctly.- // Application code (controllers, importers) writes only to the pivot.- static::created(function (User $user) {- if ($user->company_id) {- $user->companies()->syncWithoutDetaching([$user->company_id]);- }- });-static::forceDeleted(function (User $user) {CheckoutRequest::where(['user_id' => $user->id])->forceDelete();$user->purgeAssociatedPassportTokens();@@ -671,9 +661,14 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo** @return Relation*/+ /**+ * @deprecated Use companies() for multi-company support. This resolves via+ * the legacy_company_id mirror, which is kept in sync with the pivot but is+ * not authoritative and may be dropped in a future release.+ */public function company(){- return $this->belongsTo(Company::class, 'company_id');+ return $this->belongsTo(Company::class, 'legacy_company_id');}public function companies(): BelongsToMany@@ -758,6 +753,8 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo$this->companies()->sync($companyIds);$newIds = $this->companies()->orderBy('companies.id')->pluck('companies.id')->toArray();+ $this->syncLegacyCompanyIdMirror();+if ($oldIds === $newIds) {return;}@@ -784,6 +781,44 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo$logAction->logaction('update');}+ /**+ * Update the legacy users.company_id column so that it mirrors the+ * company_user pivot: empty pivot writes NULL; a non-empty pivot writes+ * the lowest-id pivot entry (arbitrary but stable).+ *+ * The column is a compatibility mirror maintained only for external+ * consumers that historically read it (the API transformer, CSV export+ * templates, SCIM schema mappings). It has NO role in FMCS scoping,+ * checkout eligibility, or any internal application logic. Do not read+ * it from application code.+ *+ * Call this after any write to the company_user pivot so the mirror+ * stays consistent. Writes via the query builder so it doesn't trigger+ * the User model's save events (which would recurse through+ * UserObserver::updating and produce a spurious change log entry).+ */+ public function syncLegacyCompanyIdMirror(): void+ {+ if (! $this->exists) {+ return;+ }++ $lowestPivotId = DB::table('company_user')+ ->where('user_id', $this->id)+ ->orderBy('company_id')+ ->value('company_id');++ $target = $lowestPivotId ? (int) $lowestPivotId : null;++ if ((int) $this->legacy_company_id === (int) $target && ($target !== null || is_null($this->legacy_company_id))) {+ return;+ }++ DB::table('users')->where('id', $this->id)->update(['legacy_company_id' => $target]);+ $this->legacy_company_id = $target;+ $this->syncOriginalAttribute('legacy_company_id');+ }+/*** Establishes the user -> department relationship*diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.phpindex 4725d9a8bb..082cf412ac 100644--- a/app/Presenters/AssetPresenter.php+++ b/app/Presenters/AssetPresenter.php@@ -45,7 +45,7 @@ class AssetPresenter extends Presenter'field' => 'name','searchable' => true,'sortable' => true,- 'title' => trans('admin/hardware/form.name'),+ 'title' => trans('general.name'),'visible' => true,'formatter' => 'hardwareLinkFormatter',], [diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.phpindex 6adaa776ff..73fdcea583 100644--- a/database/factories/UserFactory.php+++ b/database/factories/UserFactory.php@@ -5,12 +5,21 @@ namespace Database\Factories;use App\Models\Company;use App\Models\User;use Illuminate\Database\Eloquent\Factories\Factory;+use Illuminate\Database\Eloquent\Model;/*** @extends Factory<User>*/class UserFactory extends Factory{+ /**+ * Set by ->forCompany() and ->withoutCompany() to suppress the default+ * "attach a fresh Company via the pivot" behavior in configure(). Laravel+ * factory chain calls clone the factory, and clone copies protected+ * properties, so setting this in a chained state persists through create().+ */+ protected bool $skipDefaultCompanyAttach = false;+/*** Define the model's default state.*@@ -22,7 +31,6 @@ class UserFactory extends Factory'activated' => 1,'address' => $this->faker->address(),'city' => $this->faker->city(),- 'company_id' => Company::factory(),'country' => $this->faker->country(),'created_by' => 1,'display_name' => null,@@ -43,6 +51,85 @@ class UserFactory extends Factory];}+ /**+ * By default every factory-created user is attached to a fresh Company via+ * the company_user pivot (the authoritative source of user-company+ * membership under FMCS). Use ->forCompany($company) to pin them to a+ * specific company, or ->withoutCompany() to leave them unattached+ * ("floater" users).+ *+ * We hook create() (not afterCreating) because chained state calls clone+ * the factory and register additional afterCreating closures that captured+ * $this at closure-creation time. Reading $this->skipDefaultCompanyAttach+ * at create() time gives us the final factory's flag, which is what we+ * want.+ */+ public function create($attributes = [], ?Model $parent = null)+ {+ $result = parent::create($attributes, $parent);++ $models = $result instanceof User+ ? [$result]+ : $result->all();++ foreach ($models as $user) {+ if ($this->skipDefaultCompanyAttach) {+ continue;+ }+ if ($user->companies()->count() > 0) {+ continue;+ }+ $company = Company::factory()->create();+ $user->companies()->attach($company->id);+ $user->syncLegacyCompanyIdMirror();+ }++ return $result;+ }++ /**+ * Preserve the skipDefaultCompanyAttach flag across chained states.+ * Laravel's Factory::newInstance() rebuilds the factory but does not carry+ * arbitrary properties, so we copy the flag ourselves.+ */+ protected function newInstance(array $arguments = [])+ {+ $factory = parent::newInstance($arguments);+ $factory->skipDefaultCompanyAttach = $this->skipDefaultCompanyAttach;++ return $factory;+ }++ /**+ * Attach the created user to a specific Company via the pivot. Accepts+ * either a Company model or a raw company id, so tests can call+ * ->forCompany($company) or ->forCompany($company->id) interchangeably.+ */+ public function forCompany(Company|int $company): static+ {+ $companyId = $company instanceof Company ? $company->id : $company;++ $factory = $this->afterCreating(function (User $user) use ($companyId) {+ $user->companies()->syncWithoutDetaching([$companyId]);+ $user->syncLegacyCompanyIdMirror();+ });+ $factory->skipDefaultCompanyAttach = true;++ return $factory;+ }++ /**+ * Create a user with no company_user pivot rows (a "floater" under FMCS+ * floater mode).+ */+ public function withoutCompany(): static+ {+ $factory = clone $this;+ $factory->skipDefaultCompanyAttach = true;++ return $factory;+ }+public function deletedUser(){return $this->state(function () {diff --git a/database/migrations/2026_07_10_000001_rename_users_company_id_to_legacy_company_id.php b/database/migrations/2026_07_10_000001_rename_users_company_id_to_legacy_company_id.phpnew file mode 100644index 0000000000..c71d63773b--- /dev/null+++ b/database/migrations/2026_07_10_000001_rename_users_company_id_to_legacy_company_id.php@@ -0,0 +1,36 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Rename users.company_id to users.legacy_company_id.+ *+ * The company_user pivot table is the authoritative source of user-company+ * membership. This column is a compatibility mirror kept in sync only for+ * external consumers that still expect it (backfilled by User::syncLegacyCompanyIdMirror).+ * Renaming it makes internal code that accidentally reads or writes the old+ * name fail loudly instead of silently producing stale mirror data.+ *+ * API/CSV/SCIM inputs that name the field "company_id" continue to work;+ * those are field-name conventions at the request/importer layer and are+ * routed into the company_user pivot regardless of what the underlying+ * column is called.+ */+ public function up(): void+ {+ Schema::table('users', function (Blueprint $table) {+ $table->renameColumn('company_id', 'legacy_company_id');+ });+ }++ public function down(): void+ {+ Schema::table('users', function (Blueprint $table) {+ $table->renameColumn('legacy_company_id', 'company_id');+ });+ }+};diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.phpindex 3d0277895c..46eb6260f8 100644--- a/database/seeders/UserSeeder.php+++ b/database/seeders/UserSeeder.php@@ -33,63 +33,74 @@ class UserSeeder extends Seeder$departmentIds = Department::all()->pluck('id');- // Named admins get multiple companies — they manage assets across several organisations.+ // Named admins get multiple companies. They manage assets across several organisations.foreach (['firstAdmin', 'snipeAdmin', 'testAdmin'] as $state) {- $user = User::factory()->{$state}()->create([- 'company_id' => null,+ $user = User::factory()->{$state}()->withoutCompany()->create(['department_id' => $departmentIds->random(),]);$ids = $companyIds->random(min(rand(2, 3), $companyIds->count()))->toArray();- User::where('id', $user->id)->update(['company_id' => $ids[0]]);$user->companies()->sync($ids);+ $user->syncLegacyCompanyIdMirror();}- // Superusers — one company each.+ // Superusers, one company each.User::factory()->count(3)->superuser()+ ->withoutCompany()->state(new Sequence(fn ($sequence) => [- 'company_id' => $companyIds->random(),'department_id' => $departmentIds->random(),]))- ->create();+ ->create()+ ->each(function (User $user) use ($companyIds) {+ $user->companies()->sync([$companyIds->random()]);+ $user->syncLegacyCompanyIdMirror();+ });- // Admins — one company each.+ // Admins, one company each.User::factory()->count(3)->admin()+ ->withoutCompany()->state(new Sequence(fn ($sequence) => [- 'company_id' => $companyIds->random(),'department_id' => $departmentIds->random(),]))- ->create();+ ->create()+ ->each(function (User $user) use ($companyIds) {+ $user->companies()->sync([$companyIds->random()]);+ $user->syncLegacyCompanyIdMirror();+ });- // Regular users — three groups:- // ~30 % (600) no company- // ~50 % (1 000) one company- // ~20 % (400) two or three companies+ // Regular users, three groups:+ // ~30% (600) no company+ // ~50% (1000) one company+ // ~20% (400) two or three companiesUser::factory()->count(600)->viewAssets()+ ->withoutCompany()->state(new Sequence(fn ($sequence) => [- 'company_id' => null,'department_id' => $departmentIds->random(),]))->create();User::factory()->count(1000)->viewAssets()+ ->withoutCompany()->state(new Sequence(fn ($sequence) => [- 'company_id' => $companyIds->random(),'department_id' => $departmentIds->random(),]))- ->create();+ ->create()+ ->each(function (User $user) use ($companyIds) {+ $user->companies()->sync([$companyIds->random()]);+ $user->syncLegacyCompanyIdMirror();+ });$multiCompanyUsers = User::factory()->count(400)->viewAssets()+ ->withoutCompany()->state(new Sequence(fn ($sequence) => [- 'company_id' => null,'department_id' => $departmentIds->random(),]))->create();foreach ($multiCompanyUsers as $user) {$ids = $companyIds->random(min(rand(2, 3), $companyIds->count()))->toArray();- User::where('id', $user->id)->update(['company_id' => $ids[0]]);$user->companies()->sync($ids);+ $user->syncLegacyCompanyIdMirror();}$src = public_path('/img/demo/avatars/');diff --git a/tests/Feature/Accessories/Api/ShowAccessoryTest.php b/tests/Feature/Accessories/Api/ShowAccessoryTest.phpindex af51169574..5b787f2984 100644--- a/tests/Feature/Accessories/Api/ShowAccessoryTest.php+++ b/tests/Feature/Accessories/Api/ShowAccessoryTest.php@@ -27,7 +27,7 @@ class ShowAccessoryTest extends TestCase implements TestsFullMultipleCompaniesSu$accessoryForCompanyA = Accessory::factory()->for($companyA)->create();$superuser = User::factory()->superuser()->create();- $userForCompanyB = User::factory()->for($companyB)->viewAccessories()->create();+ $userForCompanyB = User::factory()->forCompany($companyB)->viewAccessories()->create();$this->settings->enableMultipleFullCompanySupport();diff --git a/tests/Feature/Accessories/Api/StoreAccessoryTest.php b/tests/Feature/Accessories/Api/StoreAccessoryTest.phpindex 0345325f3b..b6104e3e6e 100644--- a/tests/Feature/Accessories/Api/StoreAccessoryTest.php+++ b/tests/Feature/Accessories/Api/StoreAccessoryTest.php@@ -25,7 +25,7 @@ class StoreAccessoryTest extends TestCase implements TestsFullMultipleCompaniesSpublic function test_adheres_to_full_multiple_companies_support_scoping(){[$companyA, $companyB] = Company::factory()->count(2)->create();- $userInCompanyA = User::factory()->for($companyA)->createAccessories()->create();+ $userInCompanyA = User::factory()->forCompany($companyA)->createAccessories()->create();$this->settings->enableMultipleFullCompanySupport();diff --git a/tests/Feature/Accessories/Api/UpdateAccessoryTest.php b/tests/Feature/Accessories/Api/UpdateAccessoryTest.phpindex 615f7e5218..57f305beef 100644--- a/tests/Feature/Accessories/Api/UpdateAccessoryTest.php+++ b/tests/Feature/Accessories/Api/UpdateAccessoryTest.php@@ -60,7 +60,7 @@ class UpdateAccessoryTest extends TestCase implements TestsFullMultipleCompanies{[$companyA, $companyB] = Company::factory()->count(2)->create();$accessory = Accessory::factory()->for($companyA)->create();- $userInCompanyA = User::factory()->for($companyA)->editAccessories()->create();+ $userInCompanyA = User::factory()->forCompany($companyA)->editAccessories()->create();$this->settings->enableMultipleFullCompanySupport();@@ -77,7 +77,7 @@ class UpdateAccessoryTest extends TestCase implements TestsFullMultipleCompanies{[$companyA, $companyB] = Company::factory()->count(2)->create();$accessory = Accessory::factory()->for($companyA)->create();- $superuser = User::factory()->superuser()->create(['company_id' => null]);+ $superuser = User::factory()->superuser()->withoutCompany()->create();$this->settings->enableMultipleFullCompanySupport();diff --git a/tests/Feature/Accessories/Ui/BulkDeleteAccessoriesTest.php b/tests/Feature/Accessories/Ui/BulkDeleteAccessoriesTest.phpindex 0e2cfcdf32..48d5a1f676 100644--- a/tests/Feature/Accessories/Ui/BulkDeleteAccessoriesTest.php+++ b/tests/Feature/Accessories/Ui/BulkDeleteAccessoriesTest.php@@ -94,7 +94,7 @@ class BulkDeleteAccessoriesTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$accessoryA = Accessory::factory()->for($companyA)->create();$accessoryB = Accessory::factory()->for($companyB)->create();- $userA = User::factory()->for($companyA)->deleteAccessories()->create();+ $userA = User::factory()->forCompany($companyA)->deleteAccessories()->create();$this->actingAs($userA)->post(route('accessories.bulk.delete'), [diff --git a/tests/Feature/Accessories/Ui/CheckoutAccessoryTest.php b/tests/Feature/Accessories/Ui/CheckoutAccessoryTest.phpindex 97881ce1a7..f546e98ea1 100644--- a/tests/Feature/Accessories/Ui/CheckoutAccessoryTest.php+++ b/tests/Feature/Accessories/Ui/CheckoutAccessoryTest.php@@ -15,7 +15,7 @@ class CheckoutAccessoryTest extends TestCase{[$companyA] = Company::factory()->count(1)->create();$accessory = Accessory::factory()->for($companyA)->create(['qty' => 5]);- $user = User::factory()->for($companyA)->create();+ $user = User::factory()->forCompany($companyA)->create();$user->companies()->sync([$companyA->id]);$this->settings->enableMultipleFullCompanySupport();@@ -41,7 +41,7 @@ class CheckoutAccessoryTest extends TestCase{[$companyA, $companyB] = Company::factory()->count(2)->create();$accessory = Accessory::factory()->for($companyA)->create(['qty' => 5]);- $user = User::factory()->for($companyB)->create();+ $user = User::factory()->forCompany($companyB)->create();$user->companies()->sync([$companyB->id]);$this->settings->enableMultipleFullCompanySupport();@@ -67,7 +67,7 @@ class CheckoutAccessoryTest extends TestCase{$accessory = Accessory::factory()->create(['qty' => 5, 'company_id' => null]);[$companyA] = Company::factory()->count(1)->create();- $user = User::factory()->for($companyA)->create();+ $user = User::factory()->forCompany($companyA)->create();$user->companies()->sync([$companyA->id]);$this->settings->enableMultipleFullCompanySupport();@@ -94,7 +94,7 @@ class CheckoutAccessoryTest extends TestCase{$accessory = Accessory::factory()->create(['qty' => 5, 'company_id' => null]);[$companyA] = Company::factory()->count(1)->create();- $user = User::factory()->for($companyA)->create();+ $user = User::factory()->forCompany($companyA)->create();$user->companies()->sync([$companyA->id]);$this->settings->enableFloaterMode();@@ -145,7 +145,7 @@ class CheckoutAccessoryTest extends TestCase{[$companyA] = Company::factory()->count(1)->create();$accessory = Accessory::factory()->for($companyA)->create(['qty' => 5]);- $nullCompanyUser = User::factory()->create(['company_id' => null]);+ $nullCompanyUser = User::factory()->withoutCompany()->create();$this->settings->enableMultipleFullCompanySupport();@@ -170,7 +170,7 @@ class CheckoutAccessoryTest extends TestCase{[$companyA] = Company::factory()->count(1)->create();$accessory = Accessory::factory()->for($companyA)->create(['qty' => 5]);- $nullCompanyUser = User::factory()->create(['company_id' => null]);+ $nullCompanyUser = User::factory()->withoutCompany()->create();$this->settings->enableFloaterMode();diff --git a/tests/Feature/Accessories/Ui/DeleteAccessoryTest.php b/tests/Feature/Accessories/Ui/DeleteAccessoryTest.phpindex 6badc84d95..4a0b0b06fd 100644--- a/tests/Feature/Accessories/Ui/DeleteAccessoryTest.php+++ b/tests/Feature/Accessories/Ui/DeleteAccessoryTest.php@@ -23,7 +23,7 @@ class DeleteAccessoryTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$accessoryForCompanyA = Accessory::factory()->for($companyA)->create();- $userForCompanyB = User::factory()->for($companyB)->deleteAccessories()->create();+ $userForCompanyB = User::factory()->forCompany($companyB)->deleteAccessories()->create();$this->actingAs($userForCompanyB)->delete(route('accessories.destroy', $accessoryForCompanyA->id));diff --git a/tests/Feature/Accessories/Ui/ShowAccessoryTest.php b/tests/Feature/Accessories/Ui/ShowAccessoryTest.phpindex 42457fced9..7661daa4ce 100644--- a/tests/Feature/Accessories/Ui/ShowAccessoryTest.php+++ b/tests/Feature/Accessories/Ui/ShowAccessoryTest.php@@ -22,7 +22,7 @@ class ShowAccessoryTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$accessoryForCompanyA = Accessory::factory()->for($companyA)->create();- $userForCompanyB = User::factory()->for($companyB)->viewAccessories()->create();+ $userForCompanyB = User::factory()->forCompany($companyB)->viewAccessories()->create();$this->actingAs($userForCompanyB)->get(route('accessories.show', $accessoryForCompanyA))diff --git a/tests/Feature/Accessories/Ui/UpdateAccessoryTest.php b/tests/Feature/Accessories/Ui/UpdateAccessoryTest.phpindex 5113ea255a..3e55733a24 100644--- a/tests/Feature/Accessories/Ui/UpdateAccessoryTest.php+++ b/tests/Feature/Accessories/Ui/UpdateAccessoryTest.php@@ -35,7 +35,7 @@ class UpdateAccessoryTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$accessoryForCompanyA = Accessory::factory()->for($companyA)->create();- $userForCompanyB = User::factory()->for($companyB)->editAccessories()->create();+ $userForCompanyB = User::factory()->forCompany($companyB)->editAccessories()->create();$this->actingAs($userForCompanyB)->get(route('accessories.edit', $accessoryForCompanyA->id))diff --git a/tests/Feature/AssetModels/Api/AssetModelFilesTest.php b/tests/Feature/AssetModels/Api/AssetModelFilesTest.phpindex 64271c6e15..01f8cb8757 100644--- a/tests/Feature/AssetModels/Api/AssetModelFilesTest.php+++ b/tests/Feature/AssetModels/Api/AssetModelFilesTest.php@@ -231,7 +231,8 @@ class AssetModelFilesTest extends TestCase$superUser = User::factory()->superuser()->create();$normalUser = User::factory()->manageModelFiles()- ->create(['company_id' => $company->id]);+ ->forCompany($company)+ ->create();// Superuser uploads a file (company_id on the log will be null)$this->actingAsForApi($superUser)diff --git a/tests/Feature/Assets/Api/AssignedAssetsTest.php b/tests/Feature/Assets/Api/AssignedAssetsTest.phpindex 93d9bbbfb0..f3d9b68a7c 100644--- a/tests/Feature/Assets/Api/AssignedAssetsTest.php+++ b/tests/Feature/Assets/Api/AssignedAssetsTest.php@@ -25,7 +25,7 @@ class AssignedAssetsTest extends TestCase$asset = Asset::factory()->for($companyA)->create();- $user = User::factory()->for($companyB)->viewAssets()->create();+ $user = User::factory()->forCompany($companyB)->viewAssets()->create();$this->actingAsForApi($user)->getJson(route('api.assets.assigned_assets', $asset))diff --git a/tests/Feature/Assets/Api/AssignedComponentsTest.php b/tests/Feature/Assets/Api/AssignedComponentsTest.phpindex 42d11de621..5fdbee8c3f 100644--- a/tests/Feature/Assets/Api/AssignedComponentsTest.php+++ b/tests/Feature/Assets/Api/AssignedComponentsTest.php@@ -26,7 +26,7 @@ class AssignedComponentsTest extends TestCase$asset = Asset::factory()->for($companyA)->create();- $user = User::factory()->for($companyB)->viewAssets()->create();+ $user = User::factory()->forCompany($companyB)->viewAssets()->create();$this->actingAsForApi($user)->getJson(route('api.assets.assigned_components', $asset))diff --git a/tests/Feature/Assets/Api/BulkAuditAssetsTest.php b/tests/Feature/Assets/Api/BulkAuditAssetsTest.phpindex 6e29d559ef..4c2ab3cca9 100644--- a/tests/Feature/Assets/Api/BulkAuditAssetsTest.php+++ b/tests/Feature/Assets/Api/BulkAuditAssetsTest.php@@ -213,7 +213,7 @@ class BulkAuditAssetsTest extends TestCase$companyA = Company::factory()->create();$companyB = Company::factory()->create();- $userA = User::factory()->auditAssets()->create(['company_id' => $companyA->id]);+ $userA = User::factory()->auditAssets()->forCompany($companyA->id)->create();$assetA = Asset::factory()->create(['company_id' => $companyA->id, 'created_by' => $userA->id]);$assetB = Asset::factory()->create(['company_id' => $companyB->id]);diff --git a/tests/Feature/Assets/Api/BulkUpdateAssetsTest.php b/tests/Feature/Assets/Api/BulkUpdateAssetsTest.phpindex 45e5aa2e5f..f75dcad84e 100644--- a/tests/Feature/Assets/Api/BulkUpdateAssetsTest.php+++ b/tests/Feature/Assets/Api/BulkUpdateAssetsTest.php@@ -291,7 +291,7 @@ class BulkUpdateAssetsTest extends TestCase$companyA = Company::factory()->create();$companyB = Company::factory()->create();- $userA = User::factory()->editAssets()->create(['company_id' => $companyA->id]);+ $userA = User::factory()->editAssets()->forCompany($companyA->id)->create();$assetA = Asset::factory()->create(['company_id' => $companyA->id, 'created_by' => $userA->id]);$assetB = Asset::factory()->create(['company_id' => $companyB->id]);diff --git a/tests/Feature/Assets/Api/StoreAssetTest.php b/tests/Feature/Assets/Api/StoreAssetTest.phpindex 7487051f72..87a6ab8711 100644--- a/tests/Feature/Assets/Api/StoreAssetTest.php+++ b/tests/Feature/Assets/Api/StoreAssetTest.php@@ -188,8 +188,8 @@ class StoreAssetTest extends TestCase$this->assertNull($asset->assigned_to, 'assigned_to must not be set via the raw pair');$this->assertHasTheseActionLogs($asset, ['create']);$this->assertDatabaseMissing('action_logs', [- 'item_type' => Asset::class,- 'item_id' => $asset->id,+ 'item_type' => Asset::class,+ 'item_id' => $asset->id,'action_type' => 'checkout',]);}@@ -596,8 +596,8 @@ class StoreAssetTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();- $actorInCompanyA = User::factory()->createAssets()->for($companyA)->create();- $targetUserInCompanyB = User::factory()->for($companyB)->create();+ $actorInCompanyA = User::factory()->createAssets()->forCompany($companyA)->create();+ $targetUserInCompanyB = User::factory()->forCompany($companyB)->create();$model = AssetModel::factory()->create();$status = Statuslabel::factory()->readyToDeploy()->create();diff --git a/tests/Feature/Assets/Api/UpdateAssetTest.php b/tests/Feature/Assets/Api/UpdateAssetTest.phpindex 1276d764df..7a02f0895a 100644--- a/tests/Feature/Assets/Api/UpdateAssetTest.php+++ b/tests/Feature/Assets/Api/UpdateAssetTest.php@@ -429,8 +429,8 @@ class UpdateAssetTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$asset = Asset::factory()->for($companyA)->create(['name' => 'Original Name']);- $actorInCompanyA = User::factory()->editAssets()->for($companyA)->create();- $targetUserInCompanyB = User::factory()->for($companyB)->create();+ $actorInCompanyA = User::factory()->editAssets()->forCompany($companyA)->create();+ $targetUserInCompanyB = User::factory()->forCompany($companyB)->create();$this->actingAsForApi($actorInCompanyA)->patchJson(route('api.assets.update', $asset->id), [@@ -480,7 +480,7 @@ class UpdateAssetTest extends TestCase$this->assertEquals($originalAssignedTo, $asset->assigned_to, 'assigned_to must not change via the raw pair');$this->assertDatabaseMissing('action_logs', ['item_type' => Asset::class,- 'item_id' => $asset->id,+ 'item_id' => $asset->id,'action_type' => 'checkout',]);}@@ -643,12 +643,8 @@ class UpdateAssetTest extends TestCase$companyA = Company::factory()->create();$companyB = Company::factory()->create();- $userA = User::factory()->editAssets()->create([- 'company_id' => $companyA->id,- ]);- $userB = User::factory()->editAssets()->create([- 'company_id' => $companyB->id,- ]);+ $userA = User::factory()->editAssets()->forCompany($companyA)->create();+ $userB = User::factory()->editAssets()->forCompany($companyB)->create();$asset = Asset::factory()->create(['created_by' => $userA->id,'company_id' => $companyA->id,diff --git a/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php b/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.phpindex c2677eab60..853140d6ee 100644--- a/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php+++ b/tests/Feature/Assets/Ui/StoreAssetWithFullMultipleCompanySupportTest.php@@ -50,7 +50,7 @@ class StoreAssetWithFullMultipleCompanySupportTest extends TestCase// Create a user with NULL scalar company_id but a pivot membership in $company.// This mirrors users created/updated via the web UI, which writes only to the pivot.- $user = User::factory()->createAssets()->create(['company_id' => null]);+ $user = User::factory()->createAssets()->withoutCompany()->create();$user->companies()->sync([$company->id]);$this->actingAs($user)@@ -80,7 +80,7 @@ class StoreAssetWithFullMultipleCompanySupportTest extends TestCase$company = Company::factory()->create();$location = Location::factory()->for($company)->create();- $admin = User::factory()->admin()->for($company)->create();+ $admin = User::factory()->admin()->forCompany($company)->create();$this->actingAs($admin)->post(route('hardware.store'), [diff --git a/tests/Feature/Checkins/Api/AccessoryCheckinTest.php b/tests/Feature/Checkins/Api/AccessoryCheckinTest.phpindex 5d2fcb99ca..485c2cc7c9 100644--- a/tests/Feature/Checkins/Api/AccessoryCheckinTest.php+++ b/tests/Feature/Checkins/Api/AccessoryCheckinTest.php@@ -26,7 +26,7 @@ class AccessoryCheckinTest extends TestCase implements TestsFullMultipleCompanie[$companyA, $companyB] = Company::factory()->count(2)->create();$superUser = $companyA->users()->save(User::factory()->superuser()->make());- $userInCompanyA = User::factory()->for($companyA)->checkinAccessories()->create();+ $userInCompanyA = User::factory()->forCompany($companyA)->checkinAccessories()->create();$accessoryForCompanyB = Accessory::factory()->for($companyB)->checkedOutToUser()->create();$anotherAccessoryForCompanyB = Accessory::factory()->for($companyB)->checkedOutToUser()->create();diff --git a/tests/Feature/Checkins/Api/ComponentCheckinTest.php b/tests/Feature/Checkins/Api/ComponentCheckinTest.phpindex 20fe68a793..880df30f0e 100644--- a/tests/Feature/Checkins/Api/ComponentCheckinTest.php+++ b/tests/Feature/Checkins/Api/ComponentCheckinTest.php@@ -126,7 +126,7 @@ class ComponentCheckinTest extends TestCase implements TestsFullMultipleCompanie[$companyA, $companyB] = Company::factory()->count(2)->create();$componentInCompanyA = Component::factory()->for($companyA)->checkedOutToAsset()->create();- $userInCompanyB = User::factory()->for($companyB)->create();+ $userInCompanyB = User::factory()->forCompany($companyB)->create();$pivotId = $componentInCompanyA->assets->first()->pivot->id;$this->actingAsForApi($userInCompanyB)diff --git a/tests/Feature/Checkins/Ui/AssetCheckinTest.php b/tests/Feature/Checkins/Ui/AssetCheckinTest.phpindex 4263b2d28f..88f81af7a3 100644--- a/tests/Feature/Checkins/Ui/AssetCheckinTest.php+++ b/tests/Feature/Checkins/Ui/AssetCheckinTest.php@@ -207,7 +207,7 @@ class AssetCheckinTest extends TestCase'company_id' => $companyA->id,'rtd_location_id' => $rtdLocation->id,]);- $actor = User::factory()->checkinAssets()->viewAssets()->create(['company_id' => $companyA->id]);+ $actor = User::factory()->checkinAssets()->viewAssets()->forCompany($companyA->id)->create();$this->actingAs($actor)->post(route('hardware.checkin.store', [$asset]), [diff --git a/tests/Feature/Checkins/Ui/BulkAssetCheckinTest.php b/tests/Feature/Checkins/Ui/BulkAssetCheckinTest.phpindex 9511140769..9bc5248172 100644--- a/tests/Feature/Checkins/Ui/BulkAssetCheckinTest.php+++ b/tests/Feature/Checkins/Ui/BulkAssetCheckinTest.php@@ -169,7 +169,7 @@ class BulkAssetCheckinTest extends TestCase'company_id' => $companyA->id,'rtd_location_id' => $rtdLocation->id,]);- $actor = User::factory()->checkinAssets()->viewAssets()->create(['company_id' => $companyA->id]);+ $actor = User::factory()->checkinAssets()->viewAssets()->forCompany($companyA->id)->create();$this->actingAs($actor)->post(route('hardware.bulkcheckin.store'), [diff --git a/tests/Feature/Checkouts/Api/AccessoryCheckoutTest.php b/tests/Feature/Checkouts/Api/AccessoryCheckoutTest.phpindex 3fff410017..8540fd7bfc 100644--- a/tests/Feature/Checkouts/Api/AccessoryCheckoutTest.php+++ b/tests/Feature/Checkouts/Api/AccessoryCheckoutTest.php@@ -197,9 +197,9 @@ class AccessoryCheckoutTest extends TestCase implements TestsPermissionsRequirem[$companyA, $companyB] = Company::factory()->count(2)->create();- $superuser = User::factory()->superuser()->create(['company_id' => null]);+ $superuser = User::factory()->superuser()->withoutCompany()->create();$accessoryInCompanyA = Accessory::factory()->for($companyA)->create(['qty' => 1]);- $userInCompanyB = User::factory()->for($companyB)->create();+ $userInCompanyB = User::factory()->forCompany($companyB)->create();$this->actingAsForApi($superuser)->postJson(route('api.accessories.checkout', $accessoryInCompanyA), [diff --git a/tests/Feature/Checkouts/Api/AssetCheckoutTest.php b/tests/Feature/Checkouts/Api/AssetCheckoutTest.phpindex cbba06287e..8082999766 100644--- a/tests/Feature/Checkouts/Api/AssetCheckoutTest.php+++ b/tests/Feature/Checkouts/Api/AssetCheckoutTest.php@@ -100,9 +100,9 @@ class AssetCheckoutTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();- $actorInCompanyA = User::factory()->checkoutAssets()->for($companyA)->create();+ $actorInCompanyA = User::factory()->checkoutAssets()->forCompany($companyA)->create();$assetInCompanyA = Asset::factory()->for($companyA)->create();- $userInCompanyB = User::factory()->for($companyB)->create();+ $userInCompanyB = User::factory()->forCompany($companyB)->create();$this->actingAsForApi($actorInCompanyA)->postJson(route('api.asset.checkout', $assetInCompanyA), [@@ -135,9 +135,9 @@ class AssetCheckoutTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();- $actorInCompanyA = User::factory()->checkoutAssets()->for($companyA)->create();+ $actorInCompanyA = User::factory()->checkoutAssets()->forCompany($companyA)->create();$assetInCompanyA = Asset::factory()->for($companyA)->create();- $userInCompanyB = User::factory()->for($companyB)->create();+ $userInCompanyB = User::factory()->forCompany($companyB)->create();$this->actingAsForApi($actorInCompanyA)->postJson(route('api.assets.checkout.bytag', $assetInCompanyA->asset_tag), [@@ -287,11 +287,11 @@ class AssetCheckoutTest extends TestCase[$companyA, $companyB, $companyC] = Company::factory()->count(3)->create();// Actor is in companyC (same as the asset) so FMCS scoping lets them see and checkout it.- $actor = User::factory()->checkoutAssets()->for($companyC)->create();+ $actor = User::factory()->checkoutAssets()->forCompany($companyC)->create();$assetInCompanyC = Asset::factory()->for($companyC)->create();// Target user's primary company is A, but they also belong to C via pivot.- $target = User::factory()->for($companyA)->create();+ $target = User::factory()->forCompany($companyA)->create();$target->companies()->sync([$companyA->id, $companyB->id, $companyC->id]);$this->actingAsForApi($actor)@@ -313,11 +313,11 @@ class AssetCheckoutTest extends TestCase[$companyA, $companyB, $companyC] = Company::factory()->count(3)->create();// Actor is in companyC (same as the asset).- $actor = User::factory()->checkoutAssets()->for($companyC)->create();+ $actor = User::factory()->checkoutAssets()->forCompany($companyC)->create();$assetInCompanyC = Asset::factory()->for($companyC)->create();// Target belongs to A and B — not C. Checkout to them should be blocked.- $target = User::factory()->for($companyA)->create();+ $target = User::factory()->forCompany($companyA)->create();$target->companies()->sync([$companyA->id, $companyB->id]);$this->actingAsForApi($actor)@@ -340,10 +340,10 @@ class AssetCheckoutTest extends TestCase$company = Company::factory()->create();// Actor is in the same company as the asset.- $actor = User::factory()->checkoutAssets()->for($company)->create();+ $actor = User::factory()->checkoutAssets()->forCompany($company)->create();$assetInCompany = Asset::factory()->for($company)->create();- $target = User::factory()->create(['company_id' => null]);+ $target = User::factory()->withoutCompany()->create();$target->companies()->sync([]);$this->actingAsForApi($actor)@@ -417,7 +417,7 @@ class AssetCheckoutTest extends TestCase$company = Company::factory()->create();$actor = User::factory()->superuser()->create();$nullCompanyAsset = Asset::factory()->create(['company_id' => null]);- $companiedUser = User::factory()->for($company)->create();+ $companiedUser = User::factory()->forCompany($company)->create();$this->actingAsForApi($actor)->postJson(route('api.asset.checkout', $nullCompanyAsset), [@@ -438,7 +438,7 @@ class AssetCheckoutTest extends TestCase$company = Company::factory()->create();$actor = User::factory()->superuser()->create();$nullCompanyAsset = Asset::factory()->create(['company_id' => null]);- $companiedUser = User::factory()->for($company)->create();+ $companiedUser = User::factory()->forCompany($company)->create();$this->actingAsForApi($actor)->postJson(route('api.asset.checkout', $nullCompanyAsset), [diff --git a/tests/Feature/Checkouts/Api/ComponentCheckoutTest.php b/tests/Feature/Checkouts/Api/ComponentCheckoutTest.phpindex 22814a70b8..a59f013261 100644--- a/tests/Feature/Checkouts/Api/ComponentCheckoutTest.php+++ b/tests/Feature/Checkouts/Api/ComponentCheckoutTest.php@@ -129,7 +129,7 @@ class ComponentCheckoutTest extends TestCase implements TestsFullMultipleCompani[$companyA, $companyB] = Company::factory()->count(2)->create();- $userForCompanyA = User::factory()->for($companyA)->create();+ $userForCompanyA = User::factory()->forCompany($companyA)->create();$assetForCompanyB = Asset::factory()->for($companyB)->create();$componentForCompanyB = Component::factory()->for($companyB)->create();@@ -147,7 +147,7 @@ class ComponentCheckoutTest extends TestCase implements TestsFullMultipleCompani[$companyA, $companyB] = Company::factory()->count(2)->create();- $userInCompanyA = User::factory()->checkoutComponents()->for($companyA)->create();+ $userInCompanyA = User::factory()->checkoutComponents()->forCompany($companyA)->create();$componentInCompanyA = Component::factory()->for($companyA)->create(['qty' => 1]);$assetInCompanyB = Asset::factory()->for($companyB)->create();@@ -183,7 +183,7 @@ class ComponentCheckoutTest extends TestCase implements TestsFullMultipleCompani[$companyA, $companyB] = Company::factory()->count(2)->create();- $superuser = User::factory()->superuser()->create(['company_id' => null]);+ $superuser = User::factory()->superuser()->withoutCompany()->create();$componentInCompanyA = Component::factory()->for($companyA)->create(['qty' => 1]);$assetInCompanyB = Asset::factory()->for($companyB)->create();diff --git a/tests/Feature/Checkouts/Api/ConsumableCheckoutTest.php b/tests/Feature/Checkouts/Api/ConsumableCheckoutTest.phpindex 17dc835bd1..10a989216f 100644--- a/tests/Feature/Checkouts/Api/ConsumableCheckoutTest.php+++ b/tests/Feature/Checkouts/Api/ConsumableCheckoutTest.php@@ -123,9 +123,9 @@ class ConsumableCheckoutTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();- $superuser = User::factory()->superuser()->create(['company_id' => null]);+ $superuser = User::factory()->superuser()->withoutCompany()->create();$consumableInCompanyA = Consumable::factory()->for($companyA)->create(['qty' => 1]);- $userInCompanyB = User::factory()->for($companyB)->create();+ $userInCompanyB = User::factory()->forCompany($companyB)->create();$this->actingAsForApi($superuser)->postJson(route('api.consumables.checkout', $consumableInCompanyA), [diff --git a/tests/Feature/Checkouts/Ui/AssetCheckoutTest.php b/tests/Feature/Checkouts/Ui/AssetCheckoutTest.phpindex 94153f056c..6d74533a5f 100644--- a/tests/Feature/Checkouts/Ui/AssetCheckoutTest.php+++ b/tests/Feature/Checkouts/Ui/AssetCheckoutTest.php@@ -106,7 +106,7 @@ class AssetCheckoutTest extends TestCase$assetCompany = Company::factory()->create();$userCompany = Company::factory()->create();- $user = User::factory()->for($userCompany)->create();+ $user = User::factory()->forCompany($userCompany)->create();$asset = Asset::factory()->for($assetCompany)->create();$this->actingAs(User::factory()->superuser()->create())@@ -127,7 +127,7 @@ class AssetCheckoutTest extends TestCase$companyB = Company::factory()->create();// User's primary company is A but is also assigned to B via pivot- $user = User::factory()->for($companyA)->create();+ $user = User::factory()->forCompany($companyA)->create();$user->companies()->sync([$companyA->id, $companyB->id]);// Asset belongs to company Bdiff --git a/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php b/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.phpindex 090e7ae716..31afcec4ee 100644--- a/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php+++ b/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php@@ -142,7 +142,7 @@ class BulkAssetCheckoutTest extends TestCasefunction () {return ['type' => 'user',- 'target' => User::factory()->forCompany()->create(),+ 'target' => User::factory()->create(),];},];@@ -151,7 +151,7 @@ class BulkAssetCheckoutTest extends TestCasefunction () {return ['type' => 'asset',- 'target' => Asset::factory()->forCompany()->create(),+ 'target' => Asset::factory()->create(),];},];@@ -160,7 +160,7 @@ class BulkAssetCheckoutTest extends TestCasefunction () {return ['type' => 'location',- 'target' => Location::factory()->forCompany()->create(),+ 'target' => Location::factory()->create(),];},];diff --git a/tests/Feature/Components/Ui/DeleteComponentTest.php b/tests/Feature/Components/Ui/DeleteComponentTest.phpindex f46a32c723..ece7b0d538 100644--- a/tests/Feature/Components/Ui/DeleteComponentTest.php+++ b/tests/Feature/Components/Ui/DeleteComponentTest.php@@ -86,7 +86,7 @@ class DeleteComponentTest extends TestCase implements TestsFullMultipleCompanies[$companyA, $companyB] = Company::factory()->count(2)->create();- $userInCompanyA = User::factory()->for($companyA)->create();+ $userInCompanyA = User::factory()->forCompany($companyA)->create();$componentForCompanyB = Component::factory()->for($companyB)->create();$this->actingAs($userInCompanyA)diff --git a/tests/Feature/Console/BulkDeleteTest.php b/tests/Feature/Console/BulkDeleteTest.phpindex 61d6409b4d..a8bed44df8 100644--- a/tests/Feature/Console/BulkDeleteTest.php+++ b/tests/Feature/Console/BulkDeleteTest.php@@ -109,7 +109,7 @@ class BulkDeleteTest extends TestCase{$admin = User::factory()->superuser()->create();$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id]);+ $user = User::factory()->forCompany($company->id)->create();$asset = Asset::factory()->for($company)->assignedToUser($user)->create();$this->assertNotNull($asset->assigned_to);@@ -212,7 +212,7 @@ class BulkDeleteTest extends TestCase{$admin = User::factory()->superuser()->create();$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id]);+ $user = User::factory()->forCompany($company->id)->create();$asset = Asset::factory()->for($company)->assignedToUser($user)->create();$seat = LicenseSeat::factory()->create(['asset_id' => $asset->id, 'assigned_to' => $user->id]);@@ -384,7 +384,7 @@ class BulkDeleteTest extends TestCase{$admin = User::factory()->superuser()->create();$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id, 'activated' => 1]);+ $user = User::factory()->forCompany($company->id)->create(['activated' => 1]);$this->runCommand($admin, [$company->id], ['users'])->assertExitCode(0);@@ -396,7 +396,7 @@ class BulkDeleteTest extends TestCase{$admin = User::factory()->superuser()->create();$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id, 'activated' => 1]);+ $user = User::factory()->forCompany($company->id)->create(['activated' => 1]);$seat = LicenseSeat::factory()->create(['assigned_to' => $user->id]);$this->runCommand($admin, [$company->id], ['users'])@@ -409,7 +409,7 @@ class BulkDeleteTest extends TestCase{$admin = User::factory()->superuser()->create();$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id, 'activated' => 1]);+ $user = User::factory()->forCompany($company->id)->create(['activated' => 1]);Accessory::factory()->for($company)->checkedOutToUser($user)->create();$this->assertDatabaseHas('accessories_checkout', ['assigned_to' => $user->id]);@@ -424,7 +424,7 @@ class BulkDeleteTest extends TestCase{$admin = User::factory()->superuser()->create();$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id, 'activated' => 1]);+ $user = User::factory()->forCompany($company->id)->create(['activated' => 1]);Consumable::factory()->for($company)->checkedOutToUser($user)->create();$this->assertDatabaseHas('consumables_users', ['assigned_to' => $user->id]);@@ -439,7 +439,7 @@ class BulkDeleteTest extends TestCase{$admin = User::factory()->superuser()->create();$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id, 'activated' => 1]);+ $user = User::factory()->forCompany($company->id)->create(['activated' => 1]);CheckoutAcceptance::factory()->create(['assigned_to_id' => $user->id]);@@ -452,7 +452,7 @@ class BulkDeleteTest extends TestCasepublic function test_admin_user_is_skipped_during_user_deletion(): void{$company = Company::factory()->create();- $admin = User::factory()->superuser()->create(['company_id' => $company->id, 'activated' => 1]);+ $admin = User::factory()->superuser()->forCompany($company->id)->create(['activated' => 1]);$this->runCommand($admin, [$company->id], ['users'])->assertExitCode(0);@@ -585,7 +585,7 @@ class BulkDeleteTest extends TestCase{$admin = User::factory()->superuser()->create();$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id]);+ $user = User::factory()->forCompany($company->id)->create();$asset = Asset::factory()->for($company)->assignedToUser($user)->create();$this->runCommand($admin, [$company->id], ['assets'], dryRun: true)@@ -636,7 +636,7 @@ class BulkDeleteTest extends TestCase{$admin = User::factory()->superuser()->create();$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id]);+ $user = User::factory()->forCompany($company->id)->create();$asset = Asset::factory()->for($company)->assignedToUser($user)->create();$this->runCommand($admin, [$company->id], ['assets'], deleteType: 'none')@@ -694,7 +694,7 @@ class BulkDeleteTest extends TestCase{$admin = User::factory()->superuser()->create();[$companyA, $companyB] = Company::factory()->count(2)->create();- $user = User::factory()->create(['company_id' => $companyA->id, 'activated' => 1]);+ $user = User::factory()->forCompany($companyA->id)->create(['activated' => 1]);$user->companies()->syncWithoutDetaching([$companyA->id, $companyB->id]);$this->runCommand($admin, [$companyA->id], ['users'])@@ -712,7 +712,7 @@ class BulkDeleteTest extends TestCase{$admin = User::factory()->superuser()->create();$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id, 'activated' => 1]);+ $user = User::factory()->forCompany($company->id)->create(['activated' => 1]);$user->companies()->syncWithoutDetaching([$company->id]);$this->runCommand($admin, [$company->id], ['users'])@@ -725,7 +725,7 @@ class BulkDeleteTest extends TestCase{$admin = User::factory()->superuser()->create();$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id, 'activated' => 1]);+ $user = User::factory()->forCompany($company->id)->create(['activated' => 1]);$user->companies()->syncWithoutDetaching([$company->id]);$this->assertDatabaseHas('company_user', ['user_id' => $user->id, 'company_id' => $company->id]);diff --git a/tests/Feature/Console/Commands/PurgeEulaPDFTest.php b/tests/Feature/Console/Commands/PurgeEulaPDFTest.phpindex 91ee998d5b..6e22eb1751 100644--- a/tests/Feature/Console/Commands/PurgeEulaPDFTest.php+++ b/tests/Feature/Console/Commands/PurgeEulaPDFTest.php@@ -18,14 +18,10 @@ class PurgeEulaPDFTest extends TestCase$company = Company::factory()->create();$asset = Asset::factory()->create();$otherAsset = Asset::factory()->create();- $softDeletedUser = User::factory()->create([- 'company_id' => $company->id,- ]);+ $softDeletedUser = User::factory()->forCompany($company)->create();$softDeletedUser->delete();- $activeUser = User::factory()->create([- 'company_id' => $company->id,- ]);+ $activeUser = User::factory()->forCompany($company)->create();$acceptanceToPurge = CheckoutAcceptance::factory()->create(['checkoutable_type' => Asset::class,@@ -69,12 +65,8 @@ class PurgeEulaPDFTest extends TestCase$targetAsset = Asset::factory()->create();$otherAsset = Asset::factory()->create();- $userInTargetCompany = User::factory()->create([- 'company_id' => $targetCompany->id,- ]);- $userInOtherCompany = User::factory()->create([- 'company_id' => $otherCompany->id,- ]);+ $userInTargetCompany = User::factory()->forCompany($targetCompany)->create();+ $userInOtherCompany = User::factory()->forCompany($otherCompany)->create();$targetAcceptance = CheckoutAcceptance::factory()->create(['checkoutable_type' => Asset::class,@@ -128,19 +120,13 @@ class PurgeEulaPDFTest extends TestCase$wrongCompanyAsset = Asset::factory()->create();$activeUserAsset = Asset::factory()->create();- $matchingUser = User::factory()->create([- 'company_id' => $targetCompany->id,- ]);+ $matchingUser = User::factory()->forCompany($targetCompany)->create();$matchingUser->delete();- $wrongCompanyUser = User::factory()->create([- 'company_id' => $otherCompany->id,- ]);+ $wrongCompanyUser = User::factory()->forCompany($otherCompany)->create();$wrongCompanyUser->delete();- $activeUserInTargetCompany = User::factory()->create([- 'company_id' => $targetCompany->id,- ]);+ $activeUserInTargetCompany = User::factory()->forCompany($targetCompany)->create();Storage::fake('local');Storage::put('private_uploads/signatures/matching-signature.png', 'fake');Storage::put('private_uploads/eula-pdfs/matching-eula.pdf', 'fake');@@ -202,9 +188,7 @@ class PurgeEulaPDFTest extends TestCase{$company = Company::factory()->create();- $softDeletedUser = User::factory()->create([- 'company_id' => $company->id,- ]);+ $softDeletedUser = User::factory()->forCompany($company)->create();$softDeletedUser->delete();$recentAsset = Asset::factory()->create();diff --git a/tests/Feature/Console/TestLocationsFmcsTest.php b/tests/Feature/Console/TestLocationsFmcsTest.phpindex 250ed21f6f..4a7a1ca7c5 100644--- a/tests/Feature/Console/TestLocationsFmcsTest.php+++ b/tests/Feature/Console/TestLocationsFmcsTest.php@@ -148,7 +148,7 @@ class TestLocationsFmcsTest extends TestCase{$company = Company::factory()->create();$location = Location::factory()->for($company)->create();- $user = User::factory()->create(['company_id' => null, 'location_id' => $location->id]);+ $user = User::factory()->withoutCompany()->create(['location_id' => $location->id]);$user->companies()->sync([]);$this->settings->enableMultipleFullCompanySupport();@@ -162,7 +162,7 @@ class TestLocationsFmcsTest extends TestCase{$company = Company::factory()->create();$location = Location::factory()->for($company)->create();- $user = User::factory()->create(['company_id' => null, 'location_id' => $location->id]);+ $user = User::factory()->withoutCompany()->create(['location_id' => $location->id]);$user->companies()->sync([]);$this->settings->enableFloaterMode();diff --git a/tests/Feature/Consumables/Ui/DeleteConsumableTest.php b/tests/Feature/Consumables/Ui/DeleteConsumableTest.phpindex da50e149b8..f517ad13f6 100644--- a/tests/Feature/Consumables/Ui/DeleteConsumableTest.php+++ b/tests/Feature/Consumables/Ui/DeleteConsumableTest.php@@ -23,7 +23,7 @@ class DeleteConsumableTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$consumableForCompanyA = Consumable::factory()->for($companyA)->create();- $userForCompanyB = User::factory()->deleteConsumables()->for($companyB)->create();+ $userForCompanyB = User::factory()->deleteConsumables()->forCompany($companyB)->create();$this->actingAs($userForCompanyB)->delete(route('consumables.destroy', $consumableForCompanyA->id))diff --git a/tests/Feature/Consumables/Ui/UpdateConsumableTest.php b/tests/Feature/Consumables/Ui/UpdateConsumableTest.phpindex c34e307cfd..9f188ba9a3 100644--- a/tests/Feature/Consumables/Ui/UpdateConsumableTest.php+++ b/tests/Feature/Consumables/Ui/UpdateConsumableTest.php@@ -26,7 +26,7 @@ class UpdateConsumableTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$consumableForCompanyA = Consumable::factory()->for($companyA)->create();- $userForCompanyB = User::factory()->editConsumables()->for($companyB)->create();+ $userForCompanyB = User::factory()->editConsumables()->forCompany($companyB)->create();$this->actingAs($userForCompanyB)->get(route('consumables.edit', $consumableForCompanyA))@@ -48,7 +48,7 @@ class UpdateConsumableTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$consumableForCompanyA = Consumable::factory()->for($companyA)->create();- $userForCompanyB = User::factory()->editConsumables()->for($companyB)->create();+ $userForCompanyB = User::factory()->editConsumables()->forCompany($companyB)->create();$this->actingAs($userForCompanyB)->put(route('consumables.update', $consumableForCompanyA), [diff --git a/tests/Feature/Importing/Api/ImportAssetsTest.php b/tests/Feature/Importing/Api/ImportAssetsTest.phpindex 43956b6dc2..782fbbcf86 100644--- a/tests/Feature/Importing/Api/ImportAssetsTest.php+++ b/tests/Feature/Importing/Api/ImportAssetsTest.php@@ -647,7 +647,7 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReqpublic function import_asset_checkout_is_blocked_when_fmcs_companies_differ(): void{[$companyA, $companyB] = Company::factory()->count(2)->create();- $user = User::factory()->for($companyB)->create();+ $user = User::factory()->forCompany($companyB)->create();$this->settings->enableMultipleFullCompanySupport();$importFileBuilder = ImportFileBuilder::new([@@ -668,7 +668,7 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReqpublic function import_asset_checkout_is_allowed_when_fmcs_companies_match(): void{$company = Company::factory()->create();- $user = User::factory()->for($company)->create();+ $user = User::factory()->forCompany($company)->create();$this->settings->enableMultipleFullCompanySupport();$importFileBuilder = ImportFileBuilder::new([@@ -689,7 +689,7 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReqpublic function import_asset_checkout_is_blocked_when_floater_disabled_and_user_has_no_company(): void{$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => null]);+ $user = User::factory()->withoutCompany()->create();$this->settings->enableMultipleFullCompanySupport()->disableFloaterMode();$importFileBuilder = ImportFileBuilder::new([@@ -710,7 +710,7 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReqpublic function import_asset_checkout_is_allowed_when_floater_enabled_and_user_has_no_company(): void{$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => null]);+ $user = User::factory()->withoutCompany()->create();$this->settings->enableFloaterMode();$importFileBuilder = ImportFileBuilder::new([diff --git a/tests/Feature/Importing/Api/ImportLicenseTest.php b/tests/Feature/Importing/Api/ImportLicenseTest.phpindex 8dac1de093..cf3dd1eb4c 100644--- a/tests/Feature/Importing/Api/ImportLicenseTest.php+++ b/tests/Feature/Importing/Api/ImportLicenseTest.php@@ -406,7 +406,7 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRepublic function import_license_checkout_is_blocked_when_fmcs_companies_differ(): void{[$companyA, $companyB] = Company::factory()->count(2)->create();- $user = User::factory()->for($companyB)->create();+ $user = User::factory()->forCompany($companyB)->create();$this->settings->enableMultipleFullCompanySupport();$importFileBuilder = ImportFileBuilder::new([@@ -429,7 +429,7 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRepublic function import_license_checkout_is_allowed_when_fmcs_companies_match(): void{$company = Company::factory()->create();- $user = User::factory()->for($company)->create();+ $user = User::factory()->forCompany($company)->create();$this->settings->enableMultipleFullCompanySupport();$importFileBuilder = ImportFileBuilder::new([@@ -452,7 +452,7 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRepublic function import_license_checkout_is_blocked_when_floater_disabled_and_user_has_no_company(): void{$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => null]);+ $user = User::factory()->withoutCompany()->create();$this->settings->enableMultipleFullCompanySupport()->disableFloaterMode();$importFileBuilder = ImportFileBuilder::new([@@ -475,7 +475,7 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRepublic function import_license_checkout_is_allowed_when_floater_enabled_and_user_has_no_company(): void{$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => null]);+ $user = User::factory()->withoutCompany()->create();$this->settings->enableFloaterMode();$importFileBuilder = ImportFileBuilder::new([diff --git a/tests/Feature/Importing/Api/ImportUsersTest.php b/tests/Feature/Importing/Api/ImportUsersTest.phpindex 4ce8805a7b..f6a0fc6bf3 100644--- a/tests/Feature/Importing/Api/ImportUsersTest.php+++ b/tests/Feature/Importing/Api/ImportUsersTest.php@@ -240,6 +240,11 @@ class ImportUsersTest extends ImportDataTestCase implements TestsPermissionsRequ'updated_at','phone','jobtitle',+ // The import changes the user's company via the company_user pivot.+ // syncLegacyCompanyIdMirror() then updates the users.legacy_company_id+ // mirror to reflect that change, so it also legitimately differs+ // between $user (pre-import) and $updatedUser (post-import).+ 'legacy_company_id',];$this->assertEquals($row['email'], $updatedUser->email);diff --git a/tests/Feature/LicenseSeats/Api/LicenseSeatUpdateTest.php b/tests/Feature/LicenseSeats/Api/LicenseSeatUpdateTest.phpindex d44db73d3b..c999ee3e36 100644--- a/tests/Feature/LicenseSeats/Api/LicenseSeatUpdateTest.php+++ b/tests/Feature/LicenseSeats/Api/LicenseSeatUpdateTest.php@@ -451,7 +451,7 @@ class LicenseSeatUpdateTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();- $superuser = User::factory()->superuser()->create(['company_id' => null]);+ $superuser = User::factory()->superuser()->withoutCompany()->create();$licenseInCompanyA = License::factory()->for($companyA)->create();$seatForCompanyA = LicenseSeat::factory()->create(['license_id' => $licenseInCompanyA->id,@@ -459,7 +459,7 @@ class LicenseSeatUpdateTest extends TestCase'asset_id' => null,'notes' => null,]);- $userInCompanyB = User::factory()->for($companyB)->create();+ $userInCompanyB = User::factory()->forCompany($companyB)->create();$this->actingAsForApi($superuser)->patchJson($this->route($seatForCompanyA), [diff --git a/tests/Feature/Licenses/Ui/BulkCheckinSelectedLicenseSeatsTest.php b/tests/Feature/Licenses/Ui/BulkCheckinSelectedLicenseSeatsTest.phpindex a65e1d07f4..bf995c4900 100644--- a/tests/Feature/Licenses/Ui/BulkCheckinSelectedLicenseSeatsTest.php+++ b/tests/Feature/Licenses/Ui/BulkCheckinSelectedLicenseSeatsTest.php@@ -195,9 +195,9 @@ class BulkCheckinSelectedLicenseSeatsTest extends TestCase implements TestsPermi[$myCompany, $otherCompany] = Company::factory()->count(2)->create();- $actor = User::factory()->checkinLicenses()->create(['company_id' => $myCompany->id]);+ $actor = User::factory()->checkinLicenses()->forCompany($myCompany->id)->create();$otherLicense = License::factory()->create(['company_id' => $otherCompany->id, 'seats' => 2]);- $targetUser = User::factory()->create(['company_id' => $otherCompany->id]);+ $targetUser = User::factory()->forCompany($otherCompany->id)->create();$seat = LicenseSeat::factory()->assignedToUser($targetUser)->create(['license_id' => $otherLicense->id]);$this->settings->enableMultipleFullCompanySupport();diff --git a/tests/Feature/Licenses/Ui/BulkDeleteLicensesTest.php b/tests/Feature/Licenses/Ui/BulkDeleteLicensesTest.phpindex f1f6eca004..98fb5c8ce0 100644--- a/tests/Feature/Licenses/Ui/BulkDeleteLicensesTest.php+++ b/tests/Feature/Licenses/Ui/BulkDeleteLicensesTest.php@@ -70,7 +70,7 @@ class BulkDeleteLicensesTest extends TestCase implements TestsPermissionsRequire{[$myCompany, $otherCompany] = Company::factory()->count(2)->create();- $actor = User::factory()->deleteLicenses()->create(['company_id' => $myCompany->id]);+ $actor = User::factory()->deleteLicenses()->forCompany($myCompany->id)->create();$otherLicense = License::factory()->create(['company_id' => $otherCompany->id, 'seats' => 1]);$this->settings->enableMultipleFullCompanySupport();diff --git a/tests/Feature/Locations/Api/LocationFileTest.php b/tests/Feature/Locations/Api/LocationFileTest.phpindex ca082cf4ed..bd52b8a40d 100644--- a/tests/Feature/Locations/Api/LocationFileTest.php+++ b/tests/Feature/Locations/Api/LocationFileTest.php@@ -228,7 +228,8 @@ class LocationFileTest extends TestCase$superUser = User::factory()->superuser()->create();$normalUser = User::factory()->manageLocationFiles()- ->create(['company_id' => $company->id]);+ ->forCompany($company)+ ->create();$this->actingAsForApi($superUser)->post(@@ -255,7 +256,8 @@ class LocationFileTest extends TestCase$superUser = User::factory()->superuser()->create();$userInCompanyB = User::factory()->manageLocationFiles()- ->create(['company_id' => $companyB->id]);+ ->forCompany($companyB)+ ->create();$this->actingAsForApi($superUser)->post(diff --git a/tests/Feature/Locations/Api/LocationParentCompanyTest.php b/tests/Feature/Locations/Api/LocationParentCompanyTest.phpindex 94db08c976..378bc847bd 100644--- a/tests/Feature/Locations/Api/LocationParentCompanyTest.php+++ b/tests/Feature/Locations/Api/LocationParentCompanyTest.php@@ -24,16 +24,16 @@ class LocationParentCompanyTest extends TestCase{$this->settings->enableMultipleFullCompanySupport();- $acme = Company::factory()->create(['name' => 'Acme']);+ $acme = Company::factory()->create(['name' => 'Acme']);$globex = Company::factory()->create(['name' => 'Globex']);$parentLocation = Location::factory()->create(['company_id' => $acme->id]);$this->actingAsForApi(User::factory()->superuser()->create())->postJson(route('api.locations.store'), [- 'name' => 'Location B',+ 'name' => 'Location B','company_id' => $globex->id,- 'parent_id' => $parentLocation->id,+ 'parent_id' => $parentLocation->id,])->assertOk()->assertStatusMessageIs('error');@@ -51,9 +51,9 @@ class LocationParentCompanyTest extends TestCase$this->actingAsForApi(User::factory()->superuser()->create())->postJson(route('api.locations.store'), [- 'name' => 'Location B',+ 'name' => 'Location B','company_id' => $acme->id,- 'parent_id' => $parentLocation->id,+ 'parent_id' => $parentLocation->id,])->assertOk()->assertStatusMessageIs('success');@@ -65,16 +65,16 @@ class LocationParentCompanyTest extends TestCase{$this->settings->disableMultipleFullCompanySupport();- $acme = Company::factory()->create(['name' => 'Acme']);+ $acme = Company::factory()->create(['name' => 'Acme']);$globex = Company::factory()->create(['name' => 'Globex']);$parentLocation = Location::factory()->create(['company_id' => $acme->id]);$this->actingAsForApi(User::factory()->superuser()->create())->postJson(route('api.locations.store'), [- 'name' => 'Location B',+ 'name' => 'Location B','company_id' => $globex->id,- 'parent_id' => $parentLocation->id,+ 'parent_id' => $parentLocation->id,])->assertOk()->assertStatusMessageIs('success');@@ -90,17 +90,17 @@ class LocationParentCompanyTest extends TestCase{$this->settings->enableMultipleFullCompanySupport();- $acme = Company::factory()->create(['name' => 'Acme']);+ $acme = Company::factory()->create(['name' => 'Acme']);$globex = Company::factory()->create(['name' => 'Globex']);$parentLocation = Location::factory()->create(['company_id' => $acme->id]);- $location = Location::factory()->create(['name' => 'Location B', 'company_id' => $globex->id]);+ $location = Location::factory()->create(['name' => 'Location B', 'company_id' => $globex->id]);$this->actingAsForApi(User::factory()->superuser()->create())->patchJson(route('api.locations.update', $location), [- 'name' => 'Location B',+ 'name' => 'Location B','company_id' => $globex->id,- 'parent_id' => $parentLocation->id,+ 'parent_id' => $parentLocation->id,])->assertOk()->assertStatusMessageIs('error');@@ -113,11 +113,11 @@ class LocationParentCompanyTest extends TestCase// Ensures the check fires even when company_id is not included in the request.$this->settings->enableMultipleFullCompanySupport();- $acme = Company::factory()->create(['name' => 'Acme']);+ $acme = Company::factory()->create(['name' => 'Acme']);$globex = Company::factory()->create(['name' => 'Globex']);$parentLocation = Location::factory()->create(['company_id' => $acme->id]);- $location = Location::factory()->create(['name' => 'Location B', 'company_id' => $globex->id]);+ $location = Location::factory()->create(['name' => 'Location B', 'company_id' => $globex->id]);$this->actingAsForApi(User::factory()->superuser()->create())->patchJson(route('api.locations.update', $location), [@@ -136,13 +136,13 @@ class LocationParentCompanyTest extends TestCase$acme = Company::factory()->create(['name' => 'Acme']);$parentLocation = Location::factory()->create(['company_id' => $acme->id]);- $location = Location::factory()->create(['name' => 'Location B', 'company_id' => $acme->id]);+ $location = Location::factory()->create(['name' => 'Location B', 'company_id' => $acme->id]);$this->actingAsForApi(User::factory()->superuser()->create())->patchJson(route('api.locations.update', $location), [- 'name' => 'Location B',+ 'name' => 'Location B','company_id' => $acme->id,- 'parent_id' => $parentLocation->id,+ 'parent_id' => $parentLocation->id,])->assertOk()->assertStatusMessageIs('success');@@ -154,17 +154,17 @@ class LocationParentCompanyTest extends TestCase{$this->settings->disableMultipleFullCompanySupport();- $acme = Company::factory()->create(['name' => 'Acme']);+ $acme = Company::factory()->create(['name' => 'Acme']);$globex = Company::factory()->create(['name' => 'Globex']);$parentLocation = Location::factory()->create(['company_id' => $acme->id]);- $location = Location::factory()->create(['name' => 'Location B', 'company_id' => $globex->id]);+ $location = Location::factory()->create(['name' => 'Location B', 'company_id' => $globex->id]);$this->actingAsForApi(User::factory()->superuser()->create())->patchJson(route('api.locations.update', $location), [- 'name' => 'Location B',+ 'name' => 'Location B','company_id' => $globex->id,- 'parent_id' => $parentLocation->id,+ 'parent_id' => $parentLocation->id,])->assertOk()->assertStatusMessageIs('success');diff --git a/tests/Feature/Locations/Api/LocationsFmcsScopingTest.php b/tests/Feature/Locations/Api/LocationsFmcsScopingTest.phpindex 22918f9695..2b0fefbd96 100644--- a/tests/Feature/Locations/Api/LocationsFmcsScopingTest.php+++ b/tests/Feature/Locations/Api/LocationsFmcsScopingTest.php@@ -41,7 +41,7 @@ class LocationsFmcsScopingTest extends TestCaseprivate function userWithNoCompany(): User{- return User::factory()->viewLocationHistory()->createUsers()->create(['company_id' => null]);+ return User::factory()->viewLocationHistory()->createUsers()->withoutCompany()->create();}private function indexIds(User $user): arraydiff --git a/tests/Feature/Locations/Ui/LocationParentCompanyTest.php b/tests/Feature/Locations/Ui/LocationParentCompanyTest.phpindex 351e36a243..772114c37d 100644--- a/tests/Feature/Locations/Ui/LocationParentCompanyTest.php+++ b/tests/Feature/Locations/Ui/LocationParentCompanyTest.php@@ -21,7 +21,7 @@ class LocationParentCompanyTest extends TestCase{$this->settings->enableMultipleFullCompanySupport();- $acme = Company::factory()->create(['name' => 'Acme']);+ $acme = Company::factory()->create(['name' => 'Acme']);$globex = Company::factory()->create(['name' => 'Globex']);$parentLocation = Location::factory()->create(['company_id' => $acme->id]);@@ -29,9 +29,9 @@ class LocationParentCompanyTest extends TestCase$this->actingAs(User::factory()->superuser()->create())->from(route('locations.create'))->post(route('locations.store'), [- 'name' => 'Location B',+ 'name' => 'Location B','company_id' => $globex->id,- 'parent_id' => $parentLocation->id,+ 'parent_id' => $parentLocation->id,])->assertRedirect(route('locations.create'))->assertSessionHas('error');@@ -49,9 +49,9 @@ class LocationParentCompanyTest extends TestCase$this->actingAs(User::factory()->superuser()->create())->post(route('locations.store'), [- 'name' => 'Location B',+ 'name' => 'Location B','company_id' => $acme->id,- 'parent_id' => $parentLocation->id,+ 'parent_id' => $parentLocation->id,])->assertRedirect(route('locations.index'))->assertSessionHasNoErrors();@@ -63,16 +63,16 @@ class LocationParentCompanyTest extends TestCase{$this->settings->disableMultipleFullCompanySupport();- $acme = Company::factory()->create(['name' => 'Acme']);+ $acme = Company::factory()->create(['name' => 'Acme']);$globex = Company::factory()->create(['name' => 'Globex']);$parentLocation = Location::factory()->create(['company_id' => $acme->id]);$this->actingAs(User::factory()->superuser()->create())->post(route('locations.store'), [- 'name' => 'Location B',+ 'name' => 'Location B','company_id' => $globex->id,- 'parent_id' => $parentLocation->id,+ 'parent_id' => $parentLocation->id,])->assertRedirect(route('locations.index'))->assertSessionHasNoErrors();@@ -88,18 +88,18 @@ class LocationParentCompanyTest extends TestCase{$this->settings->enableMultipleFullCompanySupport();- $acme = Company::factory()->create(['name' => 'Acme']);+ $acme = Company::factory()->create(['name' => 'Acme']);$globex = Company::factory()->create(['name' => 'Globex']);$parentLocation = Location::factory()->create(['company_id' => $acme->id]);- $location = Location::factory()->create(['name' => 'Location B', 'company_id' => $globex->id]);+ $location = Location::factory()->create(['name' => 'Location B', 'company_id' => $globex->id]);$this->actingAs(User::factory()->superuser()->create())->from(route('locations.edit', $location))->put(route('locations.update', $location), [- 'name' => 'Location B',+ 'name' => 'Location B','company_id' => $globex->id,- 'parent_id' => $parentLocation->id,+ 'parent_id' => $parentLocation->id,])->assertRedirect(route('locations.edit', $location))->assertSessionHas('error');@@ -114,13 +114,13 @@ class LocationParentCompanyTest extends TestCase$acme = Company::factory()->create(['name' => 'Acme']);$parentLocation = Location::factory()->create(['company_id' => $acme->id]);- $location = Location::factory()->create(['name' => 'Location B', 'company_id' => $acme->id]);+ $location = Location::factory()->create(['name' => 'Location B', 'company_id' => $acme->id]);$this->actingAs(User::factory()->superuser()->create())->put(route('locations.update', $location), [- 'name' => 'Location B',+ 'name' => 'Location B','company_id' => $acme->id,- 'parent_id' => $parentLocation->id,+ 'parent_id' => $parentLocation->id,])->assertRedirect(route('locations.index'))->assertSessionHasNoErrors();@@ -132,17 +132,17 @@ class LocationParentCompanyTest extends TestCase{$this->settings->disableMultipleFullCompanySupport();- $acme = Company::factory()->create(['name' => 'Acme']);+ $acme = Company::factory()->create(['name' => 'Acme']);$globex = Company::factory()->create(['name' => 'Globex']);$parentLocation = Location::factory()->create(['company_id' => $acme->id]);- $location = Location::factory()->create(['name' => 'Location B', 'company_id' => $globex->id]);+ $location = Location::factory()->create(['name' => 'Location B', 'company_id' => $globex->id]);$this->actingAs(User::factory()->superuser()->create())->put(route('locations.update', $location), [- 'name' => 'Location B',+ 'name' => 'Location B','company_id' => $globex->id,- 'parent_id' => $parentLocation->id,+ 'parent_id' => $parentLocation->id,])->assertRedirect(route('locations.index'))->assertSessionHasNoErrors();diff --git a/tests/Feature/Maintenances/Api/MaintenanceFileTest.php b/tests/Feature/Maintenances/Api/MaintenanceFileTest.phpindex 3b0a92043b..1db2c24276 100644--- a/tests/Feature/Maintenances/Api/MaintenanceFileTest.php+++ b/tests/Feature/Maintenances/Api/MaintenanceFileTest.php@@ -17,8 +17,7 @@ class MaintenanceFileTest extends TestCase$company = Company::factory()->create();$user = User::factory()- ->editAssets()- ->create(['company_id' => $company->id]);+ ->editAssets()->forCompany($company)->create();$asset = Asset::factory()->create(['company_id' => $company->id]);diff --git a/tests/Feature/Maintenances/Ui/MaintenanceFileTest.php b/tests/Feature/Maintenances/Ui/MaintenanceFileTest.phpindex a3cc091962..46a707a04f 100644--- a/tests/Feature/Maintenances/Ui/MaintenanceFileTest.php+++ b/tests/Feature/Maintenances/Ui/MaintenanceFileTest.php@@ -20,8 +20,7 @@ class MaintenanceFileTest extends TestCase$company = Company::factory()->create();$user = User::factory()- ->editAssets()- ->create(['company_id' => $company->id]);+ ->editAssets()->forCompany($company)->create();$asset = Asset::factory()->create(['company_id' => $company->id]);@@ -55,8 +54,7 @@ class MaintenanceFileTest extends TestCase$user = User::factory()->viewAssets()- ->editAssets()- ->create(['company_id' => $company->id]);+ ->editAssets()->forCompany($company)->create();$asset = Asset::factory()->create(['company_id' => $company->id]);diff --git a/tests/Feature/Reporting/ActivityReportTest.php b/tests/Feature/Reporting/ActivityReportTest.phpindex 5747152972..e411627644 100644--- a/tests/Feature/Reporting/ActivityReportTest.php+++ b/tests/Feature/Reporting/ActivityReportTest.php@@ -72,7 +72,8 @@ class ActivityReportTest extends TestCase$viewingUser = User::factory()->canViewReports()- ->create(['company_id' => $company->id]);+ ->forCompany($company)+ ->create();$model = AssetModel::factory()->create();@@ -109,7 +110,8 @@ class ActivityReportTest extends TestCase$viewerInCompanyB = User::factory()->canViewReports()- ->create(['company_id' => $companyB->id]);+ ->forCompany($companyB)+ ->create();// Superuser uploads a file to company A's asset (log gets company_id = companyA->id)$this->actingAsForApi($superUser)@@ -144,13 +146,15 @@ class ActivityReportTest extends TestCase->viewUsers()->viewAssets()->canViewReports()- ->create(['company_id' => $companyA->id]);+ ->forCompany($companyA)+ ->create();$userInCompanyB = User::factory()->viewUsers()->viewAssets()->canViewReports()- ->create(['company_id' => $companyB->id]);+ ->forCompany($companyB)+ ->create();Asset::factory()->count(5)->create(['company_id' => $companyA->id]);Asset::factory()->count(4)->create(['company_id' => $companyB->id]);diff --git a/tests/Feature/Reporting/Custom/CustomComponentReportTest.php b/tests/Feature/Reporting/Custom/CustomComponentReportTest.phpindex e8ff91072e..231899fb6f 100644--- a/tests/Feature/Reporting/Custom/CustomComponentReportTest.php+++ b/tests/Feature/Reporting/Custom/CustomComponentReportTest.php@@ -667,7 +667,7 @@ class CustomComponentReportTest extends TestCaseComponent::factory()->for($companyA)->create(['name' => 'Company A Component']);Component::factory()->for($companyB)->create(['name' => 'Company B Component']);- $this->actor = User::factory()->canViewReports()->for($companyA)->create();+ $this->actor = User::factory()->canViewReports()->forCompany($companyA)->create();$this->settings->enableMultipleFullCompanySupport();diff --git a/tests/Feature/Reporting/DeleteAcceptanceAuthorizationTest.php b/tests/Feature/Reporting/DeleteAcceptanceAuthorizationTest.phpindex 0749068e59..a6c920217f 100644--- a/tests/Feature/Reporting/DeleteAcceptanceAuthorizationTest.php+++ b/tests/Feature/Reporting/DeleteAcceptanceAuthorizationTest.php@@ -28,7 +28,7 @@ class DeleteAcceptanceAuthorizationTest extends TestCase[$companyA] = Company::factory()->count(2)->create();$asset = Asset::factory()->create(['company_id' => $companyA->id]);- $reporter = User::factory()->canViewReports()->create(['company_id' => $companyA->id]);+ $reporter = User::factory()->canViewReports()->forCompany($companyA)->create();$acceptance = CheckoutAcceptance::factory()->pending()->for($asset, 'checkoutable')->create();$this->actingAs($reporter)@@ -46,7 +46,7 @@ class DeleteAcceptanceAuthorizationTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$assetB = Asset::factory()->create(['company_id' => $companyB->id]);- $reporter = User::factory()->canViewReports()->create(['company_id' => $companyA->id]);+ $reporter = User::factory()->canViewReports()->forCompany($companyA)->create();$acceptance = CheckoutAcceptance::factory()->pending()->for($assetB, 'checkoutable')->create();$this->actingAs($reporter)@@ -64,7 +64,7 @@ class DeleteAcceptanceAuthorizationTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$assetB = Asset::factory()->create(['company_id' => $companyB->id]);- $superuser = User::factory()->superuser()->create(['company_id' => $companyA->id]);+ $superuser = User::factory()->superuser()->forCompany($companyA)->create();$acceptance = CheckoutAcceptance::factory()->pending()->for($assetB, 'checkoutable')->create();$this->actingAs($superuser)@@ -82,7 +82,7 @@ class DeleteAcceptanceAuthorizationTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$assetB = Asset::factory()->create(['company_id' => $companyB->id]);- $reporter = User::factory()->canViewReports()->create(['company_id' => null]);+ $reporter = User::factory()->canViewReports()->withoutCompany()->create();$reporter->companies()->sync([$companyA->id]);$acceptance = CheckoutAcceptance::factory()->pending()->for($assetB, 'checkoutable')->create();@@ -102,7 +102,7 @@ class DeleteAcceptanceAuthorizationTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$assetB = Asset::factory()->create(['company_id' => $companyB->id]);- $reporter = User::factory()->canViewReports()->create(['company_id' => $companyA->id]);+ $reporter = User::factory()->canViewReports()->forCompany($companyA)->create();$acceptance = CheckoutAcceptance::factory()->pending()->for($assetB, 'checkoutable')->create();$this->actingAs($reporter)diff --git a/tests/Feature/Reporting/SentReminderAuthorizationTest.php b/tests/Feature/Reporting/SentReminderAuthorizationTest.phpindex 7cd9568997..716c9f2cfe 100644--- a/tests/Feature/Reporting/SentReminderAuthorizationTest.php+++ b/tests/Feature/Reporting/SentReminderAuthorizationTest.php@@ -38,9 +38,9 @@ class SentReminderAuthorizationTest extends TestCase[$companyA] = Company::factory()->count(2)->create();- $assignee = User::factory()->create(['email' => '[email protected]', 'company_id' => $companyA->id]);+ $assignee = User::factory()->forCompany($companyA)->create(['email' => '[email protected]']);$asset = Asset::factory()->create(['company_id' => $companyA->id]);- $reporter = User::factory()->canViewReports()->create(['company_id' => $companyA->id]);+ $reporter = User::factory()->canViewReports()->forCompany($companyA)->create();$acceptance = CheckoutAcceptance::factory()->pending()->for($asset, 'checkoutable')@@ -64,7 +64,7 @@ class SentReminderAuthorizationTest extends TestCase$assignee = User::factory()->create(['email' => '[email protected]']);$assetB = Asset::factory()->create(['company_id' => $companyB->id]);- $reporter = User::factory()->canViewReports()->create(['company_id' => $companyA->id]);+ $reporter = User::factory()->canViewReports()->forCompany($companyA)->create();$acceptance = CheckoutAcceptance::factory()->pending()->for($assetB, 'checkoutable')@@ -88,7 +88,7 @@ class SentReminderAuthorizationTest extends TestCase$assignee = User::factory()->create(['email' => '[email protected]']);$assetB = Asset::factory()->create(['company_id' => $companyB->id]);- $reporter = User::factory()->canViewReports()->create(['company_id' => null]);+ $reporter = User::factory()->canViewReports()->withoutCompany()->create();$reporter->companies()->sync([$companyA->id]);$acceptance = CheckoutAcceptance::factory()@@ -114,7 +114,7 @@ class SentReminderAuthorizationTest extends TestCase$assignee = User::factory()->create(['email' => '[email protected]']);$assetB = Asset::factory()->create(['company_id' => $companyB->id]);- $superuser = User::factory()->superuser()->create(['company_id' => $companyA->id]);+ $superuser = User::factory()->superuser()->forCompany($companyA)->create();$acceptance = CheckoutAcceptance::factory()->pending()->for($assetB, 'checkoutable')diff --git a/tests/Feature/Requests/Ui/AssetRequestIndexTest.php b/tests/Feature/Requests/Ui/AssetRequestIndexTest.phpindex cc1bcab927..1542ecf84a 100644--- a/tests/Feature/Requests/Ui/AssetRequestIndexTest.php+++ b/tests/Feature/Requests/Ui/AssetRequestIndexTest.php@@ -36,7 +36,7 @@ class AssetRequestIndexTest extends TestCase$assetA = Asset::factory()->create(['company_id' => $companyA->id]);$request = CheckoutRequest::factory()->create(['requestable_id' => $assetA->id, 'requestable_type' => Asset::class]);- $viewer = User::factory()->viewAssets()->create(['company_id' => $companyA->id]);+ $viewer = User::factory()->viewAssets()->forCompany($companyA->id)->create();$this->actingAs($viewer)->get(route('assets.requested'))@@ -52,7 +52,7 @@ class AssetRequestIndexTest extends TestCase$assetB = Asset::factory()->create(['company_id' => $companyB->id]);$crossCompanyRequest = CheckoutRequest::factory()->create(['requestable_id' => $assetB->id, 'requestable_type' => Asset::class]);- $viewer = User::factory()->viewAssets()->create(['company_id' => $companyA->id]);+ $viewer = User::factory()->viewAssets()->forCompany($companyA->id)->create();$this->actingAs($viewer)->get(route('assets.requested'))@@ -71,7 +71,7 @@ class AssetRequestIndexTest extends TestCase$assetB = Asset::factory()->create(['company_id' => $companyB->id]);$crossCompanyRequest = CheckoutRequest::factory()->create(['requestable_id' => $assetB->id, 'requestable_type' => Asset::class]);- $viewer = User::factory()->viewAssets()->create(['company_id' => null]);+ $viewer = User::factory()->viewAssets()->withoutCompany()->create();$viewer->companies()->sync([$companyA->id]);$this->actingAs($viewer)@@ -92,7 +92,7 @@ class AssetRequestIndexTest extends TestCase$floaterAsset = Asset::factory()->create(['company_id' => null]);$request = CheckoutRequest::factory()->create(['requestable_id' => $floaterAsset->id, 'requestable_type' => Asset::class]);- $viewer = User::factory()->viewAssets()->create(['company_id' => $companyA->id]);+ $viewer = User::factory()->viewAssets()->forCompany($companyA->id)->create();$this->actingAs($viewer)->get(route('assets.requested'))@@ -113,7 +113,7 @@ class AssetRequestIndexTest extends TestCase$assetB = Asset::factory()->create(['company_id' => $companyB->id]);$requestA = CheckoutRequest::factory()->create(['requestable_id' => $assetA->id, 'requestable_type' => Asset::class]);$requestB = CheckoutRequest::factory()->create(['requestable_id' => $assetB->id, 'requestable_type' => Asset::class]);- $superuser = User::factory()->superuser()->create(['company_id' => $companyA->id]);+ $superuser = User::factory()->superuser()->forCompany($companyA->id)->create();$this->actingAs($superuser)->get(route('assets.requested'))@@ -130,7 +130,7 @@ class AssetRequestIndexTest extends TestCase$assetB = Asset::factory()->create(['company_id' => $companyB->id]);$request = CheckoutRequest::factory()->create(['requestable_id' => $assetB->id, 'requestable_type' => Asset::class]);- $viewer = User::factory()->viewAssets()->create(['company_id' => $companyA->id]);+ $viewer = User::factory()->viewAssets()->forCompany($companyA->id)->create();$this->actingAs($viewer)->get(route('assets.requested'))diff --git a/tests/Feature/Settings/ShowSetUpPageTest.php b/tests/Feature/Settings/ShowSetUpPageTest.phpindex 1c5a4cdee4..07f0cc026e 100644--- a/tests/Feature/Settings/ShowSetUpPageTest.php+++ b/tests/Feature/Settings/ShowSetUpPageTest.php@@ -7,12 +7,10 @@ use Illuminate\Database\Events\QueryExecuted;use Illuminate\Http\Client\ConnectionException;use Illuminate\Http\Client\Request;use Illuminate\Http\Client\Response;-use Illuminate\Log\Events\MessageLogged;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Event;use Illuminate\Support\Facades\File;use Illuminate\Support\Facades\Http;-use Illuminate\Support\Facades\Log;use Illuminate\Support\Facades\URL;use Illuminate\Testing\TestResponse;use PDOException;diff --git a/tests/Feature/Users/Api/DeleteUsersTest.php b/tests/Feature/Users/Api/DeleteUsersTest.phpindex 03d578ff39..f3258ff293 100644--- a/tests/Feature/Users/Api/DeleteUsersTest.php+++ b/tests/Feature/Users/Api/DeleteUsersTest.php@@ -108,8 +108,8 @@ class DeleteUsersTest extends TestCase implements TestsFullMultipleCompaniesSupp[$companyA, $companyB] = Company::factory()->count(2)->create();$superuser = User::factory()->superuser()->create();- $userFromA = User::factory()->deleteUsers()->for($companyA)->create();- $userFromB = User::factory()->deleteUsers()->for($companyB)->create();+ $userFromA = User::factory()->deleteUsers()->forCompany($companyA)->create();+ $userFromB = User::factory()->deleteUsers()->forCompany($companyB)->create();$this->actingAsForApi($userFromA)->deleteJson(route('api.users.destroy', $userFromB))diff --git a/tests/Feature/Users/Api/IndexUsersTest.php b/tests/Feature/Users/Api/IndexUsersTest.phpindex 0454eb5021..c09154aec8 100644--- a/tests/Feature/Users/Api/IndexUsersTest.php+++ b/tests/Feature/Users/Api/IndexUsersTest.php@@ -159,7 +159,7 @@ class IndexUsersTest extends TestCase$companyACaller = $companyA->users()->save(User::factory()->viewUsers()->make());$companyAPeer = $companyA->users()->save(User::factory()->make(['first_name' => 'PeerInA']));$companyBUser = $companyB->users()->save(User::factory()->make(['first_name' => 'UserInB']));- $floater = User::factory()->create(['company_id' => null, 'first_name' => 'FloaterUser']);+ $floater = User::factory()->withoutCompany()->create(['first_name' => 'FloaterUser']);$this->settings->enableFloaterMode();diff --git a/tests/Feature/Users/Api/RestoreUserTest.php b/tests/Feature/Users/Api/RestoreUserTest.phpindex b4848bb023..3471ded0cf 100644--- a/tests/Feature/Users/Api/RestoreUserTest.php+++ b/tests/Feature/Users/Api/RestoreUserTest.php@@ -59,8 +59,8 @@ class RestoreUserTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$superuser = User::factory()->superuser()->create();- $userFromA = User::factory()->deletedUser()->deleteUsers()->for($companyA)->create();- $userFromB = User::factory()->deletedUser()->deleteUsers()->for($companyB)->create();+ $userFromA = User::factory()->deletedUser()->deleteUsers()->forCompany($companyA)->create();+ $userFromB = User::factory()->deletedUser()->deleteUsers()->forCompany($companyB)->create();$this->actingAsForApi($userFromA)->postJson(route('api.users.restore', ['user' => $userFromB->id]))diff --git a/tests/Feature/Users/Api/UpdateUserTest.php b/tests/Feature/Users/Api/UpdateUserTest.phpindex 2120975b4c..b981608523 100644--- a/tests/Feature/Users/Api/UpdateUserTest.php+++ b/tests/Feature/Users/Api/UpdateUserTest.php@@ -313,14 +313,14 @@ class UpdateUserTest extends TestCase$companyA = Company::factory()->create(['name' => 'Company A']);$companyB = Company::factory()->create(['name' => 'Company B']);- $adminA = User::factory(['company_id' => $companyA->id])->admin()->create();- $adminB = User::factory(['company_id' => $companyB->id])->admin()->create();- $adminNoCompany = User::factory(['company_id' => null])->admin()->create();+ $adminA = User::factory()->forCompany($companyA)->admin()->create();+ $adminB = User::factory()->forCompany($companyB)->admin()->create();+ $adminNoCompany = User::factory()->withoutCompany()->admin()->create();// Create users that belongs to company A and B and one that is unscoped- $scoped_user_in_companyA = User::factory()->create(['company_id' => $companyA->id]);- $scoped_user_in_companyB = User::factory()->create(['company_id' => $companyB->id]);- $scoped_user_in_no_company = User::factory()->create(['company_id' => null]);+ $scoped_user_in_companyA = User::factory()->forCompany($companyA->id)->create();+ $scoped_user_in_companyB = User::factory()->forCompany($companyB->id)->create();+ $scoped_user_in_no_company = User::factory()->withoutCompany()->create();// Admin for Company A should allow updating user from Company A$this->actingAsForApi($adminA)@@ -522,9 +522,7 @@ class UpdateUserTest extends TestCase$companyA = Company::factory()->create();$companyB = Company::factory()->create();- $user = User::factory()->create([- 'company_id' => $companyA->id,- ]);+ $user = User::factory()->forCompany($companyA)->create();$superUser = User::factory()->superuser()->create();$asset = Asset::factory()->create([@@ -567,9 +565,7 @@ class UpdateUserTest extends TestCase$companyA = Company::factory()->create();$companyB = Company::factory()->create();- $user = User::factory()->create([- 'company_id' => $companyA->id,- ]);+ $user = User::factory()->forCompany($companyA)->create();$superUser = User::factory()->superuser()->create();$asset = Asset::factory()->create([diff --git a/tests/Feature/Users/Api/UserCompanyMembershipTest.php b/tests/Feature/Users/Api/UserCompanyMembershipTest.phpindex e4d8c85c2d..c4f3058fe5 100644--- a/tests/Feature/Users/Api/UserCompanyMembershipTest.php+++ b/tests/Feature/Users/Api/UserCompanyMembershipTest.php@@ -37,7 +37,7 @@ class UserCompanyMembershipTest extends TestCase{[$companyA, $companyB, $companyC] = Company::factory()->count(3)->create();- $user = User::factory()->create(['company_id' => $companyA->id]);+ $user = User::factory()->forCompany($companyA->id)->create();$user->companies()->sync([$companyA->id]);$actor = User::factory()->superuser()->create();@@ -63,7 +63,7 @@ class UserCompanyMembershipTest extends TestCase{[$companyA, $companyB] = Company::factory()->count(2)->create();- $user = User::factory()->create(['company_id' => $companyA->id]);+ $user = User::factory()->forCompany($companyA->id)->create();$user->companies()->sync([$companyA->id, $companyB->id]);$actor = User::factory()->superuser()->create();@@ -85,7 +85,7 @@ class UserCompanyMembershipTest extends TestCasepublic function test_api_response_company_entries_include_tag_color(){$company = Company::factory()->create(['tag_color' => '#ff0000']);- $user = User::factory()->create(['company_id' => $company->id]);+ $user = User::factory()->forCompany($company->id)->create();$user->companies()->sync([$company->id]);$actor = User::factory()->superuser()->create();@@ -105,17 +105,12 @@ class UserCompanyMembershipTest extends TestCase[$companyA, $companyB, $companyC] = Company::factory()->count(3)->create();- $userInA = User::factory()->create(['first_name' => 'Alice', 'last_name' => 'Alpha', 'company_id' => $companyA->id]);- $companyA->users()->syncWithoutDetaching([$userInA->id]);-- $userInB = User::factory()->create(['first_name' => 'Bob', 'last_name' => 'Beta', 'company_id' => $companyB->id]);- $companyB->users()->syncWithoutDetaching([$userInB->id]);-- $userInC = User::factory()->create(['first_name' => 'Carol', 'last_name' => 'Gamma', 'company_id' => $companyC->id]);- $companyC->users()->syncWithoutDetaching([$userInC->id]);+ $userInA = User::factory()->forCompany($companyA)->create(['first_name' => 'Alice', 'last_name' => 'Alpha']);+ $userInB = User::factory()->forCompany($companyB)->create(['first_name' => 'Bob', 'last_name' => 'Beta']);+ $userInC = User::factory()->forCompany($companyC)->create(['first_name' => 'Carol', 'last_name' => 'Gamma']);// Acting user belongs to both A and B.- $actor = User::factory()->viewUsers()->create(['company_id' => null]);+ $actor = User::factory()->viewUsers()->withoutCompany()->create();$actor->companies()->sync([$companyA->id, $companyB->id]);$response = $this->actingAsForApi($actor)@@ -135,13 +130,13 @@ class UserCompanyMembershipTest extends TestCase$company = Company::factory()->create();- $assignedUser = User::factory()->create(['company_id' => $company->id]);+ $assignedUser = User::factory()->forCompany($company->id)->create();$company->users()->syncWithoutDetaching([$assignedUser->id]);- $unassignedUser = User::factory()->create(['company_id' => null]);+ $unassignedUser = User::factory()->withoutCompany()->create();// Actor belongs to no companies.- $actor = User::factory()->viewUsers()->create(['company_id' => null]);+ $actor = User::factory()->viewUsers()->withoutCompany()->create();$response = $this->actingAsForApi($actor)->getJson(route('api.users.index'))@@ -157,7 +152,7 @@ class UserCompanyMembershipTest extends TestCasepublic function test_patch_with_invalid_company_id_returns_error(){$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id]);+ $user = User::factory()->forCompany($company->id)->create();$user->companies()->sync([$company->id]);$actor = User::factory()->superuser()->create();@@ -170,13 +165,13 @@ class UserCompanyMembershipTest extends TestCase->assertStatusMessageIs('error');$user->refresh();- $this->assertEquals($company->id, $user->company_id, 'company_id should not be changed on invalid input');+ $this->assertEquals($company->id, $user->legacy_company_id, 'legacy_company_id mirror should not be changed on invalid input');}public function test_put_with_invalid_company_id_returns_error(){$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id]);+ $user = User::factory()->forCompany($company->id)->create();$actor = User::factory()->superuser()->create();@@ -191,13 +186,13 @@ class UserCompanyMembershipTest extends TestCase->assertStatusMessageIs('error');$user->refresh();- $this->assertEquals($company->id, $user->company_id, 'company_id should not be changed on invalid input');+ $this->assertEquals($company->id, $user->legacy_company_id, 'legacy_company_id mirror should not be changed on invalid input');}public function test_patch_with_invalid_company_ids_returns_error(){$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id]);+ $user = User::factory()->forCompany($company->id)->create();$user->companies()->sync([$company->id]);$actor = User::factory()->superuser()->create();diff --git a/tests/Feature/Users/Api/UserSearchTest.php b/tests/Feature/Users/Api/UserSearchTest.phpindex 2c28f3fb3e..1643833ead 100644--- a/tests/Feature/Users/Api/UserSearchTest.php+++ b/tests/Feature/Users/Api/UserSearchTest.php@@ -94,7 +94,7 @@ class UserSearchTest extends TestCase->has(User::factory(['first_name' => 'Company B', 'last_name' => 'User']))->create();- $response = $this->actingAsForApi(User::factory()->for($companyA)->viewUsers()->create())+ $response = $this->actingAsForApi(User::factory()->forCompany($companyA)->viewUsers()->create())->getJson(route('api.users.index'))->assertOk();@@ -122,7 +122,7 @@ class UserSearchTest extends TestCase->has(User::factory(['first_name' => 'Company B', 'last_name' => 'User']))->create();- $response = $this->actingAsForApi(User::factory()->for($companyA)->viewUsers()->create())+ $response = $this->actingAsForApi(User::factory()->forCompany($companyA)->viewUsers()->create())->getJson(route('api.users.index', ['deleted' => 'false','company_id' => null,diff --git a/tests/Feature/Users/ImpersonateUserTest.php b/tests/Feature/Users/ImpersonateUserTest.phpindex b21f4afd0d..af832ed16a 100644--- a/tests/Feature/Users/ImpersonateUserTest.php+++ b/tests/Feature/Users/ImpersonateUserTest.php@@ -223,7 +223,7 @@ class ImpersonateUserTest extends TestCase$actor = User::factory()->superuser()->create();$actor->companies()->sync([$companyA->id]);- $target = User::factory()->create(['activated' => 1, 'company_id' => $companyB->id]);+ $target = User::factory()->forCompany($companyB)->create(['activated' => 1]);$target->companies()->sync([$companyB->id]);$this->allow($actor);diff --git a/tests/Feature/Users/LegacyCompanyIdMirrorTest.php b/tests/Feature/Users/LegacyCompanyIdMirrorTest.phpnew file mode 100644index 0000000000..67f097cd79--- /dev/null+++ b/tests/Feature/Users/LegacyCompanyIdMirrorTest.php@@ -0,0 +1,103 @@+<?php++namespace Tests\Feature\Users;++use App\Models\Company;+use App\Models\User;+use Illuminate\Support\Facades\DB;+use Tests\TestCase;++/**+ * The users.legacy_company_id column is a compatibility mirror of the+ * company_user pivot, maintained purely for external consumers (API responses,+ * CSV exports, SCIM mappings) that still expect it. Internal FMCS logic reads+ * ONLY the pivot. The invariant these tests protect: the mirror is always+ * either NULL (pivot empty) or equal to one of the pivot entries, so it can+ * never surprise a downstream integration that reads the two independently.+ */+class LegacyCompanyIdMirrorTest extends TestCase+{+ public function test_sync_companies_with_logging_populates_scalar_from_empty()+ {+ $company = Company::factory()->create();+ $user = User::factory()->create();+ DB::table('users')->where('id', $user->id)->update(['legacy_company_id' => null]);+ $user->refresh();++ $user->syncCompaniesWithLogging([$company->id]);++ $this->assertSame((int) $company->id, (int) $user->fresh()->legacy_company_id);+ }++ public function test_sync_companies_with_logging_clears_scalar_when_pivot_becomes_empty()+ {+ $company = Company::factory()->create();+ $user = User::factory()->create();+ $user->companies()->sync([$company->id]);+ DB::table('users')->where('id', $user->id)->update(['legacy_company_id' => $company->id]);+ $user->refresh();++ $this->assertSame((int) $company->id, (int) $user->legacy_company_id);++ $user->syncCompaniesWithLogging([]);++ $this->assertNull($user->fresh()->legacy_company_id);+ }++ public function test_sync_companies_with_logging_realigns_scalar_when_original_membership_removed()+ {+ [$companyA, $companyB] = Company::factory()->count(2)->create();+ $user = User::factory()->create();+ $user->companies()->sync([$companyA->id]);+ DB::table('users')->where('id', $user->id)->update(['legacy_company_id' => $companyA->id]);+ $user->refresh();++ $user->syncCompaniesWithLogging([$companyB->id]);++ $this->assertSame((int) $companyB->id, (int) $user->fresh()->legacy_company_id);+ }++ public function test_align_helper_picks_the_lowest_pivot_id_when_multiple()+ {+ $companies = Company::factory()->count(3)->create();+ $expected = $companies->min('id');++ $user = User::factory()->create();+ $user->syncCompaniesWithLogging($companies->pluck('id')->all());++ $this->assertSame((int) $expected, (int) $user->fresh()->legacy_company_id);+ }++ public function test_legacy_user_with_empty_pivot_and_null_scalar_is_preserved()+ {+ // Legacy no-company users predate FMCS. Neither the scalar nor the pivot+ // is populated, and the FMCS policy check reads that combination as+ // "true legacy user, treat as unscoped". The invariant enforcement must+ // NOT accidentally move them out of that state when they haven't been+ // touched by a pivot write.+ $user = User::factory()->withoutCompany()->create();+ $user->companies()->detach();+ DB::table('users')->where('id', $user->id)->update(['legacy_company_id' => null]);+ $user->refresh();++ $this->assertEmpty($user->companies()->pluck('companies.id')->all());+ $this->assertNull($user->legacy_company_id);++ // Simulating a downstream code path that reads (not writes) the user+ // must not mutate either field.+ $user->fresh();++ $this->assertNull($user->legacy_company_id);+ $this->assertEmpty($user->companies()->pluck('companies.id')->all());+ }++ public function test_align_helper_is_a_noop_on_unpersisted_users()+ {+ $user = new User;++ // Should not throw and should not attempt a DB write.+ $user->syncLegacyCompanyIdMirror();++ $this->assertFalse($user->exists);+ }+}diff --git a/tests/Feature/Users/Ui/CloneUserTest.php b/tests/Feature/Users/Ui/CloneUserTest.phpindex 8534e8116f..c42ad64c36 100644--- a/tests/Feature/Users/Ui/CloneUserTest.php+++ b/tests/Feature/Users/Ui/CloneUserTest.php@@ -19,7 +19,7 @@ class CloneUserTest extends TestCase{[$companyA, $companyB] = Company::factory()->count(2)->create();- $user = User::factory()->create(['company_id' => $companyA->id]);+ $user = User::factory()->forCompany($companyA->id)->create();$user->companies()->sync([$companyA->id, $companyB->id]);$response = $this->actingAs(User::factory()->superuser()->create())diff --git a/tests/Feature/Users/Ui/DeleteUserTest.php b/tests/Feature/Users/Ui/DeleteUserTest.phpindex b3a63177bc..9c0e1cb980 100644--- a/tests/Feature/Users/Ui/DeleteUserTest.php+++ b/tests/Feature/Users/Ui/DeleteUserTest.php@@ -61,8 +61,8 @@ class DeleteUserTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$superuser = User::factory()->superuser()->create();- $userFromA = User::factory()->deleteUsers()->for($companyA)->create();- $userFromB = User::factory()->deleteUsers()->for($companyB)->create();+ $userFromA = User::factory()->deleteUsers()->forCompany($companyA)->create();+ $userFromB = User::factory()->deleteUsers()->forCompany($companyB)->create();$response = $this->followingRedirects()->actingAs($userFromA)->delete(route('users.destroy', ['user' => $userFromB->id]))diff --git a/tests/Feature/Users/Ui/EmailAssignedToUserTest.php b/tests/Feature/Users/Ui/EmailAssignedToUserTest.phpindex 4bdb73b830..14e31bc21d 100644--- a/tests/Feature/Users/Ui/EmailAssignedToUserTest.php+++ b/tests/Feature/Users/Ui/EmailAssignedToUserTest.php@@ -19,13 +19,13 @@ class EmailAssignedToUserTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();$superuser = User::factory()->superuser()->create();- $user = User::factory()->for($companyB)->create();+ $user = User::factory()->forCompany($companyB)->create();- $this->actingAs(User::factory()->viewUsers()->for($companyA)->create())+ $this->actingAs(User::factory()->viewUsers()->forCompany($companyA)->create())->post(route('users.email', ['userId' => $user->id]))->assertStatus(403);- $this->actingAs(User::factory()->viewUsers()->for($companyB)->create())+ $this->actingAs(User::factory()->viewUsers()->forCompany($companyB)->create())->post(route('users.email', ['userId' => $user->id]))->assertStatus(302);diff --git a/tests/Feature/Users/Ui/ExportUsersTest.php b/tests/Feature/Users/Ui/ExportUsersTest.phpindex bd3f022134..27abf4ce03 100644--- a/tests/Feature/Users/Ui/ExportUsersTest.php+++ b/tests/Feature/Users/Ui/ExportUsersTest.php@@ -27,7 +27,7 @@ class ExportUsersTest extends TestCase$deptManager = User::factory()->create(['first_name' => 'Mace', 'last_name' => 'Windu']);$luke = User::factory()- ->forCompany(['name' => 'Jedi'])+ ->forCompany(Company::factory()->create(['name' => 'Jedi']))->forManager(['first_name' => 'Ben', 'last_name' => 'Kenobi'])->forLocation(['name' => 'Space'])->forDepartment(['name' => 'Lightsaber Fighting Dept', 'manager_id' => $deptManager->id])@@ -139,7 +139,7 @@ class ExportUsersTest extends TestCase['name' => 'Galactic Senate'],)->count(2)->create();- $user = User::factory()->create(['company_id' => $companyA->id]);+ $user = User::factory()->forCompany($companyA->id)->create();$user->companies()->sync([$companyA->id, $companyB->id]);$this->actingAs(User::factory()->viewUsers()->create())@@ -185,7 +185,7 @@ class ExportUsersTest extends TestCase$inScope = User::factory()->create();$inScope->companies()->sync([$company->id]);- $nullCompany = User::factory()->create(['company_id' => null]);+ $nullCompany = User::factory()->withoutCompany()->create();$actor = User::factory()->viewUsers()->create();$actor->companies()->sync([$company->id]);@@ -207,7 +207,7 @@ class ExportUsersTest extends TestCase$inScope = User::factory()->create();$inScope->companies()->sync([$company->id]);- $nullCompany = User::factory()->create(['company_id' => null]);+ $nullCompany = User::factory()->withoutCompany()->create();$actor = User::factory()->viewUsers()->create();$actor->companies()->sync([$company->id]);diff --git a/tests/Feature/Users/Ui/PrintUserInventoryTest.php b/tests/Feature/Users/Ui/PrintUserInventoryTest.phpindex 9468d571f0..545adb841c 100644--- a/tests/Feature/Users/Ui/PrintUserInventoryTest.php+++ b/tests/Feature/Users/Ui/PrintUserInventoryTest.php@@ -35,8 +35,8 @@ class PrintUserInventoryTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();- $actor = User::factory()->for($companyA)->viewUsers()->create();- $user = User::factory()->for($companyB)->create();+ $actor = User::factory()->forCompany($companyA)->viewUsers()->create();+ $user = User::factory()->forCompany($companyB)->create();$this->actingAs($actor)->get(route('users.print', $user))diff --git a/tests/Feature/Users/Ui/UpdateUserTest.php b/tests/Feature/Users/Ui/UpdateUserTest.phpindex 53e7969fc6..92137d30d1 100644--- a/tests/Feature/Users/Ui/UpdateUserTest.php+++ b/tests/Feature/Users/Ui/UpdateUserTest.php@@ -66,7 +66,7 @@ class UpdateUserTest extends TestCase$this->settings->enableMultipleFullCompanySupport();$this->settings->disableFloaterMode();- $self = User::factory()->editUsers()->create(['company_id' => null]);+ $self = User::factory()->editUsers()->withoutCompany()->create();$self->companies()->sync([]);$this->actingAs($self)@@ -234,9 +234,7 @@ class UpdateUserTest extends TestCase$companyA = Company::factory()->create();$companyB = Company::factory()->create();- $user = User::factory()->create([- 'company_id' => $companyA->id,- ]);+ $user = User::factory()->forCompany($companyA)->create();$superUser = User::factory()->superuser()->create();$asset = Asset::factory()->create([@@ -270,9 +268,7 @@ class UpdateUserTest extends TestCase$companyA = Company::factory()->create();- $user = User::factory()->create([- 'company_id' => $companyA->id,- ]);+ $user = User::factory()->forCompany($companyA)->create();$superUser = User::factory()->superuser()->create();$asset = Asset::factory()->create([@@ -362,7 +358,7 @@ class UpdateUserTest extends TestCasepublic function test_attempting_to_update_deleted_user_is_handled_gracefully(){[$companyA, $companyB] = Company::factory()->count(2)->create();- $user = User::factory()->for($companyA)->create();+ $user = User::factory()->forCompany($companyA)->create();Asset::factory()->assignedToUser($user)->create();$id = $user->id;diff --git a/tests/Feature/Users/Ui/UserCompanyMembershipTest.php b/tests/Feature/Users/Ui/UserCompanyMembershipTest.phpindex bb39dac157..e07ab2a242 100644--- a/tests/Feature/Users/Ui/UserCompanyMembershipTest.php+++ b/tests/Feature/Users/Ui/UserCompanyMembershipTest.php@@ -12,7 +12,7 @@ class UserCompanyMembershipTest extends TestCase{[$companyA, $companyB] = Company::factory()->count(2)->create();- $user = User::factory()->create(['company_id' => $companyA->id]);+ $user = User::factory()->forCompany($companyA->id)->create();$user->companies()->sync([$companyA->id]);$actor = User::factory()->superuser()->create();@@ -38,7 +38,7 @@ class UserCompanyMembershipTest extends TestCase{[$companyA, $companyB] = Company::factory()->count(2)->create();- $users = User::factory()->count(3)->create(['company_id' => null]);+ $users = User::factory()->count(3)->withoutCompany()->create();$actor = User::factory()->superuser()->create();@@ -63,7 +63,7 @@ class UserCompanyMembershipTest extends TestCase{$company = Company::factory()->create();- $users = User::factory()->count(2)->create(['company_id' => $company->id]);+ $users = User::factory()->count(2)->forCompany($company->id)->create();foreach ($users as $user) {$user->companies()->sync([$company->id]);}diff --git a/tests/Feature/Users/Ui/ViewUserTest.php b/tests/Feature/Users/Ui/ViewUserTest.phpindex fc1ccb9c33..600a88a29c 100644--- a/tests/Feature/Users/Ui/ViewUserTest.php+++ b/tests/Feature/Users/Ui/ViewUserTest.php@@ -34,8 +34,8 @@ class ViewUserTest extends TestCase[$companyA, $companyB] = Company::factory()->count(2)->create();- $actor = User::factory()->for($companyA)->viewUsers()->create();- $user = User::factory()->for($companyB)->create();+ $actor = User::factory()->forCompany($companyA)->viewUsers()->create();+ $user = User::factory()->forCompany($companyB)->create();$this->actingAs($actor)->get(route('users.show', $user))diff --git a/tests/Feature/Users/UserCompanyLoggingTest.php b/tests/Feature/Users/UserCompanyLoggingTest.phpindex 1ab8680a3f..9d09795f0c 100644--- a/tests/Feature/Users/UserCompanyLoggingTest.php+++ b/tests/Feature/Users/UserCompanyLoggingTest.php@@ -13,7 +13,7 @@ class UserCompanyLoggingTest extends TestCase{[$companyA, $companyB] = Company::factory()->count(2)->create();- $user = User::factory()->create(['company_id' => $companyA->id, 'jobtitle' => 'Engineer']);+ $user = User::factory()->forCompany($companyA->id)->create(['jobtitle' => 'Engineer']);$user->companies()->sync([$companyA->id]);$actor = User::factory()->superuser()->create();@@ -49,7 +49,7 @@ class UserCompanyLoggingTest extends TestCase{[$companyA, $companyB] = Company::factory()->count(2)->create();- $user = User::factory()->create(['company_id' => $companyA->id]);+ $user = User::factory()->forCompany($companyA->id)->create();$user->companies()->sync([$companyA->id]);$actor = User::factory()->superuser()->create();@@ -84,7 +84,7 @@ class UserCompanyLoggingTest extends TestCase{[$companyA, $companyB, $companyC] = Company::factory()->count(3)->create();- $user = User::factory()->create(['company_id' => $companyA->id]);+ $user = User::factory()->forCompany($companyA->id)->create();$user->companies()->sync([$companyA->id, $companyB->id]);$actor = User::factory()->superuser()->create();@@ -122,7 +122,7 @@ class UserCompanyLoggingTest extends TestCase{$company = Company::factory()->create();- $user = User::factory()->create(['company_id' => $company->id]);+ $user = User::factory()->forCompany($company->id)->create();$user->companies()->sync([$company->id]);$actor = User::factory()->superuser()->create();diff --git a/tests/Support/ProvidesDataForFullMultipleCompanySupportTesting.php b/tests/Support/ProvidesDataForFullMultipleCompanySupportTesting.phpindex 1a4ffd05a9..2aacee4f7e 100644--- a/tests/Support/ProvidesDataForFullMultipleCompanySupportTesting.php+++ b/tests/Support/ProvidesDataForFullMultipleCompanySupportTesting.php@@ -13,7 +13,7 @@ trait ProvidesDataForFullMultipleCompanySupportTestingyield "User in a company should result in user's company_id being used" => [function () {$jedi = Company::factory()->create();- $luke = User::factory()->for($jedi)+ $luke = User::factory()->forCompany($jedi)->createAccessories()->createAssets()->createComponents()@@ -35,12 +35,13 @@ trait ProvidesDataForFullMultipleCompanySupportTestingyield 'User without a company should result in company_id being null' => [function () {$userInNoCompany = User::factory()+ ->withoutCompany()->createAccessories()->createAssets()->createComponents()->createConsumables()->createLicenses()- ->create(['company_id' => null]);+ ->create();return ['actor' => $userInNoCompany,@@ -54,7 +55,7 @@ trait ProvidesDataForFullMultipleCompanySupportTestingyield 'Super-User assigning across companies should result in company_id being set to what was provided' => [function () {- $superUser = User::factory()->superuser()->create(['company_id' => null]);+ $superUser = User::factory()->superuser()->withoutCompany()->create();$company = Company::factory()->create();return [diff --git a/tests/Unit/CompanyScopingTest.php b/tests/Unit/CompanyScopingTest.phpindex 0a53ef305b..7e2a22d0b9 100644--- a/tests/Unit/CompanyScopingTest.php+++ b/tests/Unit/CompanyScopingTest.php@@ -200,7 +200,7 @@ class CompanyScopingTest extends TestCase$company = Company::factory()->create();$nullCompanyItem = $model::factory()->create(['company_id' => null]);$companyItem = $model::factory()->for($company)->create();- $nullCompanyUser = User::factory()->create(['company_id' => null]);+ $nullCompanyUser = User::factory()->withoutCompany()->create();$this->settings->enableMultipleFullCompanySupport();@@ -215,7 +215,7 @@ class CompanyScopingTest extends TestCase$company = Company::factory()->create();$nullCompanyItem = $model::factory()->create(['company_id' => null]);$companyItem = $model::factory()->for($company)->create();- $nullCompanyUser = User::factory()->create(['company_id' => null]);+ $nullCompanyUser = User::factory()->withoutCompany()->create();$this->settings->enableFloaterMode();@@ -236,7 +236,7 @@ class CompanyScopingTest extends TestCase{$company = Company::factory()->create();$companyUser = $company->users()->save(User::factory()->make());- $nullCompanyUser = User::factory()->create(['company_id' => null]);+ $nullCompanyUser = User::factory()->withoutCompany()->create();$this->settings->enableFloaterMode();@@ -248,7 +248,7 @@ class CompanyScopingTest extends TestCase{$company = Company::factory()->create();$companyUser = $company->users()->save(User::factory()->make());- $nullCompanyUser = User::factory()->create(['company_id' => null]);+ $nullCompanyUser = User::factory()->withoutCompany()->create();$this->settings->enableMultipleFullCompanySupport();@@ -265,8 +265,8 @@ class CompanyScopingTest extends TestCase{$company = Company::factory()->create();$companyUser = $company->users()->save(User::factory()->make());- $nullCompanyCaller = User::factory()->create(['company_id' => null]);- $anotherNullCompanyUser = User::factory()->create(['company_id' => null]);+ $nullCompanyCaller = User::factory()->withoutCompany()->create();+ $anotherNullCompanyUser = User::factory()->withoutCompany()->create();$this->settings->enableFloaterMode();@@ -293,7 +293,7 @@ class CompanyScopingTest extends TestCase$companyACaller = $companyA->users()->save(User::factory()->make());$companyAPeer = $companyA->users()->save(User::factory()->make());$companyBUser = $companyB->users()->save(User::factory()->make());- $floaterUser = User::factory()->create(['company_id' => null]);+ $floaterUser = User::factory()->withoutCompany()->create();$this->settings->enableFloaterMode();@@ -327,10 +327,10 @@ class CompanyScopingTest extends TestCase$superuser = $companyA->users()->save(User::factory()->superuser()->make());$callerInA = $companyA->users()->save(User::factory()->make());- $callerFloater = User::factory()->create(['company_id' => null]);+ $callerFloater = User::factory()->withoutCompany()->create();$peerInA = $companyA->users()->save(User::factory()->make());$userInB = $companyB->users()->save(User::factory()->make());- $floater = User::factory()->create(['company_id' => null]);+ $floater = User::factory()->withoutCompany()->create();// FMCS off: everyone sees everyone regardless of caller.$this->settings->disableMultipleFullCompanySupport();diff --git a/tests/Unit/ComponentTest.php b/tests/Unit/ComponentTest.phpindex 1b5ba36545..19adf45dd9 100644--- a/tests/Unit/ComponentTest.php+++ b/tests/Unit/ComponentTest.php@@ -67,7 +67,7 @@ class ComponentTest extends TestCase$this->actingAs(User::factory()->admin()->create());$this->assertEquals(4, $componentForCompanyA->fresh()->numCheckedOut());- $this->actingAs(User::factory()->for($companyA)->create());+ $this->actingAs(User::factory()->forCompany($companyA)->create());$this->assertEquals(4, $componentForCompanyA->fresh()->numCheckedOut());}@@ -94,7 +94,7 @@ class ComponentTest extends TestCase$this->actingAs(User::factory()->admin()->create());$this->assertEquals(1, $componentForCompanyA->fresh()->numRemaining());- $this->actingAs(User::factory()->for($companyA)->create());+ $this->actingAs(User::factory()->forCompany($companyA)->create());$this->assertEquals(1, $componentForCompanyA->fresh()->numRemaining());}diff --git a/tests/Unit/Models/Company/CompanyTest.php b/tests/Unit/Models/Company/CompanyTest.phpindex 8857f99de8..c2040da495 100644--- a/tests/Unit/Models/Company/CompanyTest.php+++ b/tests/Unit/Models/Company/CompanyTest.php@@ -11,12 +11,7 @@ class CompanyTest extends TestCasepublic function test_a_company_can_have_users(){$company = Company::factory()->create();- $user = User::factory()- ->create(- [- 'company_id' => $company->id,- ]- );+ User::factory()->forCompany($company)->create();$this->assertCount(1, $company->users);}diff --git a/tests/Unit/Models/Company/GetIdForCurrentUserTest.php b/tests/Unit/Models/Company/GetIdForCurrentUserTest.phpindex d3efcf6813..ae29024a48 100644--- a/tests/Unit/Models/Company/GetIdForCurrentUserTest.php+++ b/tests/Unit/Models/Company/GetIdForCurrentUserTest.php@@ -29,7 +29,8 @@ class GetIdForCurrentUserTest extends TestCase{$this->settings->enableMultipleFullCompanySupport();- $this->actingAs(User::factory()->forCompany(['id' => 2000])->create());+ $company = Company::factory()->create(['id' => 2000]);+ $this->actingAs(User::factory()->forCompany($company)->create());$this->expectException(ValidationException::class);Company::getIdForCurrentUser(1000);}@@ -38,7 +39,7 @@ class GetIdForCurrentUserTest extends TestCase{$this->settings->enableMultipleFullCompanySupport();- $this->actingAs(User::factory()->create(['company_id' => null]));+ $this->actingAs(User::factory()->withoutCompany()->create());$this->assertNull(Company::getIdForCurrentUser(1000));}}