| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace Tests\Services\NewOrderCountingRecordService;
- use App\Services\NewOrderCountingRecordService;
- use Carbon\Carbon;
- use Tests\TestCase;
- use App\OrderCountingRecord;
- use App\Traits\TestMockSubServices;
- class RecordByYearTest extends TestCase
- {
- use TestMockSubServices;
- /** @var NewOrderCountingRecordService $service */
- public $service;
- private $data;
- private $amount = 1;
- 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 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);
- }
- }
|