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 Oct 16, 2024
1 parent 4a95a1f commit eda06e9
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 70 deletions.
40 changes: 0 additions & 40 deletions .github/workflows/sonar.yml

This file was deleted.

1 change: 0 additions & 1 deletion sonar-project.properties

This file was deleted.

6 changes: 2 additions & 4 deletions src/Client/LtiBasicOutcomeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,13 @@ public function sendBasicOutcome(
string $registrationId,
string $lisOutcomeServiceUrl,
string $xml,
): BasicOutcomeResponseInterface {
): void {
$event = new SendBasicOutcomeEvent($registrationId, $lisOutcomeServiceUrl, $xml);

try {
$response = $this->ltiGateway->send($event);

$this->assertStatusCode($response, 200, SendBasicOutcomeEvent::TYPE);

return $this->basicOutcomeResponseSerializer->deserialize($response->getBody()->getContents());
$this->assertStatusCode($response, 201, SendBasicOutcomeEvent::TYPE);
} catch (LtiGatewayException $exception) {
throw $this->createLtiBasicOutcomeClientException(SendBasicOutcomeEvent::TYPE, $exception->getMessage(), $exception);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Client/LtiBasicOutcomeClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ public function sendBasicOutcome(
string $registrationId,
string $lisOutcomeServiceUrl,
string $xml,
): BasicOutcomeResponseInterface;
): void;
}
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;
}
19 changes: 5 additions & 14 deletions tests/Unit/Client/LtiBasicOutcomeClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@
use OAT\Library\EnvironmentManagementLtiClient\Exception\LtiGatewayException;
use OAT\Library\EnvironmentManagementLtiClient\Gateway\LtiGatewayInterface;
use OAT\Library\EnvironmentManagementLtiClient\Tests\Traits\ClientTesterTrait;
use OAT\Library\EnvironmentManagementLtiEvents\Event\Ags\GetLineItemEvent;
use OAT\Library\EnvironmentManagementLtiEvents\Event\BasicOutcome\DeleteResultEvent;
use OAT\Library\EnvironmentManagementLtiEvents\Event\BasicOutcome\ReadResultEvent;
use OAT\Library\EnvironmentManagementLtiEvents\Event\BasicOutcome\ReplaceResultEvent;
use OAT\Library\EnvironmentManagementLtiEvents\Event\BasicOutcome\SendBasicOutcomeEvent;
use OAT\Library\Lti1p3Ags\Model\LineItem\LineItem;
use OAT\Library\Lti1p3BasicOutcome\Message\Response\BasicOutcomeResponseInterface;
use OAT\Library\Lti1p3BasicOutcome\Serializer\Response\BasicOutcomeResponseSerializerInterface;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -188,10 +186,11 @@ public function testReplaceResultThrowsExceptionWhenUnexpectedStatusCodeReturned
$this->subject->replaceResult('reg-1', 'http://example.url', 'source-id', 4.5);
}

/**
* @doesNotPerformAssertions
*/
public function testSendBasicOutcomeForSuccess(): void
{
$outcomeResponse = $this->createMock(BasicOutcomeResponseInterface::class);

$this->gatewayMock->expects($this->once())
->method('send')
->with(
Expand All @@ -201,17 +200,9 @@ public function testSendBasicOutcomeForSuccess(): void
&& 'test-xml-content' === $event->getXml();
})
)
->willReturn($this->getResponseMock(200, 1, 'test body'));

$this->outcomeSerializerMock->expects($this->once())
->method('deserialize')
->with('test body')
->willReturn($outcomeResponse);
->willReturn($this->getResponseMock(201, 1, 'test body'));

$this->assertSame(
$outcomeResponse,
$this->subject->sendBasicOutcome('reg-1', 'http://example.url', 'test-xml-content')
);
$this->subject->sendBasicOutcome('reg-1', 'http://example.url', 'test-xml-content');
}

public function testSendBasicOutcomeThrowsExceptionWhenRequestFailed(): void
Expand Down
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 eda06e9

Please sign in to comment.