| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace Tests\Integration;
- use App\Console\Commands\MemberDailyReport;
- use Illuminate\Support\Facades\DB;
- use PHPUnit\Framework\TestCase;
- use Symfony\Component\Console\Input\ArrayInput;
- use Symfony\Component\Console\Output\BufferedOutput;
- use Tests\Support\AgentTestEnvironment;
- /** report:member-daily 补算历史:--from 指定起点、--all 从最早有数据的一天开始;默认 --days 行为不变。今天 2026-09-07。 */
- class MemberDailyReportBackfillTest extends TestCase
- {
- use AgentTestEnvironment;
- private function artisan(array $input): array
- {
- $command = new MemberDailyReport();
- $command->setLaravel($this->app);
- $output = new BufferedOutput();
- $code = $command->run(new ArrayInput($input), $output);
- return [$code, $output->fetch()];
- }
- public function test_backfill_from_a_date_or_all_history(): void
- {
- DB::table('users')->insert(['id' => 1, 'member_id' => 'm1', 'username' => 'm1', 'created_at' => '2026-06-30 09:00:00']);
- foreach (['2026-07-01 10:00:00' => 100, '2026-08-15 10:00:00' => 200, '2026-09-07 10:00:00' => 300] as $at => $amount) {
- DB::table('recharges')->insert(['member_id' => 'm1', 'status' => 1, 'amount' => $amount, 'created_at' => $at]);
- }
- [$code, $out] = $this->artisan(['date' => '2026-08-20', '--from' => '2026-08-10']);
- $this->assertSame(0, $code, $out);
- $this->assertStringContainsString('共 11 天', $out);
- $this->assertSame(['2026-08-15'], DB::table('member_daily_reports')->pluck('report_date')->map(fn ($d) => substr($d, 0, 10))->all());
- [$code, $out] = $this->artisan(['--all' => true]);
- $this->assertSame(0, $code, $out);
- $this->assertStringContainsString('重算 2026-06-30 ~ 2026-09-07,共 70 天', $out);
- $this->assertSame('600.0000', bcadd((string) DB::table('member_daily_reports')->sum('deposit_amount'), '0', 4));
- [$code, $out] = $this->artisan(['date' => '2026-09-07', '--days' => 3]);
- $this->assertSame(0, $code);
- $this->assertSame(3, substr_count($out, '/3] '), 'scheduled --days run unchanged');
- $this->assertStringContainsString('重算 2026-09-05 ~ 2026-09-07', $out);
- [$code] = $this->artisan(['date' => '2026-09-01', '--from' => '2026-09-05']);
- $this->assertSame(1, $code, 'start after end is rejected');
- }
- }
|