| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace Tests\Services\OwnerStoreFeeReportService;
- use App\OwnerBillReport;
- use App\OwnerFeeDetail;
- use App\OwnerPriceOperation;
- use App\OwnerStoreFeeDetail;
- use App\Services\OwnerStoreFeeReportService;
- use Tests\TestCase;
- use App\OwnerStoreFeeReport;
- use App\Traits\TestMockSubServices;
- class RecordReportTest extends TestCase
- {
- use TestMockSubServices;
- /** @var OwnerStoreFeeReportService $service */
- public $service;
- private $data;
- private $amount = 2;
- function setUp(): void
- {
- parent::setUp();
- $this->service = app('OwnerStoreFeeReportService');
- }
- public function testReturned()
- {
- OwnerStoreFeeDetail::query()->truncate();
- OwnerStoreFeeReport::query()->truncate();
- $ownerStoreFeeDetail_xx_1_2 = factory(OwnerStoreFeeDetail::class)->times(100)
- ->create([
- 'owner_id' => 8,
- 'work_name' => 'xx入库费',
- 'unit_price' => 1.2,
- 'unit_id' => 1,
- ]);
- $ownerStoreFeeDetail_xx_1_4 = factory(OwnerStoreFeeDetail::class)->times(100)
- ->create([
- 'owner_id' => 8,
- 'work_name' => 'xx入库费',
- 'unit_price' => 1.4,
- 'unit_id' => 1,
- ]);
- $ownerStoreFeeDetail_xx2_1_6 = factory(OwnerStoreFeeDetail::class)->times(100)
- ->create([
- 'owner_id' => 8,
- 'work_name' => 'xx入库费2',
- 'unit_price' => 1.2,
- 'unit_id' => 1,
- ]);
- $this->service->recordReport();
- $report = OwnerStoreFeeReport::query()
- ->where('unit_price', '1.2')
- ->where('owner_id', 8)
- ->where('unit_id', 1)
- ->where('work_name', 'xx入库费')
- ->first();
- $this->assertEquals($ownerStoreFeeDetail_xx_1_2->sum('amount'), $report->amount);
- $this->assertEquals($ownerStoreFeeDetail_xx_1_2->sum('fee'), $report->fee);
- $report = OwnerStoreFeeReport::query()
- ->where('unit_price', '1.4')
- ->where('owner_id', 8)
- ->where('unit_id', 1)
- ->where('work_name', 'xx入库费')
- ->first();
- $this->assertEquals($ownerStoreFeeDetail_xx_1_4->sum('amount'), $report->amount);
- $this->assertEquals($ownerStoreFeeDetail_xx_1_4->sum('fee'), $report->fee);
- $report = OwnerStoreFeeReport::query()
- ->where('unit_price', '1.2')
- ->where('owner_id', 8)
- ->where('unit_id', 1)
- ->where('work_name', 'xx入库费2')
- ->first();
- $this->assertEquals($ownerStoreFeeDetail_xx2_1_6->sum('amount'), $report->amount);
- $this->assertEquals($ownerStoreFeeDetail_xx2_1_6->sum('fee'), $report->fee);
- }
- function tearDown(): void
- {
- OwnerStoreFeeReport::query()
- ->whereIn('id', data_get($this->data['ownerStoreFeeReports'], '*.id') ?? [])
- ->delete();
- parent::tearDown();
- }
- }
|