withPersonalCompany()->create(); $user->currentCompany->users()->attach( $otherUser = User::factory()->create(), ['role' => 'admin'] ); $this->actingAs($otherUser); $component = Livewire::test(CompanyEmployeeManager::class, ['company' => $user->currentCompany]) ->call('leaveCompany'); $this->assertCount(0, $user->currentCompany->fresh()->users); } public function test_company_owners_cant_leave_their_own_company(): void { $this->actingAs($user = User::factory()->withPersonalCompany()->create()); $component = Livewire::test(CompanyEmployeeManager::class, ['company' => $user->currentCompany]) ->call('leaveCompany') ->assertHasErrors(['company']); $this->assertNotNull($user->currentCompany->fresh()); } }