testSessionMock = $this->createMock(TestSession::class); $this->subject = new TestSessionService(); } public function testGetSmallestMaxTimeConstraint_NoConstraints_ReturnsNull(): void { $this->testSessionMock->method('getTimeConstraints') ->willReturn(new TimeConstraintCollection()); self::assertNull( $this->subject->getSmallestMaxTimeConstraint($this->testSessionMock), 'Method must return correct response in case session does not have time constraints.' ); } public function testGetSmallestMaxTimeConstraint_NoConstraintsWithMaximumRemainingTime_ReturnsNull(): void { $timeConstraintSession = $this->mockQtiTimeConstraint(false); $timeConstraintTestPart = $this->mockQtiTimeConstraint(false); $timeConstraintsCollection = new TimeConstraintCollection([$timeConstraintSession, $timeConstraintTestPart]); $this->testSessionMock->method('getTimeConstraints') ->willReturn($timeConstraintsCollection); self::assertNull( $this->subject->getSmallestMaxTimeConstraint($this->testSessionMock), 'Method must return correct response in case constraints do not have max time limits.' ); } public function testGetSmallestMaxTimeConstraint_OneConstraintWithMaximumRemainingTime(): void { $timeConstraintSession = $this->mockQtiTimeConstraint(false); $timeConstraintTestPart = $this->mockQtiTimeConstraint(false); $timeConstraintTest = $this->mockQtiTimeConstraint($this->mockQtiDuration(600)); $timeConstraintsCollection = new TimeConstraintCollection([ $timeConstraintSession, $timeConstraintTestPart, $timeConstraintTest ]); $expectedConstraint = $timeConstraintTest; $this->testSessionMock->method('getTimeConstraints') ->willReturn($timeConstraintsCollection); self::assertSame( $expectedConstraint, $this->subject->getSmallestMaxTimeConstraint($this->testSessionMock), 'Method must return correct response in case there is one constraint with max time limit.' ); } public function testGetSmallestMaxTimeConstraint_MultipleConstraintsWithMaximumRemainingTime(): void { $timeConstraintTest = $this->mockQtiTimeConstraint($this->mockQtiDuration(600)); $timeConstraintTestPart = $this->mockQtiTimeConstraint($this->mockQtiDuration(450)); $timeConstraintSession = $this->mockQtiTimeConstraint($this->mockQtiDuration(300)); $timeConstraintsCollection = new TimeConstraintCollection([ $timeConstraintSession, $timeConstraintTestPart, $timeConstraintTest ]); $expectedConstraint = $timeConstraintSession; $this->testSessionMock->method('getTimeConstraints') ->willReturn($timeConstraintsCollection); self::assertSame( $expectedConstraint, $this->subject->getSmallestMaxTimeConstraint($this->testSessionMock), 'Method must return correct response in case there multiple constraints with max time limit.' ); } /** * @param int $maxRemainingTime * @return QtiDuration */ private function mockQtiDuration(int $maxRemainingTime): QtiDuration { $durationMock = $this->createMock(QtiDuration::class); $durationMock->method('getSeconds') ->willReturn($maxRemainingTime); return $durationMock; } /** * @param QtiDuration|bool $maxRemainingTime * @return QtiTimeConstraint|MockObject */ private function mockQtiTimeConstraint($duration): QtiTimeConstraint { $qtiTimeConstraintMock = $this->createMock(QtiTimeConstraint::class); $qtiTimeConstraintMock->method('getMaximumRemainingTime') ->willReturn($duration); return $qtiTimeConstraintMock; } }