| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace Tests\Services;
- use App\OwnerPriceDirectLogistic;
- use App\OwnerPriceDirectLogisticCar;
- use App\Services\OwnerPriceDirectLogisticService;
- use Ramsey\Uuid\Uuid;
- use Tests\TestCase;
- class OwnerPriceDirectLogisticServiceTest extends TestCase
- {
- /** @var OwnerPriceDirectLogisticService */
- public $service;
- public $data;
- protected function setUp(): void
- {
- parent::setUp();
- $this->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();
- }
- }
|