Skip to content

Commit f574f3b

Browse files
committed
fix: withIdentities() when user not exists
1 parent 32eb7e7 commit f574f3b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Models/UserModel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ protected function fetchIdentities(array $data): array
7575
? array_column($data, 'id')
7676
: array_column($data['data'], 'id');
7777

78+
if ($userIds === []) {
79+
return $data;
80+
}
81+
7882
/** @var UserIdentityModel $identityModel */
7983
$identityModel = model(UserIdentityModel::class);
8084

tests/Unit/UserTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ public function testModelFindAllWithIdentities(): void
6969
$this->assertCount(2, $identities);
7070
}
7171

72+
public function testModelFindAllWithIdentitiesUserNotExists(): void
73+
{
74+
$users = model(UserModel::class)->where('active', 0)->withIdentities()->findAll();
75+
76+
$this->assertSame([], $users);
77+
}
78+
7279
public function testModelFindByIdWithIdentities(): void
7380
{
7481
fake(UserModel::class);
@@ -81,6 +88,13 @@ public function testModelFindByIdWithIdentities(): void
8188
$this->assertCount(2, $user->identities);
8289
}
8390

91+
public function testModelFindByIdWithIdentitiesUserNotExists(): void
92+
{
93+
$user = model(UserModel::class)->where('active', 0)->withIdentities()->findById(1);
94+
95+
$this->assertNull($user);
96+
}
97+
8498
public function testLastLogin(): void
8599
{
86100
fake(

0 commit comments

Comments
 (0)