RecordReportTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Tests\Services\OwnerStoreFeeReportService;
  3. use App\OwnerBillReport;
  4. use App\OwnerFeeDetail;
  5. use App\OwnerPriceOperation;
  6. use App\OwnerStoreFeeDetail;
  7. use App\Services\OwnerStoreFeeReportService;
  8. use Tests\TestCase;
  9. use App\OwnerStoreFeeReport;
  10. use App\Traits\TestMockSubServices;
  11. class RecordReportTest extends TestCase
  12. {
  13. use TestMockSubServices;
  14. /** @var OwnerStoreFeeReportService $service */
  15. public $service;
  16. private $data;
  17. private $amount = 2;
  18. function setUp(): void
  19. {
  20. parent::setUp();
  21. $this->service = app('OwnerStoreFeeReportService');
  22. }
  23. public function testReturned()
  24. {
  25. OwnerStoreFeeDetail::query()->truncate();
  26. OwnerStoreFeeReport::query()->truncate();
  27. $ownerStoreFeeDetail_xx_1_2 = factory(OwnerStoreFeeDetail::class)->times(100)
  28. ->create([
  29. 'owner_id' => 8,
  30. 'work_name' => 'xx入库费',
  31. 'unit_price' => 1.2,
  32. 'unit_id' => 1,
  33. ]);
  34. $ownerStoreFeeDetail_xx_1_4 = factory(OwnerStoreFeeDetail::class)->times(100)
  35. ->create([
  36. 'owner_id' => 8,
  37. 'work_name' => 'xx入库费',
  38. 'unit_price' => 1.4,
  39. 'unit_id' => 1,
  40. ]);
  41. $ownerStoreFeeDetail_xx2_1_6 = factory(OwnerStoreFeeDetail::class)->times(100)
  42. ->create([
  43. 'owner_id' => 8,
  44. 'work_name' => 'xx入库费2',
  45. 'unit_price' => 1.2,
  46. 'unit_id' => 1,
  47. ]);
  48. $this->service->recordReport();
  49. $report = OwnerStoreFeeReport::query()
  50. ->where('unit_price', '1.2')
  51. ->where('owner_id', 8)
  52. ->where('unit_id', 1)
  53. ->where('work_name', 'xx入库费')
  54. ->first();
  55. $this->assertEquals($ownerStoreFeeDetail_xx_1_2->sum('amount'), $report->amount);
  56. $this->assertEquals($ownerStoreFeeDetail_xx_1_2->sum('fee'), $report->fee);
  57. $report = OwnerStoreFeeReport::query()
  58. ->where('unit_price', '1.4')
  59. ->where('owner_id', 8)
  60. ->where('unit_id', 1)
  61. ->where('work_name', 'xx入库费')
  62. ->first();
  63. $this->assertEquals($ownerStoreFeeDetail_xx_1_4->sum('amount'), $report->amount);
  64. $this->assertEquals($ownerStoreFeeDetail_xx_1_4->sum('fee'), $report->fee);
  65. $report = OwnerStoreFeeReport::query()
  66. ->where('unit_price', '1.2')
  67. ->where('owner_id', 8)
  68. ->where('unit_id', 1)
  69. ->where('work_name', 'xx入库费2')
  70. ->first();
  71. $this->assertEquals($ownerStoreFeeDetail_xx2_1_6->sum('amount'), $report->amount);
  72. $this->assertEquals($ownerStoreFeeDetail_xx2_1_6->sum('fee'), $report->fee);
  73. }
  74. function tearDown(): void
  75. {
  76. OwnerStoreFeeReport::query()
  77. ->whereIn('id', data_get($this->data['ownerStoreFeeReports'], '*.id') ?? [])
  78. ->delete();
  79. parent::tearDown();
  80. }
  81. }