diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index c02a1fb..66febb3 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php: [ '8.0', '8.1' ] + php: [ '8.1', '8.2' ] composer-flags: [ '', '--prefer-lowest' ] steps: @@ -31,7 +31,6 @@ jobs: - name: Check coding standards run: dev/bin/php composer lint -- --ansi --diff --dry-run --using-cache=no --verbose - if: matrix.php < 8.1 - name: Clear docker volumes if: ${{ always() }} diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 59e907c..6865222 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -18,7 +18,14 @@ 'array_syntax' => ['syntax' => 'short'], 'no_unused_imports' => true, 'blank_line_after_namespace' => true, - 'braces' => true, + 'single_space_around_construct' => true, + 'control_structure_braces' => true, + 'curly_braces_position' => true, + 'control_structure_continuation_position' => true, + 'declare_parentheses' => true, + 'statement_indentation' => true, + 'no_multiple_statements_per_line' => true, + 'no_extra_blank_lines' => true, 'class_definition' => true, 'declare_strict_types' => true, 'elseif' => true, diff --git a/README.md b/README.md index 73f4e63..4d96f54 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ composer require petersons/d2l-client ## Requirements -* [PHP 8.0](https://www.php.net/releases/8_0_0.php) or greater +* [PHP 8.1](https://www.php.net/releases/8_1_0.php) or greater ## Usage example @@ -78,7 +78,7 @@ Docker dependencies for local development: 0. Build the Docker image ```bash - dev/bin/docker-compose build --build-arg PHP_VERSION=8.0 php + dev/bin/docker-compose build --build-arg PHP_VERSION=8.1 php ``` 0. Install library dependencies diff --git a/composer.json b/composer.json index e711dc9..c04434a 100644 --- a/composer.json +++ b/composer.json @@ -13,19 +13,20 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "ext-curl": "*", "ext-simplexml": "*", "illuminate/collections": "^8.56 || ^9.0", "illuminate/contracts": "^8.0 || ^9.0", "illuminate/support": "^8.0 || ^9.0", - "nesbot/carbon": "^2.55", - "symfony/http-client": "^5.4 || ^6.0" + "nesbot/carbon": "^2.67", + "symfony/http-client": "^5.4.21 || ^6.3" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.5", + "friendsofphp/php-cs-fixer": "^3.17", "illuminate/container": "^8.62 || ^9.0", - "phpunit/phpunit": "^9.5.13" + "phpunit/phpunit": "^9.6.9", + "nikic/php-parser": "^4.15.5" }, "autoload": { "psr-4": { diff --git a/dev/docker/Dockerfile b/dev/docker/Dockerfile index afacf59..0c09e0f 100644 --- a/dev/docker/Dockerfile +++ b/dev/docker/Dockerfile @@ -1,10 +1,10 @@ -ARG PHP_VERSION=8.0 +ARG PHP_VERSION=8.1 FROM php:${PHP_VERSION}-cli-alpine LABEL maintainer="Antonio Pauletich " -ARG COMPOSER_VERSION=2.2.4 -ARG XDEBUG_VERSION=3.1.2 +ARG COMPOSER_VERSION=2.5.8 +ARG XDEBUG_VERSION=3.2.1 ENV XDEBUG_START_WITH_REQUEST "no" @@ -17,6 +17,7 @@ RUN apk add --update --no-cache --virtual .build-deps \ ${PHPIZE_DEPS} \ libzip-dev \ zlib-dev \ + linux-headers \ && docker-php-ext-install -j $(getconf _NPROCESSORS_ONLN) \ zip \ && pecl install \ diff --git a/src/D2LSigner.php b/src/D2LSigner.php index 955b002..a14c7bd 100644 --- a/src/D2LSigner.php +++ b/src/D2LSigner.php @@ -12,7 +12,7 @@ final class D2LSigner * * Both the key and data parameters should be UTF-8 strings. * - * This method first generates a SHA-256-based HMAC of the provided base + * This method first generates an SHA-256-based HMAC of the provided base * string data. Then, it renders the result URL-safe by Base64-encoding it, * and removing all equal-sign characters, replacing all plus-sign characters * with hyphens, and replacing all forward-slash characters with underbars. @@ -24,7 +24,7 @@ final class D2LSigner */ public static function getBase64HashString(string $key, string $data): string { - $return = hash_hmac('sha256', utf8_encode($data), utf8_encode($key), true); + $return = hash_hmac('sha256', $data, $key, true); $return = base64_encode($return); $return = str_replace('=', '', $return); diff --git a/tests/Unit/SymfonyHttpClientTest.php b/tests/Unit/SymfonyHttpClientTest.php index 5fa49d9..2af7072 100644 --- a/tests/Unit/SymfonyHttpClientTest.php +++ b/tests/Unit/SymfonyHttpClientTest.php @@ -195,7 +195,7 @@ public function testFetchingUserByEmail(): void $userJsonResponse = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . 'user_show_response.json'); $callback = function (string $method, string $url, array $options) use ($userJsonResponse): MockResponse { - if ('GET' === $method && 'https://petersonstest.brightspace.com/d2l/api/lp/1.30/users/?x_a=baz&x_b=foo&x_c=FGDZzyI8CiSOWa-c6hr_rcwj4fY58CFqzuvWiapEyQY&x_d=OjWXyQhHjYt2qgfJEDFezAIZfYpy9jyb3Jlzknywe7o&x_t=1615390200&externalEmail=petersons_1296_0%40email.fake' === $url) { + if ('GET' === $method && 'https://petersonstest.brightspace.com/d2l/api/lp/1.30/users/?x_a=baz&x_b=foo&x_c=FGDZzyI8CiSOWa-c6hr_rcwj4fY58CFqzuvWiapEyQY&x_d=OjWXyQhHjYt2qgfJEDFezAIZfYpy9jyb3Jlzknywe7o&x_t=1615390200&externalEmail=petersons_1296_0@email.fake' === $url) { return new MockResponse($userJsonResponse); } @@ -229,7 +229,7 @@ public function testFetchingUserByEmailWhenD2LReturnsForbiddenResponse(): void $this->freezeTime(); $callback = function (string $method, string $url, array $options): MockResponse { - if ('GET' === $method && 'https://petersonstest.brightspace.com/d2l/api/lp/1.30/users/?x_a=baz&x_b=foo&x_c=FGDZzyI8CiSOWa-c6hr_rcwj4fY58CFqzuvWiapEyQY&x_d=OjWXyQhHjYt2qgfJEDFezAIZfYpy9jyb3Jlzknywe7o&x_t=1615390200&externalEmail=petersons_1296_0%40email.fake' === $url) { + if ('GET' === $method && 'https://petersonstest.brightspace.com/d2l/api/lp/1.30/users/?x_a=baz&x_b=foo&x_c=FGDZzyI8CiSOWa-c6hr_rcwj4fY58CFqzuvWiapEyQY&x_d=OjWXyQhHjYt2qgfJEDFezAIZfYpy9jyb3Jlzknywe7o&x_t=1615390200&externalEmail=petersons_1296_0@email.fake' === $url) { return new MockResponse('', ['http_code' => 403]); } @@ -242,7 +242,7 @@ public function testFetchingUserByEmailWhenD2LReturnsForbiddenResponse(): void $this->expectExceptionObject( new ApiException( - 'HTTP 403 returned for "https://petersonstest.brightspace.com/d2l/api/lp/1.30/users/?x_a=baz&x_b=foo&x_c=FGDZzyI8CiSOWa-c6hr_rcwj4fY58CFqzuvWiapEyQY&x_d=OjWXyQhHjYt2qgfJEDFezAIZfYpy9jyb3Jlzknywe7o&x_t=1615390200&externalEmail=petersons_1296_0%40email.fake".', + 'HTTP 403 returned for "https://petersonstest.brightspace.com/d2l/api/lp/1.30/users/?x_a=baz&x_b=foo&x_c=FGDZzyI8CiSOWa-c6hr_rcwj4fY58CFqzuvWiapEyQY&x_d=OjWXyQhHjYt2qgfJEDFezAIZfYpy9jyb3Jlzknywe7o&x_t=1615390200&externalEmail=petersons_1296_0@email.fake".', 403 ) ); @@ -255,7 +255,7 @@ public function testFetchingUserByEmailWhenD2LReturnsNotFoundResponse(): void $this->freezeTime(); $callback = function (string $method, string $url, array $options): MockResponse { - if ('GET' === $method && 'https://petersonstest.brightspace.com/d2l/api/lp/1.30/users/?x_a=baz&x_b=foo&x_c=FGDZzyI8CiSOWa-c6hr_rcwj4fY58CFqzuvWiapEyQY&x_d=OjWXyQhHjYt2qgfJEDFezAIZfYpy9jyb3Jlzknywe7o&x_t=1615390200&externalEmail=petersons_1296_0%40email.fake' === $url) { + if ('GET' === $method && 'https://petersonstest.brightspace.com/d2l/api/lp/1.30/users/?x_a=baz&x_b=foo&x_c=FGDZzyI8CiSOWa-c6hr_rcwj4fY58CFqzuvWiapEyQY&x_d=OjWXyQhHjYt2qgfJEDFezAIZfYpy9jyb3Jlzknywe7o&x_t=1615390200&externalEmail=petersons_1296_0@email.fake' === $url) { return new MockResponse('', ['http_code' => 404]); } @@ -268,7 +268,7 @@ public function testFetchingUserByEmailWhenD2LReturnsNotFoundResponse(): void $this->expectExceptionObject( new ApiException( - 'HTTP 404 returned for "https://petersonstest.brightspace.com/d2l/api/lp/1.30/users/?x_a=baz&x_b=foo&x_c=FGDZzyI8CiSOWa-c6hr_rcwj4fY58CFqzuvWiapEyQY&x_d=OjWXyQhHjYt2qgfJEDFezAIZfYpy9jyb3Jlzknywe7o&x_t=1615390200&externalEmail=petersons_1296_0%40email.fake".', + 'HTTP 404 returned for "https://petersonstest.brightspace.com/d2l/api/lp/1.30/users/?x_a=baz&x_b=foo&x_c=FGDZzyI8CiSOWa-c6hr_rcwj4fY58CFqzuvWiapEyQY&x_d=OjWXyQhHjYt2qgfJEDFezAIZfYpy9jyb3Jlzknywe7o&x_t=1615390200&externalEmail=petersons_1296_0@email.fake".', 404 ) );