service = app('OwnerStoreOutFeeReportService'); } public function test_record() { OwnerStoreOutFeeReport::query()->truncate(); OwnerFeeDetail::query()->truncate(); OwnerPriceOperation::query()->truncate(); OwnerStoreOutFeeDetail::query()->truncate(); $ownerFeeDetails = factory(OwnerFeeDetail::class)->times(10)->create(); $ownerPriceOperations = factory(OwnerPriceOperation::class)->times(2)->create(); $ownerStoreOutFeeDetails = []; foreach ($ownerFeeDetails as $ownerFeeDetail) { $id = $ownerPriceOperations->random(1)[0]->id; $ownerStoreOutFeeDetails[] = factory(OwnerStoreOutFeeDetail::class)->create([ 'owner_fee_detail_id' => $ownerFeeDetail->id, 'owner_id' => 8, 'owner_price_operation_id' => $id, ]); $ownerStoreOutFeeDetails[] = factory(OwnerStoreOutFeeDetail::class)->create([ 'owner_fee_detail_id' => $ownerFeeDetail->id, 'owner_id' => 8, 'owner_price_operation_id' => $id, ]); } $this->service->recordReport(); $this->assertEquals(collect($ownerFeeDetails)->sum('work_fee'), OwnerStoreOutFeeReport::query()->sum('fee')); } function tearDown(): void { parent::tearDown(); } }