diff --git a/src/Controllers/Metrics/Stats.php b/src/Controllers/Metrics/Stats.php index f1ef247b..b7aecffd 100644 --- a/src/Controllers/Metrics/Stats.php +++ b/src/Controllers/Metrics/Stats.php @@ -6,6 +6,7 @@ use Carbon\Carbon; use Engelsystem\Database\Database; use Engelsystem\Models\EventConfig; use Engelsystem\Models\News; +use Engelsystem\Models\Question; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Expression as QueryExpression; @@ -221,13 +222,10 @@ class Stats /** * @param bool $answered * @return int - * @codeCoverageIgnore */ public function questions($answered = null) { - $query = $this - ->getQuery('questions'); - + $query = Question::query(); if (!is_null($answered)) { if ($answered) { $query->whereNotNull('answerer_id'); diff --git a/tests/Unit/Controllers/Metrics/StatsTest.php b/tests/Unit/Controllers/Metrics/StatsTest.php index 54add688..146c44a0 100644 --- a/tests/Unit/Controllers/Metrics/StatsTest.php +++ b/tests/Unit/Controllers/Metrics/StatsTest.php @@ -6,6 +6,7 @@ use Carbon\Carbon; use Engelsystem\Controllers\Metrics\Stats; use Engelsystem\Models\LogEntry; use Engelsystem\Models\News; +use Engelsystem\Models\Question; use Engelsystem\Models\User\PasswordReset; use Engelsystem\Models\User\PersonalData; use Engelsystem\Models\User\State; @@ -91,6 +92,24 @@ class StatsTest extends TestCase $this->assertEquals(1, $stats->announcements(true)); } + /** + * @covers \Engelsystem\Controllers\Metrics\Stats::questions + */ + public function testQuestions() + { + $this->addUsers(); + $questionsData = ['text' => 'Lorem Ipsum', 'user_id' => 1]; + + (new Question($questionsData))->save(); + (new Question($questionsData))->save(); + (new Question($questionsData + ['answerer_id' => 2, 'answer' => 'Dolor sit!']))->save(); + + $stats = new Stats($this->database); + $this->assertEquals(3, $stats->questions()); + $this->assertEquals(2, $stats->questions(false)); + $this->assertEquals(1, $stats->questions(true)); + } + /** * @covers \Engelsystem\Controllers\Metrics\Stats::arrivedUsers */