|
|
@@ -0,0 +1,71 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Tests\Services\StationTaskMaterialBoxService;
|
|
|
+use App\Batch;
|
|
|
+use App\Order;
|
|
|
+use App\OrderCommodity;
|
|
|
+use App\Services\StationTaskMaterialBoxService;
|
|
|
+use Tests\TestCase;
|
|
|
+use App\StationTaskMaterialBox;
|
|
|
+use App\Traits\TestMockSubServices;
|
|
|
+
|
|
|
+class CreateByBatchesTest extends TestCase
|
|
|
+{
|
|
|
+ use TestMockSubServices;
|
|
|
+ /** @var StationTaskMaterialBoxService $service */
|
|
|
+ public $service;
|
|
|
+ private $data;
|
|
|
+ private $batchAmount=2;
|
|
|
+ private $orderAmount=2;
|
|
|
+ private $materialBoxAmount=2;
|
|
|
+ function setUp(): void
|
|
|
+ {
|
|
|
+ parent::setUp();
|
|
|
+ $this->service = app('StationTaskMaterialBoxService');
|
|
|
+ $this->data['batches']
|
|
|
+ = factory(Batch::class, $this->batchAmount)
|
|
|
+ ->create();
|
|
|
+ $this->data['orders']
|
|
|
+ = factory(Order::class, $this->orderAmount)
|
|
|
+ ->create([
|
|
|
+ 'batch_id'=>(function(){
|
|
|
+ if(!isset($this->data['i_batch_id_orders'])){
|
|
|
+ $this->data['i_batch_id_orders']=$this->batchAmount;
|
|
|
+ }
|
|
|
+ $this->data['i_batch_id_orders']++;
|
|
|
+ if($this->data['i_batch_id_orders']>=$this->batchAmount)$this->data['i_batch_id_orders']=0;
|
|
|
+ return $this->data['batches'][$this->data['i_batch_id_orders']];
|
|
|
+ })()
|
|
|
+ ]);
|
|
|
+ $this->data['stationTaskMaterialBoxes']
|
|
|
+ = factory(StationTaskMaterialBox::class, $this->materialBoxAmount)
|
|
|
+ ->create();
|
|
|
+ $this->data['orderCommodities']
|
|
|
+ = factory(OrderCommodity::class, $this->materialBoxAmount)
|
|
|
+ ->create([
|
|
|
+ 'order_id'=>(function(){
|
|
|
+ if(!isset($this->data['i_order_id_orderCommodities'])){
|
|
|
+ $this->data['i_order_id_orderCommodities']=$this->batchAmount;
|
|
|
+ }
|
|
|
+ $this->data['i_order_id_orderCommodities']++;
|
|
|
+ if($this->data['i_order_id_orderCommodities']>=$this->batchAmount)$this->data['i_order_id_orderCommodities']=0;
|
|
|
+ return $this->data['orders'][$this->data['i_order_id_orderCommodities']];
|
|
|
+ })(),
|
|
|
+ 'location'=>
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testReturned()
|
|
|
+ {
|
|
|
+ $this->service->createByBatches();
|
|
|
+ $this->assertTrue(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ function tearDown(): void
|
|
|
+ {
|
|
|
+ StationTaskMaterialBox::query()
|
|
|
+ ->whereIn('id',data_get($this->data['stationTaskMaterialBoxes'],'*.id')??[])
|
|
|
+ ->delete();
|
|
|
+ parent::tearDown();
|
|
|
+ }
|
|
|
+}
|