mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-07-11 20:38:21 +02:00
2fd15ba8fa
* test: expand coverage, dedupe data-driven tests, extract shared WebTestCase base - Add #[CoversClass] to Base64Test and FilenameSanitizerTest - Merge near-duplicate test methods into #[DataProvider] cases across ResetPasswordControllerTest, SettingsControllerTest, ClaimSeasonCommandTest, FilenameSanitizerTest, Base64Test, and SeasonRepositoryTest - Add integration tests for previously untested controllers: public QuizController (quiz-taking flow), LoginController, RegistrationController, EliminationController, and PrepareEliminationController - Add unit tests for Elimination and BankQuestion entity logic - Extract shared WebTestCase setup/helpers (client, entityManager, login, entity lookups, CSRF token scraping) into AbstractControllerWebTestCase, removing duplicated boilerplate from all 14 WebTestCase files * test: address PR review feedback - Scope AbstractControllerWebTestCase::getCandidate/getQuizByName by season code (both Candidate and Quiz are only unique per season, not system-wide) and add a CandidateRepository regression test guarding against same-named candidates in different seasons - Add missing entityManager->clear() before verifying DB state after a POST in PrepareEliminationControllerTest and QuestionBankControllerTest - Add non-owner denial tests for BackofficeController::exportQuiz and QuizQuestionController::edit/reorder, which had IsGranted checks with no test coverage * ci: publish PHPUnit coverage to GitHub code coverage - Generate a Cobertura report alongside the existing JUnit report and upload it with actions/upload-code-coverage so coverage shows up on PRs and the default branch via GitHub's code coverage feature - Add a step to copy both reports out of the php container before publishing them, since var/ is a Docker volume (see the Dockerfile's VOLUME /app/var/) and isn't bind-mounted to the runner — this also fixes the existing JUnit report publishing step, which was silently looking at a path that never had contets on the runner * ci: fix coverage report paths and tolerate Code Quality not yet enabled - Write PHPUnit's JUnit and Cobertura reports to reports/ instead of var/, since var/ is a Docker volume (Dockerfile's VOLUME /app/var/) that isn't bind-mounted to the runner - reports written there never reached the host, which is also why the prior junit.xml publish step had nothing to read. reports/ is a plain path under the project's bind mount, so no extra copy-out step is needed - Set fail-on-error: false on the coverage upload step: it 404s until "Code Quality" is turned on for the repo under Settings > Code security > Code quality, a one-time manual step
101 lines
3.1 KiB
PHP
101 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tvdt\Tests\Entity;
|
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Tvdt\Entity\BankAnswer;
|
|
use Tvdt\Entity\BankQuestion;
|
|
use Tvdt\Entity\BankQuestionUsage;
|
|
use Tvdt\Entity\Quiz;
|
|
|
|
#[CoversClass(BankQuestion::class)]
|
|
final class BankQuestionTest extends TestCase
|
|
{
|
|
public function testIsCompleteForQuizIsFalseWithoutTwoAnswers(): void
|
|
{
|
|
$bankQuestion = new BankQuestion();
|
|
$bankQuestion->addAnswer(new BankAnswer('Only answer', true));
|
|
|
|
$this->assertFalse($bankQuestion->isCompleteForQuiz);
|
|
}
|
|
|
|
public function testIsCompleteForQuizIsFalseWithoutCorrectAnswer(): void
|
|
{
|
|
$bankQuestion = new BankQuestion();
|
|
$bankQuestion->addAnswer(new BankAnswer('Wrong 1'));
|
|
$bankQuestion->addAnswer(new BankAnswer('Wrong 2'));
|
|
|
|
$this->assertFalse($bankQuestion->isCompleteForQuiz);
|
|
}
|
|
|
|
public function testIsCompleteForQuizIsFalseWithMultipleCorrectAnswers(): void
|
|
{
|
|
$bankQuestion = new BankQuestion();
|
|
$bankQuestion->addAnswer(new BankAnswer('Right 1', true));
|
|
$bankQuestion->addAnswer(new BankAnswer('Right 2', true));
|
|
|
|
$this->assertFalse($bankQuestion->isCompleteForQuiz);
|
|
}
|
|
|
|
public function testIsCompleteForQuizIsTrueWithTwoAnswersAndOneCorrect(): void
|
|
{
|
|
$bankQuestion = new BankQuestion();
|
|
$bankQuestion->addAnswer(new BankAnswer('Right', true));
|
|
$bankQuestion->addAnswer(new BankAnswer('Wrong'));
|
|
|
|
$this->assertTrue($bankQuestion->isCompleteForQuiz);
|
|
}
|
|
|
|
public function testCanBeAssignedIsTrueWhenUnused(): void
|
|
{
|
|
$bankQuestion = new BankQuestion();
|
|
|
|
$this->assertTrue($bankQuestion->canBeAssigned);
|
|
}
|
|
|
|
public function testCanBeAssignedIsTrueWhenReusableEvenIfUsed(): void
|
|
{
|
|
$bankQuestion = new BankQuestion();
|
|
$bankQuestion->reusable = true;
|
|
$bankQuestion->addUsage(new BankQuestionUsage($bankQuestion, new Quiz()));
|
|
|
|
$this->assertTrue($bankQuestion->canBeAssigned);
|
|
}
|
|
|
|
public function testCanBeAssignedIsFalseWhenSingleUseAndUsed(): void
|
|
{
|
|
$bankQuestion = new BankQuestion();
|
|
$bankQuestion->addUsage(new BankQuestionUsage($bankQuestion, new Quiz()));
|
|
|
|
$this->assertFalse($bankQuestion->canBeAssigned);
|
|
}
|
|
|
|
public function testIsUsedInQuizIsTrueForQuizWithUsage(): void
|
|
{
|
|
$bankQuestion = new BankQuestion();
|
|
$quiz = new Quiz();
|
|
$bankQuestion->addUsage(new BankQuestionUsage($bankQuestion, $quiz));
|
|
|
|
$this->assertTrue($bankQuestion->isUsedInQuiz($quiz));
|
|
}
|
|
|
|
public function testIsUsedInQuizIsFalseForDifferentQuiz(): void
|
|
{
|
|
$bankQuestion = new BankQuestion();
|
|
$bankQuestion->addUsage(new BankQuestionUsage($bankQuestion, new Quiz()));
|
|
|
|
$this->assertFalse($bankQuestion->isUsedInQuiz(new Quiz()));
|
|
}
|
|
|
|
public function testToStringReturnsQuestionText(): void
|
|
{
|
|
$bankQuestion = new BankQuestion();
|
|
$bankQuestion->question = 'Wie is de Krtek?';
|
|
|
|
$this->assertSame('Wie is de Krtek?', (string) $bankQuestion);
|
|
}
|
|
}
|