Skip to content

Commit

Permalink
test: add test case for loadCount()
Browse files Browse the repository at this point in the history
relates to #45
  • Loading branch information
marijoo committed Sep 12, 2024
1 parent c9fa20a commit fc9ad6d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/HasMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1286,3 +1286,14 @@
expect($post->user)->toBeInstanceOf(User::class);
expect($post->relationLoaded('meta'))->toBeFalse();
});

it('works when using loadCount', function () {
$user = User::factory()->create();
Post::factory()->for($user)->count(3)->create();

expect($user->posts_count)->toBeNull();

$user->loadCount('posts');

expect($user->posts_count)->toBe(3);
});
5 changes: 5 additions & 0 deletions tests/Mocks/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ class User extends Model
use HasFactory;

protected $table = 'users';

public function posts()
{
return $this->hasMany(Post::class);
}
}

0 comments on commit fc9ad6d

Please sign in to comment.