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 get_test() { $startYear = Carbon::parse(now()->subYear())->year; if (is_null(null)) { $end = now()->subYear()->toDateString(); } $endYear = Carbon::parse($end)->year; $aa = OrderCountingRecord::query() ->whereBetween('year', [$startYear, $endYear]) ->where('counting_unit', '月') ->sum('amount'); $this->data['newOrderCountingRecords'] = factory(OrderCountingRecord::class, $this->amount) ->create([ 'date_target' => now()->subYear()->startOfMonth()->toDateString(), 'counting_unit' => '月', 'amount' => 10, 'year' => now()->subYear()->year, ]); $this->service->recordByYear('2020-01-01'); $bb = OrderCountingRecord::query() ->whereBetween('year', [$startYear, $endYear]) ->where('counting_unit', '月') ->sum('amount'); $this->assertEquals($aa+10, $bb); } }