RecordReportTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Tests\Services\OwnerStoreOutFeeReportService;
  3. use App\OwnerBillReport;
  4. use App\OwnerFeeDetail;
  5. use App\OwnerPriceOperation;
  6. use App\OwnerStoreFeeDetail;
  7. use App\OwnerStoreFeeReport;
  8. use App\OwnerStoreOutFeeDetail;
  9. use App\Services\OwnerStoreOutFeeReportService;
  10. use Tests\TestCase;
  11. use App\OwnerStoreOutFeeReport;
  12. use App\Traits\TestMockSubServices;
  13. class RecordReportTest extends TestCase
  14. {
  15. use TestMockSubServices;
  16. /** @var OwnerStoreOutFeeReportService $service */
  17. public $service;
  18. private $data;
  19. private $amount = 2;
  20. function setUp(): void
  21. {
  22. parent::setUp();
  23. $this->service = app('OwnerStoreOutFeeReportService');
  24. }
  25. public function test_record()
  26. {
  27. OwnerStoreOutFeeReport::query()->truncate();
  28. OwnerFeeDetail::query()->truncate();
  29. OwnerPriceOperation::query()->truncate();
  30. OwnerStoreOutFeeDetail::query()->truncate();
  31. $ownerFeeDetails = factory(OwnerFeeDetail::class)->times(10)->create();
  32. $ownerPriceOperations = factory(OwnerPriceOperation::class)->times(2)->create();
  33. $ownerStoreOutFeeDetails = [];
  34. foreach ($ownerFeeDetails as $ownerFeeDetail) {
  35. $id = $ownerPriceOperations->random(1)[0]->id;
  36. $ownerStoreOutFeeDetails[] = factory(OwnerStoreOutFeeDetail::class)->create([
  37. 'owner_fee_detail_id' => $ownerFeeDetail->id,
  38. 'owner_id' => 8,
  39. 'owner_price_operation_id' => $id,
  40. ]);
  41. $ownerStoreOutFeeDetails[] = factory(OwnerStoreOutFeeDetail::class)->create([
  42. 'owner_fee_detail_id' => $ownerFeeDetail->id,
  43. 'owner_id' => 8,
  44. 'owner_price_operation_id' => $id,
  45. ]);
  46. }
  47. $this->service->recordReport();
  48. $this->assertEquals(collect($ownerFeeDetails)->sum('work_fee'), OwnerStoreOutFeeReport::query()->sum('fee'));
  49. }
  50. function tearDown(): void
  51. {
  52. parent::tearDown();
  53. }
  54. }