OwnerOutStorageRuleServiceTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace Tests\Services\OwnerOutStorageRuleService;
  3. use App\OwnerOutStorageRule;
  4. use App\OwnerPriceOperation;
  5. use App\Services\OwnerOutStorageRuleService;
  6. use App\Unit;
  7. use Tests\TestCase;
  8. class OwnerOutStorageRuleServiceTest extends TestCase
  9. {
  10. /** @var OwnerOutStorageRuleService */
  11. public $service;
  12. public $data;
  13. protected function setUp(): void
  14. {
  15. parent::setUp();
  16. $this->service = app(OwnerOutStorageRuleService::class);
  17. $this->data["units"] = [];
  18. $unit1 = Unit::query()->where("name","件")->first();
  19. if (!$unit1){
  20. $unit1 = factory(Unit::class)->create([
  21. "name" => "件"
  22. ]);
  23. $this->data["units"][] = $unit1->toArray();
  24. }
  25. $unit2 = Unit::query()->where("name","箱")->first();
  26. if (!$unit2){
  27. $unit2 = factory(Unit::class)->create([
  28. "name" => "箱"
  29. ]);
  30. $this->data["units"][] = $unit2->toArray();
  31. }
  32. $ownerPriceOperation = factory(OwnerPriceOperation::class)->create();
  33. $this->data["ownerPriceOperations"] = [$ownerPriceOperation->toArray()];
  34. $this->data["models"] = [];
  35. $this->data["models"][] = factory(OwnerOutStorageRule::class)->create([
  36. "owner_price_operation_id" => $ownerPriceOperation->id,
  37. "unit_id" => $unit1->id,
  38. ])->toArray();
  39. $this->data["models"][] = factory(OwnerOutStorageRule::class)->create([
  40. "owner_price_operation_id" => $ownerPriceOperation->id,
  41. "unit_id" => $unit2->id,
  42. ])->toArray();
  43. }
  44. /**
  45. * @group customer
  46. */
  47. public function testGet()
  48. {
  49. $models = $this->service->get(["owner_price_operation_id"=>$this->data["ownerPriceOperations"][0]["id"]]);
  50. $this->assertCount(2,$models);
  51. }
  52. /**
  53. * @group customer
  54. */
  55. public function testUpdate()
  56. {
  57. $model = $this->data["models"][0];
  58. $result = $this->service->update(["id"=>$model["id"]],[
  59. "unit_price" => 1.33,
  60. "priority" => 99,
  61. "amount" => 50
  62. ]);
  63. $this->assertEquals(1,$result);
  64. $expected = OwnerOutStorageRule::query()->find($model["id"]);
  65. $this->assertEquals(99,$expected->priority);
  66. $this->assertEquals(1.33,$expected->unit_price);
  67. $this->assertEquals(50,$expected->amount);
  68. }
  69. /**
  70. * @group customer
  71. */
  72. public function testCreate()
  73. {
  74. $model = $this->service->create([
  75. "owner_price_operation_id" => 1, //作业计费ID
  76. "strategy" => "特征", //出库策略
  77. "amount" => 20, //起步数
  78. "unit_id" => 2, //单位ID
  79. "unit_price" => 2, //单价
  80. "feature" => "1&3", //特征
  81. "priority" => 6, //优先级 值越大越高
  82. ]);
  83. $this->assertNotNull($model);
  84. $this->data["models"][] = $model->toArray();
  85. }
  86. /**
  87. * @group customer
  88. */
  89. public function testFindUpdate()
  90. {
  91. $model = OwnerOutStorageRule::query()->find($this->data["models"][0]["id"]);
  92. $result = $this->service->findUpdate($model,[
  93. "unit_price" => 0.566,
  94. ]);
  95. $this->assertEquals(1,$result);
  96. }
  97. /**
  98. * @group customer
  99. */
  100. public function testFind()
  101. {
  102. $models = $this->service->find(array_column($this->data["models"],"id"));
  103. $this->assertCount(2,$models);
  104. }
  105. /**
  106. * @group customer
  107. */
  108. public function testIsExist()
  109. {
  110. $result = $this->service->isExist([
  111. "id" => $this->data["models"][0]["id"],
  112. "owner_price_operation_id" => $this->data["models"][0]["owner_price_operation_id"],
  113. "strategy" => $this->data["models"][0]["strategy"],
  114. ]);
  115. $this->assertGreaterThan(0,$result);
  116. }
  117. public function tearDown(): void
  118. {
  119. Unit::destroy(array_column($this->data["units"],"id"));
  120. OwnerPriceOperation::destroy(array_column($this->data["ownerPriceOperations"],"id"));
  121. OwnerOutStorageRule::destroy(array_column($this->data["models"],"id"));
  122. parent::tearDown();
  123. }
  124. }