OwnerPriceDirectLogisticServiceTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Tests\Services;
  3. use App\OwnerPriceDirectLogistic;
  4. use App\OwnerPriceDirectLogisticCar;
  5. use App\Services\OwnerPriceDirectLogisticService;
  6. use Ramsey\Uuid\Uuid;
  7. use Tests\TestCase;
  8. class OwnerPriceDirectLogisticServiceTest extends TestCase
  9. {
  10. /** @var OwnerPriceDirectLogisticService */
  11. public $service;
  12. public $data;
  13. protected function setUp(): void
  14. {
  15. parent::setUp();
  16. $this->service = app(OwnerPriceDirectLogisticService::class);
  17. $this->data["models"] = factory(OwnerPriceDirectLogistic::class,3)->create()->toArray();
  18. }
  19. public function testPaginate()
  20. {
  21. $models = $this->service->paginate();
  22. $this->assertGreaterThanOrEqual(3,count($models));
  23. $this->assertLessThanOrEqual(50,count($models));
  24. $models = $this->service->paginate($this->data["models"][0]["id"]);
  25. $this->assertCount(1,$models);
  26. }
  27. public function testCreate()
  28. {
  29. $model = $this->service->create([
  30. "name" => Uuid::uuid1(),
  31. "base_km" => 3
  32. ]);
  33. $this->assertNotNull($model);
  34. $this->data["models"][] = $model->toArray();
  35. }
  36. public function testDestroy()
  37. {
  38. $result = $this->service->destroy(array_column($this->data["models"],"id"));
  39. $this->assertEquals(3,$result);
  40. $this->data["models"] = [];
  41. }
  42. public function testFind()
  43. {
  44. $model = $this->service->find($this->data["models"][0]["id"]);
  45. $this->assertNotNull($model);
  46. }
  47. public function testUpdate()
  48. {
  49. $id = $this->data["models"][0]["id"];
  50. $result = $this->service->update(["id"=>$id],[
  51. "base_km" => 3
  52. ]);
  53. $this->assertEquals(1,$result);
  54. $model = OwnerPriceDirectLogistic::query()->find($id);
  55. $this->assertEquals(3,$model->base_km);
  56. }
  57. public function testUpdateDetail()
  58. {
  59. OwnerPriceDirectLogisticCar::query()->create([
  60. "owner_price_direct_logistic_id" => $this->data["models"][0]["id"], //直发车计费ID
  61. "car_type_id", //车型ID
  62. "base_fee", //起步费
  63. "additional_fee", //续费(元/KM)
  64. ]);
  65. }
  66. public function tearDown(): void
  67. {
  68. OwnerPriceDirectLogistic::destroy(array_column($this->data["models"],"id"));
  69. parent::tearDown();
  70. }
  71. }