Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 25 additions & 35 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@

class ModelTest extends TestCase
{
public function tearDown(): void
protected function setUp(): void
{
parent::setUp();

Carbon::setTestNow();
}

protected function tearDown(): void
{
Carbon::setTestNow();
DB::connection('mongodb')->getCollection('users')->drop();
Expand Down Expand Up @@ -83,15 +90,22 @@ public function testQualifyColumn(): void
$this->assertEquals('users.name', $sqlUser->qualifyColumn('name'));
}

public function testInsert(): void
private function makeUser(): User
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The helper method makeUser() has private visibility, which prevents subclasses from reusing this factory method. Consider changing it to protected to allow test class inheritance and reuse of the helper.

Suggested change
private function makeUser(): User
protected function makeUser(): User

Copilot uses AI. Check for mistakes.
{
$user = new User();
$user = new User();
$user->name = 'John Doe';
$user->title = 'admin';
$user->age = 35;

$user->save();

return $user;
}

public function testInsert(): void
{
$user = $this->makeUser();
Comment on lines 100 to +107
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The makeUser() method calls save() which performs a database operation. This tightly couples test data creation with persistence. Consider separating concerns by having the method only construct the user object and letting individual tests decide when to save, or alternatively rename to createUser() to better reflect that it persists data.

Suggested change
$user->save();
return $user;
}
public function testInsert(): void
{
$user = $this->makeUser();
return $user;
}
public function testInsert(): void
{
$user = $this->makeUser();
$user->save();

Copilot uses AI. Check for mistakes.

$this->assertTrue($user->exists);
$this->assertEquals(1, User::count());

Expand Down Expand Up @@ -130,11 +144,7 @@ public function testInsertNonIncrementable(): void

public function testUpdate(): void
{
$user = new User();
$user->name = 'John Doe';
$user->title = 'admin';
$user->age = 35;
$user->save();
$user = $this->makeUser();

$raw = $user->getAttributes();
$this->assertInstanceOf(ObjectID::class, $raw['id']);
Expand Down Expand Up @@ -264,11 +274,7 @@ public function testManualIntId(): void

public function testDelete(): void
{
$user = new User();
$user->name = 'John Doe';
$user->title = 'admin';
$user->age = 35;
$user->save();
$user = $this->makeUser();

$this->assertTrue($user->exists);
$this->assertEquals(1, User::count());
Expand All @@ -280,11 +286,7 @@ public function testDelete(): void

public function testAll(): void
{
$user = new User();
$user->name = 'John Doe';
$user->title = 'admin';
$user->age = 35;
$user->save();
$user = $this->makeUser();

$user = new User();
$user->name = 'Jane Doe';
Expand All @@ -301,11 +303,7 @@ public function testAll(): void

public function testFind(): void
{
$user = new User();
$user->name = 'John Doe';
$user->title = 'admin';
$user->age = 35;
$user->save();
$user = $this->makeUser();

$check = User::find($user->id);
$this->assertInstanceOf(User::class, $check);
Expand Down Expand Up @@ -384,11 +382,7 @@ public function testCreate(): void

public function testDestroy(): void
{
$user = new User();
$user->name = 'John Doe';
$user->title = 'admin';
$user->age = 35;
$user->save();
$user = $this->makeUser();

User::destroy((string) $user->id);

Expand All @@ -397,11 +391,7 @@ public function testDestroy(): void

public function testTouch(): void
{
$user = new User();
$user->name = 'John Doe';
$user->title = 'admin';
$user->age = 35;
$user->save();
$user = $this->makeUser();

$old = $user->updated_at;
sleep(1);
Expand Down Expand Up @@ -1089,7 +1079,7 @@ public function testChunkById(): void
$this->assertEquals(['fork', 'spork', 'spoon'], $names);
}

public function testTruncateModel()
public function testTruncateModel(): void
{
User::create(['name' => 'John Doe']);

Expand All @@ -1098,7 +1088,7 @@ public function testTruncateModel()
$this->assertEquals(0, User::count());
}

public function testGuardedModel()
public function testGuardedModel(): void
{
$model = new Guarded();

Expand Down
Loading