0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

備忘録:Laravel 単体テスト

Last updated at Posted at 2025-10-30

Modelsでテストしたい内容

・意図する返却値であるか
・意図するクエリであるか
・意図するEagerLoadであるか

class test(int $id, string $query, array $eagerLoads): void
{
    // Models層で作成したBuilderを取得
    $builder = Post::getPostData($id);
    
    // 意図する返却値であるか
    $this->assertInstanceOf(Builder::class, $builder);
    
    // 意図するクエリであるか
    $this->assertEquals($query, $builder->toSql());
    $this->assertEquals([$id], $actual->getBindings());
    
    // 意図するEagerLoadであるか
    $this->assertEquals($eagerLoads, array_keys($actual->getEagerLoads()));
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?