| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace Tests\Services\OwnerStoragePriceModelService;
- use App\Owner;
- use App\OwnerReport;
- use App\OwnerStoragePriceModel;
- use App\Services\OwnerStoragePriceModelService;
- use App\TaxRate;
- use App\Unit;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\DB;
- use Tests\TestCase;
- class OwnerStoragePriceModelServiceTest extends TestCase
- {
- /** @var OwnerStoragePriceModelService */
- public $service;
- public $data;
- protected function setUp(): void
- {
- parent::setUp();
- $this->service = app(OwnerStoragePriceModelService::class);
- $unit = Unit::query()->where("name","月")->first();
- $units = [];
- if (!$unit){
- $unit = Unit::query()->create([
- "name" => "月",
- "code" => "月"
- ]);
- $units[] = $unit;
- }
- $this->data["units"] = $units;
- // $this->data['taxRate']=factory(TaxRate::class)->create(['value'=>2]);
- $this->data['taxRate']=$res = DB::insert('insert ignore into tax_rates (value) values(2)');
- $this->data["models"] = [
- factory(OwnerStoragePriceModel::class)->create([
- "minimum_area" => 600, //最低起租面积
- "price" => 80.4, //单价
- "discount_type" => "按单减免", //减免类型
- "discount_value" => 0.1, //减免值
- "unit_id" => 1, //单位ID
- "time_unit_id" => $unit->id, //单位ID
- "tax_rate_id" => $this->data['taxRate']['id'],
- ])->toArray(),
- factory(OwnerStoragePriceModel::class)->create([
- "minimum_area" => 600, //最低起租面积
- "price" => 80.4, //单价
- "discount_type" => "固定减免", //减免类型
- "discount_value" => 3.6, //减免值
- "unit_id" => 1, //单位ID
- "time_unit_id" => $unit->id, //计时单位ID
- "tax_rate_id" => $this->data['taxRate']['id'],
- ])->toArray(),
- ];
- $this->data["owners"] = [
- factory(Owner::class)->create(["user_owner_group_id"=>1])->toArray()
- ];
- $this->data["reports"] = [
- factory(OwnerReport::class)->create([
- "owner_id" => $this->data["owners"][0]["id"],
- "owner_bill_report_id" =>1,
- "counting_month" => "2020-10-10"
- ])->toArray()
- ];
- }
- /**
- * @group customer
- */
- public function testCalculationAmount()
- {
- $model = OwnerStoragePriceModel::query()->find($this->data["models"][0]["id"]);
- $result = $this->service->calculationAmount($model,548.98,$this->data["owners"][0]["id"],"2020-10-10");
- $this->assertEquals([0,0],$result);
- $model = OwnerStoragePriceModel::query()->find($this->data["models"][1]["id"]);
- $result = $this->service->calculationAmount($model,548.98,$this->data["owners"][0]["id"],"2020-10-10");
- $this->assertEquals([0,null],$result);
- }
- public function tearDown(): void
- {
- OwnerStoragePriceModel::destroy(array_column($this->data["models"],"id"));
- Owner::destroy(array_column($this->data["owners"],"id"));
- OwnerReport::destroy(array_column($this->data["reports"],"id"));
- Unit::destroy(array_column($this->data["units"],"id"));
- TaxRate::destroy($this->data["taxRate"]['id']);
- parent::tearDown();
- }
- }
|