From 0639e105ed267b915f875c974b635c479418f162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Marsza=C5=82?= Date: Fri, 20 Dec 2024 12:52:28 +0100 Subject: [PATCH] feat: unit test fix --- .../QtiItemResponseRepositoryTest.php | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/test/unit/model/Infrastructure/QtiItemResponseRepositoryTest.php b/test/unit/model/Infrastructure/QtiItemResponseRepositoryTest.php index a40a9929b..227c101c3 100644 --- a/test/unit/model/Infrastructure/QtiItemResponseRepositoryTest.php +++ b/test/unit/model/Infrastructure/QtiItemResponseRepositoryTest.php @@ -27,6 +27,7 @@ use oat\taoQtiTest\model\Infrastructure\QtiItemResponseRepository; use oat\taoQtiTest\model\Infrastructure\QtiItemResponseValidator; use oat\taoQtiTest\models\classes\runner\QtiRunnerInvalidResponsesException; +use oat\taoQtiTest\models\runner\QtiRunnerEmptyResponsesException; use oat\taoQtiTest\models\runner\QtiRunnerService; use oat\taoQtiTest\models\runner\QtiRunnerServiceContext; use PHPUnit\Framework\TestCase; @@ -34,6 +35,7 @@ use qtism\runtime\common\State; use qtism\runtime\tests\AssessmentItemSession; use qtism\runtime\tests\AssessmentItemSessionException; +use qtism\runtime\tests\AssessmentTestSession; class QtiItemResponseRepositoryTest extends TestCase { @@ -56,15 +58,16 @@ public function setUp(): void * @dataProvider saveDataProvider */ public function testSave( - array $state, - array $response, - float $duration, - float $timestamp, + array $state, + array $response, + float $duration, + float $timestamp, string $itemHref, string $responseIdentifier, - int $storeItemResponseCount, - bool $shouldThrowException - ): void { + int $storeItemResponseCount, + bool $shouldThrowException + ): void + { $itemResponse = new ItemResponse('itemIdentifier', $state, $response, @@ -75,6 +78,7 @@ public function testSave( $runnerServiceContextMock = $this->createMock(QtiRunnerServiceContext::class); $extendedAssessmentItemRefMock = $this->createMock(ExtendedAssessmentItemRef::class); $assessmentItemSession = $this->createMock(AssessmentItemSession::class); + $assessmentTestSession = $this->createMock(AssessmentTestSession::class); $stateMock = $this->createMock(State::class); $extendedAssessmentItemRefMock->expects($this->once()) @@ -112,6 +116,10 @@ public function testSave( ->method('isEnabled') ->willReturn(true); + $runnerServiceContextMock + ->method('getTestSession') + ->willReturn($assessmentTestSession); + $this->itemResponseValidatorMock->expects($this->once()) ->method('validate'); @@ -121,6 +129,7 @@ public function testSave( if ($shouldThrowException) { $this->itemResponseValidatorMock->expects($this->once()) ->method('validate') + ->with($assessmentTestSession, $stateMock) ->willThrowException(new AssessmentItemSessionException('invalid', $assessmentItemSession, AssessmentItemSessionException::DURATION_OVERFLOW)); $this->expectException(QtiRunnerInvalidResponsesException::class); }