public function testAddScopeAndSearch() { $authorId = 1; $postRepo = new PostRepository(); $posts = $postRepo->scope(function ($query) use($authorId) { $query->where('author_id', '=', $authorId); })->all(); $this->assertTrue(count($posts) == $this->postByAuthor); $this->assertTrue($posts[0]->author_id == $authorId); }