Skip to content

Commit

Permalink
chore: test firstOrCreate method for the model (#2399)
Browse files Browse the repository at this point in the history
  • Loading branch information
abolfazl-rasoli authored Nov 4, 2022
1 parent 61cc6ed commit 42e0100
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,4 +768,23 @@ public function testGuardedModel()
$model->fill(['level1' => $dataValues]);
$this->assertEquals($dataValues, $model->getAttribute('level1'));
}

public function testFirstOrCreate(): void
{
$name = 'Jane Poe';

/** @var User $user */
$user = User::where('name', $name)->first();
$this->assertNull($user);

/** @var User $user */
$user = User::firstOrCreate(compact('name'));
$this->assertInstanceOf(Model::class, $user);
$this->assertTrue($user->exists);
$this->assertEquals($name, $user->name);

/** @var User $check */
$check = User::where('name', $name)->first();
$this->assertEquals($user->_id, $check->_id);
}
}

0 comments on commit 42e0100

Please sign in to comment.