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/composer.json b/composer.json index f32fb6b..60260a3 100644 --- a/composer.json +++ b/composer.json @@ -8,13 +8,13 @@ "ext-ctype": "*", "ext-json": "*", "ext-mbstring": "*", - "oat-sa/lib-lti1p3-ags": "^1.4", - "oat-sa/lib-lti1p3-basic-outcome": "^4.1", - "oat-sa/lib-lti1p3-core": "^6.6", - "oat-sa/lib-lti1p3-nrps": "^7.0", - "oat-sa/lib-lti1p3-proctoring": "^0.4", - "symfony/property-access": "^5.0", - "symfony/serializer": "^5.0" + "oat-sa/lib-lti1p3-ags": "^1.4 | ^2.0", + "oat-sa/lib-lti1p3-basic-outcome": "^4.1 | ^5.0", + "oat-sa/lib-lti1p3-core": "^6.6 | ^7.0", + "oat-sa/lib-lti1p3-nrps": "^7.0 | ^8.0", + "oat-sa/lib-lti1p3-proctoring": "^0.5 | ^1.0", + "symfony/property-access": "^5.0 | ^6.4 | ^7.0", + "symfony/serializer": "^5.0 | ^6.4 | ^7.0" }, "require-dev": { "phpunit/phpunit": "^9.5" diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index dd9075d..0000000 --- a/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -sonar.projectKey=lib-em-php-lti-events diff --git a/src/Factory/LtiSerializerFactory.php b/src/Factory/LtiSerializerFactory.php index bcede59..0e294e4 100644 --- a/src/Factory/LtiSerializerFactory.php +++ b/src/Factory/LtiSerializerFactory.php @@ -4,6 +4,7 @@ namespace OAT\Library\EnvironmentManagementLtiEvents\Factory; +use DateTimeInterface; use OAT\Library\EnvironmentManagementLtiEvents\Normalizer\Ags\LineItemNormalizer; use OAT\Library\EnvironmentManagementLtiEvents\Normalizer\Ags\ScoreNormalizer; use OAT\Library\EnvironmentManagementLtiEvents\Normalizer\Ags\SubmissionReviewNormalizer; @@ -15,6 +16,7 @@ use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory; use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader; use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer; +use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\SerializerInterface; @@ -34,7 +36,8 @@ public static function create(): SerializerInterface new ScoreNormalizer(), new AcsControlNormalizer(), new ResourceLinkNormalizer(), - new DateTimeNormalizer(), + new JsonSerializableNormalizer(), + new DateTimeNormalizer([DateTimeNormalizer::FORMAT_KEY => DateTimeInterface::RFC3339_EXTENDED]), new ObjectNormalizer($classMetaDataFactory, null, null, null, $classDiscriminator), ], [ diff --git a/tests/Unit/Factory/LtiSerializerTest.php b/tests/Unit/Factory/LtiSerializerTest.php new file mode 100644 index 0000000..a848a30 --- /dev/null +++ b/tests/Unit/Factory/LtiSerializerTest.php @@ -0,0 +1,112 @@ + + */ + +declare(strict_types=1); + +namespace OAT\Library\EnvironmentManagementLtiEvents\Tests\Unit\Factory; + +use DateTimeImmutable; +use OAT\Library\EnvironmentManagementLtiEvents\Event\Ags\CreateLineItemEvent; +use OAT\Library\EnvironmentManagementLtiEvents\Event\Ags\DeleteLineItemEvent; +use OAT\Library\EnvironmentManagementLtiEvents\Event\Ags\GetLineItemEvent; +use OAT\Library\EnvironmentManagementLtiEvents\Event\Ags\ListLineItemsEvent; +use OAT\Library\EnvironmentManagementLtiEvents\Event\Ags\ListResultsEvent; +use OAT\Library\EnvironmentManagementLtiEvents\Event\Ags\PublishScoreEvent; +use OAT\Library\EnvironmentManagementLtiEvents\Event\Ags\UpdateLineItemEvent; +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\EnvironmentManagementLtiEvents\Event\Core\RequestEvent; +use OAT\Library\EnvironmentManagementLtiEvents\Event\EventInterface; +use OAT\Library\EnvironmentManagementLtiEvents\Event\Nrps\GetContextMembershipEvent; +use OAT\Library\EnvironmentManagementLtiEvents\Event\Nrps\GetResourceLinkMembershipEvent; +use OAT\Library\EnvironmentManagementLtiEvents\Event\Proctoring\SendControlEvent; +use OAT\Library\EnvironmentManagementLtiEvents\Factory\LtiSerializerFactory; +use OAT\Library\Lti1p3Ags\Model\LineItem\LineItem; +use OAT\Library\Lti1p3Ags\Model\Score\Score; +use OAT\Library\Lti1p3Core\Resource\LtiResourceLink\LtiResourceLink; +use OAT\Library\Lti1p3Proctoring\Model\AcsControl; +use OAT\Library\Lti1p3Proctoring\Model\AcsControlInterface; +use PHPUnit\Framework\TestCase; +use Symfony\Component\Serializer\Encoder\JsonEncoder; +use Symfony\Component\Serializer\SerializerInterface; + +class LtiSerializerTest extends TestCase +{ + private SerializerInterface $sut; + + /** + * @before + */ + public function init(): void + { + $this->sut = LtiSerializerFactory::create(); + } + + /** + * @dataProvider dataProvider + */ + public function testEventSerialization(EventInterface $event): void + { + $this->assertEquals( + $event, + $this->sut->deserialize( + $this->sut->serialize($event, JsonEncoder::FORMAT), + EventInterface::class, + JsonEncoder::FORMAT + ) + ); + } + + public function dataProvider(): array + { + return [ + [new CreateLineItemEvent('test', new LineItem(1, 'test'), 'https://example.com')], + [new DeleteLineItemEvent('test', 'https://example.com')], + [new GetLineItemEvent('test', 'https://example.com')], + [new ListLineItemsEvent('test', 'https://example.com')], + [new ListResultsEvent('test', 'https://example.com')], + [new PublishScoreEvent('test', new Score('test'), 'https://example.com')], + [new UpdateLineItemEvent('test', new LineItem(1, 'test'))], + [new DeleteResultEvent('test', 'https://example.com', 'test')], + [new ReadResultEvent('test', 'https://example.com', 'test')], + [new ReplaceResultEvent('test', 'https://example.com', 'test', 1)], + [new SendBasicOutcomeEvent('test', 'https://example.com', '')], + [new RequestEvent('test', 'GET', 'https://example.com')], + [new GetContextMembershipEvent('test', 'https://example.com')], + [new GetResourceLinkMembershipEvent('test', 'https://example.com', 'test')], + [ + new SendControlEvent( + 'test', + new AcsControl( + new LtiResourceLink('https://example.com'), + 'test', + AcsControlInterface::ACTION_PAUSE, + DateTimeImmutable::createFromFormat('U.u', sprintf('%.3f', microtime(true))) + ), + 'https://example.com' + ), + ], + ]; + } +}