createApplication(); $this->content = App::make(Content::class); // create new rows $this->user = factory(User::class)->create(); $this->parentPage = factory(ContentModel::class)->create(['userId' => $this->user->id]); factory(ContentModel::class, 4)->create(['userId' => $this->user->id]); factory(ContentModel::class, 5)->create([ 'userId' => $this->user->id, 'parentId' => $this->parentPage->id ]); } public function testSubpages() { $subpages = $this->parentPage->subpages; $this->assertTrue($subpages instanceof Collection); $this->assertCount(5, $subpages); } function __destruct() { // clean tables ContentModel::getQuery() ->delete(); } }