| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace Tests\Services\BatchService;
- use App\Order;
- use App\OrderCommodity;
- use App\Services\BatchService;
- use App\Station;
- use App\StationRuleBatch;
- use Tests\TestCase;
- use App\Batch;
- use App\Traits\TestMockSubServices;
- class AssignTasksTest extends TestCase
- {
- use TestMockSubServices;
- /** @var BatchService $service */
- public $service;
- private $data;
- private $batchAmount=2;
- private $orderAmount=4;
- private $orderCommodityAmount=8;
- function setUp(): void
- {
- parent::setUp();
- $this->service = app('BatchService');
- $this->data['batches']
- = factory(Batch::class, $this->batchAmount)
- ->create();
- $this->data['orders'] =
- factory(Order::class)
- ->createMany($this->makeArray($this->orderAmount,[
- 'status'=>'未处理',
- 'batch_id' => function(){return $this->getTargetIdCirculately($this->data['batches']);}
- ]));
- $this->data['orderCommodities'] =
- factory(OrderCommodity::class)
- ->createMany($this->makeArray($this->orderCommodityAmount,[
- 'order_id' => function(){return $this->getTargetIdCirculately($this->data['orders']);}
- ]));
- $this->data['station_rule_batches']
- = factory(StationRuleBatch::class)
- ->createMany($this->makeArray($this->batchAmount,[
- 'owner_id' => function(){return $this->getTargetIdCirculately($this->data['batches'],'','owner_id');}
- ]));
- }
- public function testReturned()
- {
- $this->service->assignTasks($this->data['batches']);
- $this->data['batches']['0']->loadMissing('stationBatchTask.stationTask');
- $a=($this->data['batches']['0']['stationBatchTask']);
- dd($a);
- $this->assertEquals(data_get($this->data['batches'],'*.id'),$this->data['batches']);
- }
- function tearDown(): void
- {
- Batch::query()
- ->whereIn('id',data_get($this->data['batches'],'*.id')??[])
- ->delete();
- Order::query()
- ->whereIn('id',data_get($this->data['orders'],'*.id')??[])
- ->delete();
- OrderCommodity::query()
- ->whereIn('id',data_get($this->data['orderCommodities'],'*.id')??[])
- ->delete();
- StationRuleBatch::query()
- ->whereIn('id',data_get($this->data['station_rule_batches'],'*.id')??[])
- ->delete();
- parent::tearDown();
- }
- }
|