Skip to content

Commit 691a59f

Browse files
committed
fix: remove logic to set user id in the passed User object
Modifying the object gives the false impression of database equivalency. We have no created/updated timestamps, or other fields coming from the database, or effects of stored procedures and field defaults.
1 parent 0a7a40e commit 691a59f

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/Models/UserModel.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,6 @@ public function insert($data = null, bool $returnID = true)
232232

233233
$this->checkQueryReturn($result);
234234

235-
// Set user id to the passed User object.
236-
if ($data instanceof User) {
237-
$data->id = $this->insertID;
238-
}
239-
240235
return $returnID ? $this->insertID : $result;
241236
}
242237

tests/Unit/UserModelTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Tests\Unit;
66

77
use CodeIgniter\Shield\Entities\User;
8+
use CodeIgniter\Shield\Exceptions\LogicException;
89
use CodeIgniter\Shield\Models\UserModel;
910
use CodeIgniter\Test\DatabaseTestTrait;
1011
use Tests\Support\TestCase;
@@ -67,14 +68,15 @@ public function testInsertUserObject(): void
6768
*/
6869
public function testSaveNewUserAndGetEmailIdentity(): void
6970
{
71+
$this->expectException(LogicException::class);
72+
$this->expectExceptionMessage('"$user->id" is null. You should not use the incomplete User object.');
73+
7074
$users = $this->createUserModel();
7175
$user = $this->createNewUser();
7276

7377
$users->save($user);
7478

75-
$identity = $user->getEmailIdentity();
76-
77-
$this->assertSame('foo@bar.com', $identity->secret);
79+
$user->getEmailIdentity();
7880
}
7981

8082
/**

0 commit comments

Comments
 (0)