Metrics: Fixed message count

main
Igor Scheller 5 years ago
parent 395f6706d6
commit 61977f5da9

@ -8,6 +8,7 @@ use Carbon\Carbon;
use Engelsystem\Database\Database; use Engelsystem\Database\Database;
use Engelsystem\Models\EventConfig; use Engelsystem\Models\EventConfig;
use Engelsystem\Models\LogEntry; use Engelsystem\Models\LogEntry;
use Engelsystem\Models\Message;
use Engelsystem\Models\News; use Engelsystem\Models\News;
use Engelsystem\Models\Question; use Engelsystem\Models\Question;
use Engelsystem\Models\User\PasswordReset; use Engelsystem\Models\User\PasswordReset;
@ -239,13 +240,10 @@ class Stats
/** /**
* @return int * @return int
* @codeCoverageIgnore
*/ */
public function messages(): int public function messages(): int
{ {
return $this return Message::query()->count();
->getQuery('Messages')
->count();
} }
/** /**

@ -5,6 +5,7 @@ namespace Engelsystem\Test\Unit\Controllers\Metrics;
use Carbon\Carbon; use Carbon\Carbon;
use Engelsystem\Controllers\Metrics\Stats; use Engelsystem\Controllers\Metrics\Stats;
use Engelsystem\Models\LogEntry; use Engelsystem\Models\LogEntry;
use Engelsystem\Models\Message;
use Engelsystem\Models\News; use Engelsystem\Models\News;
use Engelsystem\Models\Question; use Engelsystem\Models\Question;
use Engelsystem\Models\User\PasswordReset; use Engelsystem\Models\User\PasswordReset;
@ -131,6 +132,21 @@ class StatsTest extends TestCase
$this->assertEquals(2, $stats->forceActiveUsers()); $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 * @covers \Engelsystem\Controllers\Metrics\Stats::sessions
*/ */

Loading…
Cancel
Save