service = app(OwnerPriceDirectLogisticService::class); $this->data["models"] = factory(OwnerPriceDirectLogistic::class,3)->create()->toArray(); } public function testPaginate() { $models = $this->service->paginate(); $this->assertGreaterThanOrEqual(3,count($models)); $this->assertLessThanOrEqual(50,count($models)); $models = $this->service->paginate($this->data["models"][0]["id"]); $this->assertCount(1,$models); } public function testCreate() { $model = $this->service->create([ "name" => Uuid::uuid1(), "base_km" => 3 ]); $this->assertNotNull($model); $this->data["models"][] = $model->toArray(); } public function testDestroy() { $result = $this->service->destroy(array_column($this->data["models"],"id")); $this->assertEquals(3,$result); $this->data["models"] = []; } public function testFind() { $model = $this->service->find($this->data["models"][0]["id"]); $this->assertNotNull($model); } public function testUpdate() { $id = $this->data["models"][0]["id"]; $result = $this->service->update(["id"=>$id],[ "base_km" => 3 ]); $this->assertEquals(1,$result); $model = OwnerPriceDirectLogistic::query()->find($id); $this->assertEquals(3,$model->base_km); } public function testUpdateDetail() { OwnerPriceDirectLogisticCar::query()->create([ "owner_price_direct_logistic_id" => $this->data["models"][0]["id"], //直发车计费ID "car_type_id", //车型ID "base_fee", //起步费 "additional_fee", //续费(元/KM) ]); } public function tearDown(): void { OwnerPriceDirectLogistic::destroy(array_column($this->data["models"],"id")); parent::tearDown(); } }