service = app(OwnerBillReportService::class); $userOwnerGroup = factory(\App\UserOwnerGroup::class)->create(); $owner = factory(\App\Owner::class)->create([ "user_owner_group_id"=>$userOwnerGroup->id, ]); $this->data["owners"] = [$owner->toArray()]; $this->data["userOwnerGroups"] = [$userOwnerGroup->toArray()]; $this->data["models"] = factory(OwnerBillReport::class,3)->create([ "owner_id" => $owner->id, ])->toArray(); } /** * @group customer */ public function testPaginate() { $models = $this->service->paginate(array("paginate"=>5)); $this->assertGreaterThanOrEqual(3,count($models)); $this->assertLessThanOrEqual(5,count($models)); } /** * @group customer */ public function testUpdate(){ $model = $this->data["models"][0]; $result = $this->service->update(["id"=>$model["id"]],[ "difference" => 1000, ]); $this->assertEquals(1,$result); $bill = OwnerBillReport::query()->find($model["id"]); $this->assertNotNull($bill); $this->assertEquals(1000,$bill->difference); } /** * @group customer */ public function testGet(){ $ids = implode(",",array_column($this->data["models"],"owner_id")); $models = $this->service->get(["owner_id"=>$ids]); $this->assertGreaterThanOrEqual(3,count($models)); } protected function tearDown(): void { UserOwnerGroup::destroy(array_column($this->data["userOwnerGroups"],"id")); Owner::destroy(array_column($this->data["owners"],"id")); OwnerBillReport::destroy(array_column($this->data["models"],"id")); parent::tearDown(); } }