| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace Tests\Services\NewOrderCountingRecordService;
- use App\Services\NewOrderCountingRecordService;
- use Carbon\Carbon;
- use Tests\TestCase;
- use App\OrderCountingRecord;
- use App\Traits\TestMockSubServices;
- class RecordOrderDayTest extends TestCase
- {
- use TestMockSubServices;
- /** @var NewOrderCountingRecordService $service */
- public $service;
- private $data;
- private $amount=2;
- function setUp(): void
- {
- parent::setUp();
- $this->service = app('NewOrderCountingRecordService');
- // $this->data['newOrderCountingRecords']
- // = factory(OrderCountingRecord::class, $this->amount)
- // ->create();
- }
- public function testReturned()
- {
- $this->assertTrue(true);
- }
- function tearDown(): void
- {
- OrderCountingRecord::query()
- ->whereIn('id',data_get($this->data['newOrderCountingRecords'],'*.id')??[])
- ->delete();
- parent::tearDown();
- }
- /**
- * @test
- */
- public function record_test()
- {
- $start = '2021-05-14';
- $end = '2021-06-08';
- $this->service->recordByDay($start, $end, '日');
- $startDateTime = Carbon::parse($start)->startOfDay()->toDateTimeString();
- $endDateTime = now()->subDay()->endOfDay()->toDateTimeString();
- $orderCount = \App\Order::query()
- ->whereBetween('created_at', [$startDateTime, $endDateTime])
- ->where('wms_status', '订单完成')
- ->count();
- //TODO 只能使用Date!!!!
- $sum = OrderCountingRecord::query()
- ->whereBetween('date_target', [Carbon::parse($startDateTime)->toDateString(), Carbon::parse($endDateTime)->toDateString()])
- ->sum('amount');
- $this->assertEquals($sum,
- $orderCount);
- }
- }
|