create(); $otherUser = User::factory()->create(); $fromUser = User::factory()->create(); $toUser = User::factory()->create(); TimeEntry::factory()->forOrganization($organization)->forUser($otherUser)->createMany(3); TimeEntry::factory()->forOrganization($organization)->forUser($fromUser)->createMany(3); // Act $userService = app(UserService::class); $userService->assignOrganizationEntitiesToDifferentUser($organization, $fromUser, $toUser); // Assert $this->assertSame(3, TimeEntry::query()->whereBelongsTo($toUser, 'user')->count()); $this->assertSame(3, TimeEntry::query()->whereBelongsTo($otherUser, 'user')->count()); $this->assertSame(0, TimeEntry::query()->whereBelongsTo($fromUser, 'user')->count()); } }