RecordByYearTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace Tests\Services\NewOrderCountingRecordService;
  3. use App\Services\NewOrderCountingRecordService;
  4. use Carbon\Carbon;
  5. use Tests\TestCase;
  6. use App\OrderCountingRecord;
  7. use App\Traits\TestMockSubServices;
  8. class RecordByYearTest extends TestCase
  9. {
  10. use TestMockSubServices;
  11. /** @var NewOrderCountingRecordService $service */
  12. public $service;
  13. private $data;
  14. private $amount = 1;
  15. function setUp(): void
  16. {
  17. parent::setUp();
  18. $this->service = app('NewOrderCountingRecordService');
  19. // $this->data['newOrderCountingRecords']
  20. // = factory(OrderCountingRecord::class, $this->amount)
  21. // ->create();
  22. }
  23. public function testReturned()
  24. {
  25. $this->assertTrue(true);
  26. }
  27. function tearDown(): void
  28. {
  29. OrderCountingRecord::query()
  30. ->whereIn('id', data_get($this->data['newOrderCountingRecords'], '*.id') ?? [])
  31. ->delete();
  32. parent::tearDown();
  33. }
  34. /**
  35. * @test
  36. */
  37. // public function get_test()
  38. // {
  39. // $startYear = Carbon::parse(now()->subYear())->year;
  40. // if (is_null(null)) {
  41. // $end = now()->subYear()->toDateString();
  42. // }
  43. //
  44. // $endYear = Carbon::parse($end)->year;
  45. // $aa = OrderCountingRecord::query()
  46. // ->whereBetween('year', [$startYear, $endYear])
  47. // ->where('counting_unit', '月')
  48. // ->sum('amount');
  49. //
  50. // $this->data['newOrderCountingRecords']
  51. // = factory(OrderCountingRecord::class, $this->amount)
  52. // ->create([
  53. // 'date_target' => now()->subYear()->startOfMonth()->toDateString(),
  54. // 'counting_unit' => '月',
  55. // 'amount' => 10,
  56. // 'year' => now()->subYear()->year,
  57. // ]);
  58. // $this->service->recordByYear('2020-01-01');
  59. // $bb = OrderCountingRecord::query()
  60. // ->whereBetween('year', [$startYear, $endYear])
  61. // ->where('counting_unit', '月')
  62. // ->sum('amount');
  63. // $this->assertEquals($aa+10, $bb);
  64. // }
  65. }