Skip to content

Commit

Permalink
ci: commit oat-sa/environment-management#
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jan 12, 2023
1 parent 22ece0f commit cabb5e5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
15 changes: 11 additions & 4 deletions src/Client/LtiProctoringClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Client/LtiProctoringClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
28 changes: 23 additions & 5 deletions tests/Unit/Client/LtiProctoringClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

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

Expand Down

0 comments on commit cabb5e5

Please sign in to comment.