From 24d360d56ef4fe4aad49cb7af70dc1009d684fc9 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 21 Aug 2025 15:20:23 +0200 Subject: [PATCH 1/4] Fix GitHub Actions --- .github/workflows/coding-standards.yml | 4 ++-- .github/workflows/continuous-integration.yml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 29ef794..84f874e 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -11,7 +11,7 @@ on: jobs: coding-standards: name: "CS Fixer (PHP ${{ matrix.php }})" - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-latest" strategy: matrix: @@ -20,7 +20,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v4" + uses: "actions/checkout@v5" - name: "Install PHP" uses: "shivammathur/setup-php@v2" diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index d267576..31eb003 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -14,7 +14,7 @@ env: jobs: phpunit: name: "PHPUnit (PHP ${{ matrix.php }})" - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-latest" strategy: matrix: @@ -26,7 +26,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v4" + uses: "actions/checkout@v5" with: fetch-depth: 2 @@ -49,7 +49,7 @@ jobs: phpunit-coverage: name: "PHPUnit with coverage (PHP ${{ matrix.php }})" - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-latest" strategy: matrix: @@ -58,7 +58,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v4" + uses: "actions/checkout@v5" with: fetch-depth: 2 From 391f90fd73052de11ee7d926f8d03c3891731c8c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 21 Aug 2025 15:33:22 +0200 Subject: [PATCH 2/4] Fix tests --- lib/Imgur/Middleware/ErrorMiddleware.php | 11 +++++++++++ phpstan.neon | 3 +++ tests/Api/AlbumTest.php | 2 +- tests/Api/ImageTest.php | 2 ++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Imgur/Middleware/ErrorMiddleware.php b/lib/Imgur/Middleware/ErrorMiddleware.php index 85d2c43..d1b4a55 100644 --- a/lib/Imgur/Middleware/ErrorMiddleware.php +++ b/lib/Imgur/Middleware/ErrorMiddleware.php @@ -85,6 +85,17 @@ public function checkError(ResponseInterface $response): ?ResponseInterface throw new ErrorException($message, $response->getStatusCode()); } + if (\is_array($responseData) && isset($responseData['errors'])) { + $errorMessage = $responseData['errors']; + + $message = ''; + foreach ($responseData['errors'] as $error) { + $message .= $error['detail']; + } + + throw new ErrorException($message, $response->getStatusCode()); + } + throw new RuntimeException(\is_array($responseData) && isset($responseData['message']) ? $responseData['message'] : $responseData, $response->getStatusCode()); } diff --git a/phpstan.neon b/phpstan.neon index 9744cfb..88795c2 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -14,3 +14,6 @@ parameters: - message: '#Unreachable statement#' path: %currentWorkingDirectory%/tests/Api/TopicTest.php + - + message: '#Unreachable statement#' + path: %currentWorkingDirectory%/tests/Api/ImageTest.php diff --git a/tests/Api/AlbumTest.php b/tests/Api/AlbumTest.php index eb51da6..afa418d 100644 --- a/tests/Api/AlbumTest.php +++ b/tests/Api/AlbumTest.php @@ -15,7 +15,7 @@ class AlbumTest extends ApiTestCase public function testBaseReal(): void { $this->expectException(\Imgur\Exception\ErrorException::class); - $this->expectExceptionMessage('Authentication required'); + $this->expectExceptionMessage('The requester is not authorized to access the resource.'); $httpClient = new HttpClient(); $client = new Client(null, $httpClient); diff --git a/tests/Api/ImageTest.php b/tests/Api/ImageTest.php index 844c624..15c5c72 100644 --- a/tests/Api/ImageTest.php +++ b/tests/Api/ImageTest.php @@ -17,6 +17,8 @@ public function testBaseReal(): void $this->expectException(\Imgur\Exception\ErrorException::class); $this->expectExceptionMessage('Authentication required'); + $this->markTestSkipped('Image endpoint does not always return 401 with no authentication ...'); + $httpClient = new HttpClient(); $client = new Client(null, $httpClient); $image = new Image($client); From 128ef842749aee23b77a2a2b5a9402921d66767f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 21 Aug 2025 15:35:07 +0200 Subject: [PATCH 3/4] Use PHP 8.2 --- .github/workflows/coding-standards.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 84f874e..2665269 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: php: - - "7.4" + - "8.2" steps: - name: "Checkout" From 75af9edf421fe097994d390b1e873ae2b60de48b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 21 Aug 2025 15:37:31 +0200 Subject: [PATCH 4/4] CS --- lib/Imgur/Client.php | 4 ++-- lib/Imgur/Exception/MissingArgumentException.php | 2 +- phpstan.neon | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/Imgur/Client.php b/lib/Imgur/Client.php index a454dd8..246c6b5 100644 --- a/lib/Imgur/Client.php +++ b/lib/Imgur/Client.php @@ -88,7 +88,7 @@ public function setHttpClient(HttpClientInterface $httpClient): void public function getOption(string $name): ?string { if (!\array_key_exists($name, $this->options)) { - throw new InvalidArgumentException(sprintf('Undefined option called: "%s"', $name)); + throw new InvalidArgumentException(\sprintf('Undefined option called: "%s"', $name)); } return $this->options[$name]; @@ -100,7 +100,7 @@ public function getOption(string $name): ?string public function setOption(string $name, ?string $value = null): void { if (!\array_key_exists($name, $this->options)) { - throw new InvalidArgumentException(sprintf('Undefined option called: "%s"', $name)); + throw new InvalidArgumentException(\sprintf('Undefined option called: "%s"', $name)); } $this->options[$name] = $value; diff --git a/lib/Imgur/Exception/MissingArgumentException.php b/lib/Imgur/Exception/MissingArgumentException.php index d95d797..b7fc891 100644 --- a/lib/Imgur/Exception/MissingArgumentException.php +++ b/lib/Imgur/Exception/MissingArgumentException.php @@ -13,6 +13,6 @@ public function __construct($required, int $code = 0) $required = [$required]; } - parent::__construct(sprintf('One or more of required ("%s") parameters is missing!', implode('", "', $required)), $code); + parent::__construct(\sprintf('One or more of required ("%s") parameters is missing!', implode('", "', $required)), $code); } } diff --git a/phpstan.neon b/phpstan.neon index 88795c2..33a79fe 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,9 +5,7 @@ parameters: - tests bootstrapFiles: - - vendor/bin/.phpunit/phpunit-8.5-0/vendor/autoload.php - - checkMissingIterableValueType: false + - vendor/bin/.phpunit/phpunit-9.6-0/vendor/autoload.php ignoreErrors: # because the test is skipped @@ -17,3 +15,6 @@ parameters: - message: '#Unreachable statement#' path: %currentWorkingDirectory%/tests/Api/ImageTest.php + + - + identifier: missingType.iterableValue