From df9aecae6e362e0b5d641080c1c7a7a84a592efc Mon Sep 17 00:00:00 2001 From: Ollie Date: Tue, 20 Jan 2026 17:45:44 +0000 Subject: [PATCH] Refactor WikiMetrics and WikiMetricsTest Bug: T415104 --- app/Metrics/App/WikiMetrics.php | 4 ++-- tests/Metrics/WikiMetricsTest.php | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Metrics/App/WikiMetrics.php b/app/Metrics/App/WikiMetrics.php index c67ea78d..faad0b64 100644 --- a/app/Metrics/App/WikiMetrics.php +++ b/app/Metrics/App/WikiMetrics.php @@ -36,7 +36,7 @@ public function saveMetrics(Wiki $wiki): void { $quarterlyActions = $this->getNumberOfActions(self::INTERVAL_QUARTERLY); $numberOfEntities = $this->getNumberOfEntities(); $monthlyNumberOfUsersPerActivityType = $this->getNumberOfUsersPerActivityType(); - $numberOfUsersPerWiki = $wiki->wikiSiteStats()->first()->users ?? 0; + $numberOfUsers = $wiki->wikiSiteStats()->first()->users ?? 0; $dailyMetrics = new WikiDailyMetrics([ 'id' => $wiki->id . '_' . date('Y-m-d'), @@ -55,7 +55,7 @@ public function saveMetrics(Wiki $wiki): void { 'entity_schema_count' => $numberOfEntities['640'], 'monthly_casual_users' => $monthlyNumberOfUsersPerActivityType[0], 'monthly_active_users' => $monthlyNumberOfUsersPerActivityType[1], - 'total_user_count' => $numberOfUsersPerWiki, + 'total_user_count' => $numberOfUsers, ]); // compare current record to old record and only save if there is a change diff --git a/tests/Metrics/WikiMetricsTest.php b/tests/Metrics/WikiMetricsTest.php index f594502f..06442375 100644 --- a/tests/Metrics/WikiMetricsTest.php +++ b/tests/Metrics/WikiMetricsTest.php @@ -35,7 +35,8 @@ public function testSuccessfullyAddRecords() { $wikiDb->update(['wiki_id' => $wiki->id]); (new WikiMetrics)->saveMetrics($wiki); - // Assert the metric is updated in the database + + // Assert new record is added to the database $this->assertDatabaseHas('wiki_daily_metrics', [ 'date' => now()->toDateString(), ]); @@ -96,7 +97,7 @@ public function testAddRecordsWikiIsDeleted() { ]); } - public function testItSaveTripleCountSuccessfully() { + public function testTripleCountSavedSuccessfully() { $wiki = Wiki::factory()->create([ 'domain' => 'somewikiforunittest.wikibase.cloud', ]);