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(); } }