芝麻web文件管理V1.00
编辑当前文件:/home/forge/stage.herta-bht.smartcon-survey.com/tests/Feature/StatementTest.php
countryId = 1; $this->brands = Brand::factory()->createMany([ ['sid' => 1, 'name' => 'Wagner', 'color' => '#ff0000'], ['sid' => 2, 'name' => 'Oatker', 'color' => '#fff000'], ]); $interviews = Interview::factory()->createMany([ ['wave' => 1, 'country_id' => $this->countryId, 'userid' => 1, 'created_at' => Carbon::now()->format('Y-m-d H:i:s')], ['wave' => 1, 'country_id' => $this->countryId, 'userid' => 2, 'created_at' => Carbon::now()->format('Y-m-d H:i:s')], ['wave' => 2, 'country_id' => $this->countryId, 'userid' => 3, 'created_at' => Carbon::create(today()->year - 1, rand(10, 12), rand(1, 31))->format('Y-m-d H:i:s')], ]); $dataUpload = DataUpload::factory()->createMany([ ['wave' => 1, 'country_id' => $this->countryId, 'id' => 1, 'interviews_count' => 100, 'published' => 1, 'quarter' => 4, 'year' => 2024], ['wave' => 2, 'country_id' => $this->countryId, 'id' => 2, 'interviews_count' => 100, 'published' => 1, 'quarter' => 1, 'year' => 2025], ]); DataAggregation::factory()->createMany([ ['country_id' => $this->countryId, 'model_id' => 1, 'wave' => 1, 'question_name' => 'Q9', 'value' => '1', 'statement_id' => 1, 'aggregate' => 1, 'key' => 'Q9_'.'1', 'quarter' => 4, 'year' => 2024], ['country_id' => $this->countryId, 'model_id' => 1, 'wave' => 1, 'question_name' => 'Q2', 'value' => '1', 'statement_id' => 1, 'aggregate' => 5, 'key' => 'Q2_'.'1', 'quarter' => 4, 'year' => 2024], ['country_id' => $this->countryId, 'model_id' => 1, 'wave' => 2, 'question_name' => 'Q9', 'value' => '1', 'statement_id' => 1, 'aggregate' => 4, 'key' => 'Q9_'.'1', 'quarter' => 1, 'year' => 2025], ['country_id' => $this->countryId, 'model_id' => 1, 'wave' => 2, 'question_name' => 'Q2', 'value' => '1', 'statement_id' => 1, 'aggregate' => 10, 'key' => 'Q2_'.'1', 'quarter' => 1, 'year' => 2025], ['country_id' => $this->countryId, 'model_id' => 2, 'wave' => 1, 'question_name' => 'Q9', 'value' => '1', 'statement_id' => 1, 'aggregate' => 3, 'key' => 'Q9_'.'1', 'quarter' => 4, 'year' => 2024], ['country_id' => $this->countryId, 'model_id' => 2, 'wave' => 1, 'question_name' => 'Q2', 'value' => '1', 'statement_id' => 1, 'aggregate' => 4, 'key' => 'Q2_'.'1', 'quarter' => 4, 'year' => 2024], ['country_id' => $this->countryId, 'model_id' => 2, 'wave' => 2, 'question_name' => 'Q9', 'value' => '1', 'statement_id' => 1, 'aggregate' => 2, 'key' => 'Q9_'.'1', 'quarter' => 1, 'year' => 2025], ['country_id' => $this->countryId, 'model_id' => 2, 'wave' => 2, 'question_name' => 'Q2', 'value' => '1', 'statement_id' => 1, 'aggregate' => 5, 'key' => 'Q2_'.'1', 'quarter' => 1, 'year' => 2025], ]); $this->service = new StatementsService($this->countryId, $this->brands, []); }); afterEach(function () { // Rollback or refresh the database after each test DB::rollBack(); DB::beginTransaction(); }); test('calculate statements values for first brand correctly', function () { $result = $this->service->getvalues(1); expectData($result['current'][0], 'Q1 2025', 4, 10, 40.0); expectData($result['last'][0], 'Q4 2024', 1, 5, 20.0); }); test('calculate statements values for second brand correctly', function () { $result = $this->service->getvalues(1); expectData($result['current'][1], 'Q1 2025', 2, 5, 40.0); expectData($result['last'][1], 'Q4 2024', 3, 4, 75.0); }); // Helper function for common assertions function expectData(array $data, string $x, int $n, int $totalN, float $value) { expect($data) ->toBeArray() ->and($data['label'])->toBe($x) ->and($data['n'])->toBe($n) ->and($data['totalN'])->toBe($totalN) ->and($data['value'])->toBe($value); }