diff --git a/src/Controllers/Metrics/Stats.php b/src/Controllers/Metrics/Stats.php index 718bcb39..8129f27c 100644 --- a/src/Controllers/Metrics/Stats.php +++ b/src/Controllers/Metrics/Stats.php @@ -8,6 +8,7 @@ use Carbon\Carbon; use Engelsystem\Database\Database; use Engelsystem\Models\EventConfig; use Engelsystem\Models\LogEntry; +use Engelsystem\Models\Message; use Engelsystem\Models\News; use Engelsystem\Models\Question; use Engelsystem\Models\User\PasswordReset; @@ -239,13 +240,10 @@ class Stats /** * @return int - * @codeCoverageIgnore */ public function messages(): int { - return $this - ->getQuery('Messages') - ->count(); + return Message::query()->count(); } /** diff --git a/tests/Unit/Controllers/Metrics/StatsTest.php b/tests/Unit/Controllers/Metrics/StatsTest.php index d13c2693..15447be8 100644 --- a/tests/Unit/Controllers/Metrics/StatsTest.php +++ b/tests/Unit/Controllers/Metrics/StatsTest.php @@ -5,6 +5,7 @@ namespace Engelsystem\Test\Unit\Controllers\Metrics; use Carbon\Carbon; use Engelsystem\Controllers\Metrics\Stats; use Engelsystem\Models\LogEntry; +use Engelsystem\Models\Message; use Engelsystem\Models\News; use Engelsystem\Models\Question; use Engelsystem\Models\User\PasswordReset; @@ -131,6 +132,21 @@ class StatsTest extends TestCase $this->assertEquals(2, $stats->forceActiveUsers()); } + /** + * @covers \Engelsystem\Controllers\Metrics\Stats::messages + */ + public function testMessages() + { + $this->addUsers(); + + (new Message(['user_id' => 1, 'receiver_id' => 2, 'text' => 'Ohi?']))->save(); + (new Message(['user_id' => 4, 'receiver_id' => 1, 'text' => 'Testing stuff?']))->save(); + (new Message(['user_id' => 2, 'receiver_id' => 3, 'text' => 'Nope!', 'read' => true]))->save(); + + $stats = new Stats($this->database); + $this->assertEquals(3, $stats->messages()); + } + /** * @covers \Engelsystem\Controllers\Metrics\Stats::sessions */