flush(); $this->newOrderCountingRecordService = new NewOrderCountingRecordService(); $user = User::query()->where('name', 'yang')->first(); $this->actingAs($user); $owners = factory(Owner::class)->times(2)->create(); $this->ownerIds = array_column($owners->toArray(), 'id'); $this->queryConditionDay = $this->newOrderCountingRecordService->transfersToCondition(Carbon::now()->subDays($this->step_length)->toDateString(), Carbon::now()->toDateString(), '日', $this->ownerIds); $this->queryConditionMonth = $this->newOrderCountingRecordService->transfersToCondition(Carbon::now()->subMonths($this->step_length)->toDateString(), Carbon::now()->toDateString(), '月', $this->ownerIds); $this->queryConditionYear = $this->newOrderCountingRecordService->transfersToCondition(Carbon::now()->subYears($this->step_length)->toDateString(), Carbon::now()->toDateString(), '年', $this->ownerIds); } protected function tearDown(): void { cache()->flush(); Owner::destroy($this->ownerIds); orderCountingRecord::destroy($this->orderCountingRecordIds); parent::tearDown(); } /** * @test */ public function unit_day() { for ($i = 0; $i <= $this->step_length; $i++) { foreach ($this->ownerIds as $ownerId) { $dateStr = Carbon::now()->subDays($i)->toDateTimeString(); $order = factory(Order::class)->create([ 'created_at' => $dateStr, 'owner_id' => $ownerId, 'wms_status' => '订单完成' ]); $this->orderIds = $order->id; } } $start = Carbon::now()->subDays($this->step_length)->toDateString(); $end = Carbon::now()->toDateString(); $result = $this->newOrderCountingRecordService->orderCountingRecords($start, $end, '日', $this->ownerIds); $this->assertEquals([2,2],$result->pluck('counter')->toArray()); } }