| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- namespace Tests\Services\OwnerOutStorageRuleService;
- use App\OwnerOutStorageRule;
- use App\OwnerPriceOperation;
- use App\Services\OwnerOutStorageRuleService;
- use App\Unit;
- use Tests\TestCase;
- class OwnerOutStorageRuleServiceTest extends TestCase
- {
- /** @var OwnerOutStorageRuleService */
- public $service;
- public $data;
- protected function setUp(): void
- {
- parent::setUp();
- $this->service = app(OwnerOutStorageRuleService::class);
- $this->data["units"] = [];
- $unit1 = Unit::query()->where("name","件")->first();
- if (!$unit1){
- $unit1 = factory(Unit::class)->create([
- "name" => "件"
- ]);
- $this->data["units"][] = $unit1->toArray();
- }
- $unit2 = Unit::query()->where("name","箱")->first();
- if (!$unit2){
- $unit2 = factory(Unit::class)->create([
- "name" => "箱"
- ]);
- $this->data["units"][] = $unit2->toArray();
- }
- $ownerPriceOperation = factory(OwnerPriceOperation::class)->create();
- $this->data["ownerPriceOperations"] = [$ownerPriceOperation->toArray()];
- $this->data["models"] = [];
- $this->data["models"][] = factory(OwnerOutStorageRule::class)->create([
- "owner_price_operation_id" => $ownerPriceOperation->id,
- "unit_id" => $unit1->id,
- ])->toArray();
- $this->data["models"][] = factory(OwnerOutStorageRule::class)->create([
- "owner_price_operation_id" => $ownerPriceOperation->id,
- "unit_id" => $unit2->id,
- ])->toArray();
- }
- /**
- * @group customer
- */
- public function testGet()
- {
- $models = $this->service->get(["owner_price_operation_id"=>$this->data["ownerPriceOperations"][0]["id"]]);
- $this->assertCount(2,$models);
- }
- /**
- * @group customer
- */
- public function testUpdate()
- {
- $model = $this->data["models"][0];
- $result = $this->service->update(["id"=>$model["id"]],[
- "unit_price" => 1.33,
- "priority" => 99,
- "amount" => 50
- ]);
- $this->assertEquals(1,$result);
- $expected = OwnerOutStorageRule::query()->find($model["id"]);
- $this->assertEquals(99,$expected->priority);
- $this->assertEquals(1.33,$expected->unit_price);
- $this->assertEquals(50,$expected->amount);
- }
- /**
- * @group customer
- */
- public function testCreate()
- {
- $model = $this->service->create([
- "owner_price_operation_id" => 1, //作业计费ID
- "strategy" => "特征", //出库策略
- "amount" => 20, //起步数
- "unit_id" => 2, //单位ID
- "unit_price" => 2, //单价
- "feature" => "1&3", //特征
- "priority" => 6, //优先级 值越大越高
- ]);
- $this->assertNotNull($model);
- $this->data["models"][] = $model->toArray();
- }
- /**
- * @group customer
- */
- public function testFindUpdate()
- {
- $model = OwnerOutStorageRule::query()->find($this->data["models"][0]["id"]);
- $result = $this->service->findUpdate($model,[
- "unit_price" => 0.566,
- ]);
- $this->assertEquals(1,$result);
- }
- /**
- * @group customer
- */
- public function testFind()
- {
- $models = $this->service->find(array_column($this->data["models"],"id"));
- $this->assertCount(2,$models);
- }
- /**
- * @group customer
- */
- public function testIsExist()
- {
- $result = $this->service->isExist([
- "id" => $this->data["models"][0]["id"],
- "owner_price_operation_id" => $this->data["models"][0]["owner_price_operation_id"],
- "strategy" => $this->data["models"][0]["strategy"],
- ]);
- $this->assertGreaterThan(0,$result);
- }
- public function tearDown(): void
- {
- Unit::destroy(array_column($this->data["units"],"id"));
- OwnerPriceOperation::destroy(array_column($this->data["ownerPriceOperations"],"id"));
- OwnerOutStorageRule::destroy(array_column($this->data["models"],"id"));
- parent::tearDown();
- }
- }
|