From a39c5c6bd2982298af397781b0b8d24c2d23c6ca Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 8 Nov 2024 15:01:56 +0000 Subject: [PATCH] ci: commit oat-sa/environment-management# --- .github/workflows/sonar.yml | 40 ------------------- sonar-project.properties | 1 - src/Client/LtiBasicOutcomeClient.php | 6 +-- src/Client/LtiBasicOutcomeClientInterface.php | 2 +- src/Client/LtiProctoringClient.php | 15 +++++-- src/Client/LtiProctoringClientInterface.php | 3 +- .../Unit/Client/LtiBasicOutcomeClientTest.php | 19 +++------ tests/Unit/Client/LtiProctoringClientTest.php | 28 ++++++++++--- 8 files changed, 44 insertions(+), 70 deletions(-) delete mode 100644 .github/workflows/sonar.yml delete mode 100644 sonar-project.properties diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml deleted file mode 100644 index d1cd670..0000000 --- a/.github/workflows/sonar.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Sonarqube_CI -on: - - pull_request: - types: - - labeled - - push: - branches: - - master - - main - - release-* - -jobs: - build: - name: Sonarqube_CI - if: ${{ github.event.label.name == 'sonar_check' || github.event_name == 'push' }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Sonarqube scan - uses: sonarsource/sonarqube-scan-action@master - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: 'https://sonarqube.taotesting.info/sonarqube/' - - # Job will fail when the Quality Gate is red - - name: Sonarqube quality gate check - id: sonarqube-quality-gate-check - uses: sonarsource/sonarqube-quality-gate-action@master - timeout-minutes: 5 - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - - - name: "Example show SonarQube Quality Gate Status value" - run: echo "The Quality Gate status is ${{ steps.sonarqube-quality-gate-check.outputs.quality-gate-status }}" \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index 3e5b9dc..0000000 --- a/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -sonar.projectKey=lib-em-php-lti-client diff --git a/src/Client/LtiBasicOutcomeClient.php b/src/Client/LtiBasicOutcomeClient.php index eb5d89f..307ec61 100644 --- a/src/Client/LtiBasicOutcomeClient.php +++ b/src/Client/LtiBasicOutcomeClient.php @@ -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); } diff --git a/src/Client/LtiBasicOutcomeClientInterface.php b/src/Client/LtiBasicOutcomeClientInterface.php index 2b7cacf..7f9e198 100644 --- a/src/Client/LtiBasicOutcomeClientInterface.php +++ b/src/Client/LtiBasicOutcomeClientInterface.php @@ -59,5 +59,5 @@ public function sendBasicOutcome( string $registrationId, string $lisOutcomeServiceUrl, string $xml, - ): BasicOutcomeResponseInterface; + ): void; } 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/LtiBasicOutcomeClientTest.php b/tests/Unit/Client/LtiBasicOutcomeClientTest.php index 9ee5137..e3c50d9 100644 --- a/tests/Unit/Client/LtiBasicOutcomeClientTest.php +++ b/tests/Unit/Client/LtiBasicOutcomeClientTest.php @@ -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; @@ -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( @@ -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 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);