OwnerStoragePriceModelServiceTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Tests\Services\OwnerStoragePriceModelService;
  3. use App\Owner;
  4. use App\OwnerReport;
  5. use App\OwnerStoragePriceModel;
  6. use App\Services\OwnerStoragePriceModelService;
  7. use Tests\TestCase;
  8. class OwnerStoragePriceModelServiceTest extends TestCase
  9. {
  10. /** @var OwnerStoragePriceModelService */
  11. public $service;
  12. public $data;
  13. protected function setUp(): void
  14. {
  15. parent::setUp();
  16. $this->service = app(OwnerStoragePriceModelService::class);
  17. $this->data["models"] = [
  18. factory(OwnerStoragePriceModel::class)->create([
  19. "minimum_area" => 600, //最低起租面积
  20. "price" => 80.4, //单价
  21. "discount_type" => "按单减免", //减免类型
  22. "discount_value" => 0.1, //减免值
  23. "unit_id" => 1, //单位ID
  24. ])->toArray(),
  25. factory(OwnerStoragePriceModel::class)->create([
  26. "minimum_area" => 600, //最低起租面积
  27. "price" => 80.4, //单价
  28. "discount_type" => "固定减免", //减免类型
  29. "discount_value" => 3.6, //减免值
  30. "unit_id" => 1, //单位ID
  31. ])->toArray(),
  32. ];
  33. $this->data["owners"] = [
  34. factory(Owner::class)->create(["user_owner_group_id"=>1])->toArray()
  35. ];
  36. $this->data["reports"] = [
  37. factory(OwnerReport::class)->create([
  38. "owner_id" => $this->data["owners"][0]["id"],
  39. "owner_bill_report_id" =>1,
  40. "total" => 1587,
  41. "counting_month" => "2020-10-10"
  42. ])->toArray()
  43. ];
  44. }
  45. /**
  46. * @group customer
  47. */
  48. public function testCalculationAmount()
  49. {
  50. $model = OwnerStoragePriceModel::query()->find($this->data["models"][0]["id"]);
  51. $result = $this->service->calculationAmount($model,548.98,$this->data["owners"][0]["id"],"2020-10-10");
  52. $this->assertEquals(48081.3,$result);
  53. $model = OwnerStoragePriceModel::query()->find($this->data["models"][1]["id"]);
  54. $result = $this->service->calculationAmount($model,548.98,$this->data["owners"][0]["id"],"2020-10-10");
  55. $this->assertEquals(48236.4,$result);
  56. }
  57. public function tearDown(): void
  58. {
  59. OwnerStoragePriceModel::destroy(array_column($this->data["models"],"id"));
  60. Owner::destroy(array_column($this->data["owners"],"id"));
  61. OwnerReport::destroy(array_column($this->data["reports"],"id"));
  62. parent::tearDown();
  63. }
  64. }