Skip to content

Commit

Permalink
feat: unit test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomiejmarszal committed Dec 20, 2024
1 parent 7692092 commit 0639e10
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions test/unit/model/Infrastructure/QtiItemResponseRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
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;
use qtism\data\ExtendedAssessmentItemRef;
use qtism\runtime\common\State;
use qtism\runtime\tests\AssessmentItemSession;
use qtism\runtime\tests\AssessmentItemSessionException;
use qtism\runtime\tests\AssessmentTestSession;

class QtiItemResponseRepositoryTest extends TestCase
{
Expand All @@ -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,
Expand All @@ -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())
Expand Down Expand Up @@ -112,6 +116,10 @@ public function testSave(
->method('isEnabled')
->willReturn(true);

$runnerServiceContextMock
->method('getTestSession')
->willReturn($assessmentTestSession);

$this->itemResponseValidatorMock->expects($this->once())
->method('validate');

Expand All @@ -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);
}
Expand Down

0 comments on commit 0639e10

Please sign in to comment.