From 8dacac49557c5ac9a3626b1432661ce5c07227ca Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 8 Feb 2023 15:09:52 +0000 Subject: [PATCH] ci: commit oat-sa/environment-management# --- src/Client/LtiProctoringClient.php | 15 +++++++--- src/Client/LtiProctoringClientInterface.php | 3 +- tests/Unit/Client/LtiProctoringClientTest.php | 28 +++++++++++++++---- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/Client/LtiProctoringClient.php b/src/Client/LtiProctoringClient.php index ef98dd7..7c2eb4e 100644 --- a/src/Client/LtiProctoringClient.php +++ b/src/Client/LtiProctoringClient.php @@ -9,25 +9,32 @@ use OAT\Library\EnvironmentManagementLtiClient\Gateway\LtiGatewayInterface; use OAT\Library\EnvironmentManagementLtiEvents\Event\Proctoring\SendControlEvent; use OAT\Library\Lti1p3Proctoring\Model\AcsControlInterface; +use OAT\Library\Lti1p3Proctoring\Model\AcsControlResultInterface; +use OAT\Library\Lti1p3Proctoring\Serializer\AcsControlResultSerializerInterface; use Throwable; class LtiProctoringClient implements LtiProctoringClientInterface { - public function __construct(private LtiGatewayInterface $ltiGateway) {} + public function __construct( + private LtiGatewayInterface $ltiGateway, + private AcsControlResultSerializerInterface $acsControlResultSerializer, + ) {} - public function sendControl(string $registrationId, AcsControlInterface $control, string $acsUrl): void + public function sendControl(string $registrationId, AcsControlInterface $control, string $acsUrl): AcsControlResultInterface { $event = new SendControlEvent($registrationId, $control, $acsUrl); try { $response = $this->ltiGateway->send($event); - if ($response->getStatusCode() !== 201) { + if ($response->getStatusCode() !== 200) { throw $this->createLtiProctoringClientException( SendControlEvent::TYPE, - sprintf('Expected status code is %d, got %d', 201, $response->getStatusCode() + sprintf('Expected status code is %d, got %d', 200, $response->getStatusCode() )); } + + return $this->acsControlResultSerializer->deserialize($response->getBody()->getContents()); } catch (LtiGatewayException $exception) { throw $this->createLtiProctoringClientException(SendControlEvent::TYPE, $exception->getMessage(), $exception); } diff --git a/src/Client/LtiProctoringClientInterface.php b/src/Client/LtiProctoringClientInterface.php index b9b9f8b..97836ff 100644 --- a/src/Client/LtiProctoringClientInterface.php +++ b/src/Client/LtiProctoringClientInterface.php @@ -24,11 +24,12 @@ use OAT\Library\EnvironmentManagementLtiClient\Exception\LtiProctoringClientException; use OAT\Library\Lti1p3Proctoring\Model\AcsControlInterface; +use OAT\Library\Lti1p3Proctoring\Model\AcsControlResultInterface; interface LtiProctoringClientInterface { /** * @throws LtiProctoringClientException */ - public function sendControl(string $registrationId, AcsControlInterface $control, string $acsUrl): void; + public function sendControl(string $registrationId, AcsControlInterface $control, string $acsUrl): AcsControlResultInterface; } diff --git a/tests/Unit/Client/LtiProctoringClientTest.php b/tests/Unit/Client/LtiProctoringClientTest.php index 289f0fb..ce584bc 100644 --- a/tests/Unit/Client/LtiProctoringClientTest.php +++ b/tests/Unit/Client/LtiProctoringClientTest.php @@ -32,6 +32,9 @@ use OAT\Library\EnvironmentManagementLtiEvents\Event\Proctoring\SendControlEvent; use OAT\Library\Lti1p3Ags\Model\LineItem\LineItem; use OAT\Library\Lti1p3Proctoring\Model\AcsControlInterface; +use OAT\Library\Lti1p3Proctoring\Model\AcsControlResult; +use OAT\Library\Lti1p3Proctoring\Model\AcsControlResultInterface; +use OAT\Library\Lti1p3Proctoring\Serializer\AcsControlResultSerializerInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -40,18 +43,24 @@ final class LtiProctoringClientTest extends TestCase use ClientTesterTrait; private LtiGatewayInterface|MockObject $gatewayMock; + private AcsControlResultSerializerInterface|MockObject $acsControlResultSerializerMock; private LtiProctoringClient $subject; protected function setUp(): void { $this->gatewayMock = $this->createMock(LtiGatewayInterface::class); + $this->acsControlResultSerializerMock = $this->createMock(AcsControlResultSerializerInterface::class); - $this->subject = new LtiProctoringClient($this->gatewayMock); + $this->subject = new LtiProctoringClient( + $this->gatewayMock, + $this->acsControlResultSerializerMock, + ); } public function testSendControlForSuccess(): void { $acs = $this->createMock(AcsControlInterface::class); + $acsControlResult = new AcsControlResult(AcsControlResultInterface::STATUS_NONE, 123); $this->gatewayMock->expects($this->once()) ->method('send') @@ -62,12 +71,21 @@ public function testSendControlForSuccess(): void && $acs === $event->getControl(); }) ) - ->willReturn($this->getResponseMock(201)); + ->willReturn($this->getResponseMock(201, 1, '{}')); - $this->subject->sendControl('reg-1', $acs, 'http://example.url'); + $this->acsControlResultSerializerMock->expects($this->once()) + ->method('deserialize') + ->with('{}') + ->willReturn($acsControlResult); + + $result = $this->subject->sendControl('reg-1', $acs, 'http://example.url'); + + $this->assertInstanceOf(AcsControlResultInterface::class, $result); + $this->assertSame(AcsControlResultInterface::STATUS_NONE, $result->getStatus()); + $this->assertSame(123, $result->getExtraTime()); } - public function testCreateLineItemThrowsExceptionWhenRequestFailed(): void + public function testSendControlThrowsExceptionWhenRequestFailed(): void { $acs = $this->createMock(AcsControlInterface::class); @@ -81,7 +99,7 @@ public function testCreateLineItemThrowsExceptionWhenRequestFailed(): void $this->subject->sendControl('reg-1', $acs, 'http://example.url'); } - public function testCreateLineItemThrowsExceptionWhenUnexpectedStatusCodeReturned(): void + public function testSendControlThrowsExceptionWhenUnexpectedStatusCodeReturned(): void { $acs = $this->createMock(AcsControlInterface::class);