芝麻web文件管理V1.00
编辑当前文件:/home/forge/stage.herta-bht.smartcon-survey.com/tests/Feature/FunnelTest.php
brand = Brand::factory()->create(['sid' => 1]); $this->countryId = 1; $interviews = Interview::factory()->createMany([ ['wave' => 1, 'country_id' => $this->countryId, 'userid' => 1], ['wave' => 2, 'country_id' => $this->countryId, 'userid' => 2], ['wave' => 2, 'country_id' => $this->countryId, 'userid' => 3], ]); $dataUpload = DataUpload::factory()->createMany([ ['country_id' => $this->countryId, 'id' => 1, 'interviews_count' => 100, 'quarter' => 1, 'year' => 2025], ['country_id' => $this->countryId, 'id' => 2, 'interviews_count' => 100, 'quarter' => 4, 'year' => 2024], ]); DataAggregation::factory()->createMany([ ['country_id' => $this->countryId, 'model_id' => $this->brand->sid, 'wave' => 1, 'question_name' => 'Q2', 'value' => '1', 'aggregate' => 10, 'key' => 'Q2_'.$this->brand->sid, 'quarter' => 4, 'year' => 2024], ['country_id' => $this->countryId, 'model_id' => $this->brand->sid, 'wave' => 2, 'question_name' => 'Q2', 'value' => '1', 'aggregate' => 20, 'key' => 'Q2_'.$this->brand->sid, 'quarter' => 1, 'year' => 2025], ['country_id' => $this->countryId, 'model_id' => $this->brand->sid, 'wave' => 1, 'question_name' => 'Q8', 'value' => '1', 'aggregate' => 10, 'key' => 'Q8_'.$this->brand->sid, 'quarter' => 4, 'year' => 2024], ['country_id' => $this->countryId, 'model_id' => $this->brand->sid, 'wave' => 2, 'question_name' => 'Q8', 'value' => '1', 'aggregate' => 11, 'key' => 'Q8_'.$this->brand->sid, 'quarter' => 1, 'year' => 2025], ['country_id' => $this->countryId, 'model_id' => $this->brand->sid, 'wave' => 1, 'question_name' => 'Q4', 'value' => '1', 'aggregate' => 8, 'key' => 'Q4_'.$this->brand->sid, 'quarter' => 4, 'year' => 2024], ['country_id' => $this->countryId, 'model_id' => $this->brand->sid, 'wave' => 2, 'question_name' => 'Q4', 'value' => '1', 'aggregate' => 9, 'key' => 'Q4_'.$this->brand->sid, 'quarter' => 1, 'year' => 2025], ['country_id' => $this->countryId, 'model_id' => $this->brand->sid, 'wave' => 1, 'question_name' => 'Q5', 'value' => '1', 'aggregate' => 7, 'key' => 'Q5_'.$this->brand->sid, 'quarter' => 4, 'year' => 2024], ['country_id' => $this->countryId, 'model_id' => $this->brand->sid, 'wave' => 2, 'question_name' => 'Q5', 'value' => '1', 'aggregate' => 6, 'key' => 'Q5_1'.$this->brand->sid, 'quarter' => 1, 'year' => 2025], ['country_id' => $this->countryId, 'model_id' => $this->brand->sid, 'wave' => 1, 'question_name' => 'Q7', 'value' => $this->brand->sid, 'aggregate' => 3, 'key' => 'Q7', 'quarter' => 4, 'year' => 2024], ['country_id' => $this->countryId, 'model_id' => $this->brand->sid, 'wave' => 2, 'question_name' => 'Q7', 'value' => $this->brand->sid, 'aggregate' => 4, 'key' => 'Q7', 'quarter' => 1, 'year' => 2025], ]); $this->countryId = 1; $this->service = (new FunnelService($this->countryId))->setModel($this->brand); }); afterEach(function () { // Rollback or refresh the database after each test DB::rollBack(); DB::beginTransaction(); }); test('return awareness data correctly', function () { $result = $this->service->awareness(); expectFunnelData($result, 'Awareness', 20, 20, 0.0, 10.0); }); test('return consideration data correctly', function () { $result = $this->service->consideration(); expectFunnelData($result, 'Consideration', 11, 11, 55.0, 1.0); }); test('return trial data correctly', function () { $result = $this->service->trial(); expectFunnelData($result, 'Trial', 9, 9, 82.0, 1.0); }); test('return purchase data correctly', function () { $result = $this->service->purchase(); expectFunnelData($result, 'Repurchase', 6, 6, 67.0, -1.0); }); test('return loyalty data correctly', function () { $result = $this->service->loyalty(); expectFunnelData($result, 'Loyalty', 4, 4, 67.0, 1.0); }); // Helper function for common assertions function expectFunnelData(array $data, string $label, int $n, float $value, float $conversion, float $delta): void { expect($data) ->toBeArray() ->and($data['label'])->toBe($label) ->and($data)->toHaveCount(5) ->and($data['n'])->toBe($n) ->and($data['value'])->toBe($value) ->and($data['conversion'])->toBeNumeric()->toBe($conversion) ->and($data['delta'])->toBeNumeric()->toBe($delta); }