From 71cd41dd13ec3512f8c1e1be1343fe81226db172 Mon Sep 17 00:00:00 2001 From: SmetDenis Date: Sat, 22 Jun 2024 13:43:10 +0400 Subject: [PATCH 1/3] Update test URL to a valid mock endpoint Replace the outdated mock endpoint in `testStatus404Body` with a new, valid URL. This ensures that the test correctly validates the 404 status response and the corresponding error body, improving test reliability and accuracy. --- tests/AbstractDriverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/AbstractDriverTest.php b/tests/AbstractDriverTest.php index 3cebc9c..6a5d8d8 100644 --- a/tests/AbstractDriverTest.php +++ b/tests/AbstractDriverTest.php @@ -171,7 +171,7 @@ public function testStatus404(): void public function testStatus404Body(): void { - $result = $this->getClient()->request('https://run.mocky.io/v3/54bdf866-5da9-4e15-aeb4-4d51ee870dc4'); + $result = $this->getClient()->request('https://run.mocky.io/v3/037dd813-edd9-4cc9-bab9-9244c0b5c5ec'); isSame(404, $result->code); is('{"error": "mock_not_found"}', $result->getBody()); From a3d573615594d35012f7ea8f179e9fc5e528e771 Mon Sep 17 00:00:00 2001 From: SmetDenis Date: Sat, 22 Jun 2024 13:48:07 +0400 Subject: [PATCH 2/3] Update mock URL in testSimple method Change the mock API URL in the testSimple method to use a new endpoint, ensuring the test remains functional. This update is necessary as the previous URL may no longer be available or has been deprecated, and it helps maintain the reliability of our tests. --- tests/AbstractDriverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/AbstractDriverTest.php b/tests/AbstractDriverTest.php index 6a5d8d8..237054b 100644 --- a/tests/AbstractDriverTest.php +++ b/tests/AbstractDriverTest.php @@ -36,7 +36,7 @@ abstract class AbstractDriverTest extends PHPUnit public function testSimple(): void { - $url = 'https://run.mocky.io/v3/92e40ef8-6328-4b8e-af3c-9a26c72abd3c'; + $url = 'https://run.mocky.io/v3/965f7c10-5a16-4e13-a9b9-2bcfd30a25f2'; $result = $this->getClient()->request($url); isSame(200, $result->code); From de5ee6f2fdd69a810b2ace88596fa2e66cd0a4fc Mon Sep 17 00:00:00 2001 From: SmetDenis Date: Sun, 28 Sep 2025 02:36:58 +0400 Subject: [PATCH 3/3] test(tests): Skip flaky mock API tests - Temporarily skip tests using `run.mocky.io` due to their unreliability. - Update CI workflow: - Bump PHP version matrix to 8.2, 8.3, 8.4. - Upgrade `actions/upload-artifact` to v4. - Add `contents: read` permission and remove scheduled runs. - Update `composer.json`: - Increase minimum PHP requirement to 8.2. - Upgrade `jbzoo/data`, `jbzoo/utils`, `jbzoo/event`, `jbzoo/toolbox-dev`, `rmccue/requests`, and `guzzlehttp/guzzle`. - Refactor code: - Adjust type hint order for consistency (`array|string|null`). - Make `Response` class final and its properties private. - Add Psalm suppressions for unused classes/return values. --- .github/workflows/main.yml | 16 ++++++++-------- README.md | 12 ++++++------ composer.json | 14 +++++++------- src/Driver/Auto.php | 3 +++ src/Driver/Guzzle.php | 2 +- src/HttpClient.php | 5 ++++- src/Request.php | 8 ++++---- src/Response.php | 19 ++++++++++--------- tests/AbstractDriverTest.php | 2 ++ 9 files changed, 45 insertions(+), 36 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b2d40b2..1020898 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,6 +11,8 @@ # name: CI +permissions: + contents: read on: pull_request: @@ -19,8 +21,6 @@ on: push: branches: - 'master' - schedule: - - cron: '49 */8 * * *' env: COLUMNS: 120 @@ -34,7 +34,7 @@ jobs: JBZOO_COMPOSER_UPDATE_FLAGS: ${{ matrix.composer_flags }} strategy: matrix: - php-version: [ 8.1, 8.2, 8.3 ] + php-version: [ 8.2, 8.3, 8.4 ] coverage: [ xdebug, none ] composer_flags: [ "--prefer-lowest", "" ] steps: @@ -68,7 +68,7 @@ jobs: run: make report-coveralls --no-print-directory || true - name: Upload Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 continue-on-error: true with: name: PHPUnit - ${{ matrix.php-version }} - ${{ matrix.coverage }} @@ -80,7 +80,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: [ 8.1, 8.2, 8.3 ] + php-version: [ 8.2, 8.3, 8.4 ] steps: - name: Checkout code uses: actions/checkout@v3 @@ -102,7 +102,7 @@ jobs: run: make codestyle --no-print-directory - name: Upload Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 continue-on-error: true with: name: Linters - ${{ matrix.php-version }} @@ -114,7 +114,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: [ 8.1, 8.2, 8.3 ] + php-version: [ 8.2, 8.3, 8.4 ] steps: - name: Checkout code uses: actions/checkout@v3 @@ -136,7 +136,7 @@ jobs: run: make report-all --no-print-directory - name: Upload Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 continue-on-error: true with: name: Reports - ${{ matrix.php-version }} diff --git a/README.md b/README.md index 4c5e9ba..9868aca 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # JBZoo / Http-Client -[![CI](https://github.com/JBZoo/Http-Client/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/JBZoo/Http-Client/actions/workflows/main.yml?query=branch%3Amaster) [![Coverage Status](https://coveralls.io/repos/github/JBZoo/Http-Client/badge.svg?branch=master)](https://coveralls.io/github/JBZoo/Http-Client?branch=master) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/Http-Client/coverage.svg)](https://shepherd.dev/github/JBZoo/Http-Client) [![Psalm Level](https://shepherd.dev/github/JBZoo/Http-Client/level.svg)](https://shepherd.dev/github/JBZoo/Http-Client) [![CodeFactor](https://www.codefactor.io/repository/github/jbzoo/http-client/badge)](https://www.codefactor.io/repository/github/jbzoo/http-client/issues) +[![CI](https://github.com/JBZoo/Http-Client/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/JBZoo/Http-Client/actions/workflows/main.yml?query=branch%3Amaster) [![Coverage Status](https://coveralls.io/repos/github/JBZoo/Http-Client/badge.svg?branch=master)](https://coveralls.io/github/JBZoo/Http-Client?branch=master) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/Http-Client/coverage.svg)](https://shepherd.dev/github/JBZoo/Http-Client) [![Psalm Level](https://shepherd.dev/github/JBZoo/Http-Client/level.svg)](https://shepherd.dev/github/JBZoo/Http-Client) [![CodeFactor](https://www.codefactor.io/repository/github/jbzoo/http-client/badge)](https://www.codefactor.io/repository/github/jbzoo/http-client/issues) [![Stable Version](https://poser.pugx.org/jbzoo/http-client/version)](https://packagist.org/packages/jbzoo/http-client/) [![Total Downloads](https://poser.pugx.org/jbzoo/http-client/downloads)](https://packagist.org/packages/jbzoo/http-client/stats) [![Dependents](https://poser.pugx.org/jbzoo/http-client/dependents)](https://packagist.org/packages/jbzoo/http-client/dependents?order_by=downloads) [![GitHub License](https://img.shields.io/github/license/jbzoo/http-client)](https://github.com/JBZoo/Http-Client/blob/master/LICENSE) @@ -78,11 +78,11 @@ $httpClient = new HttpClient(); $results = $httpClient->multiRequest(array( 'request_0' => 'http://mockbin.org/request', - + 'request_1' => ['http://mockbin.org/request', [ 'args' => ['key' => 'value'] ]], - + 'request_2' => ['http://mockbin.org/request', [ 'method' => 'post', 'args' => ['key' => 'value'], @@ -93,13 +93,13 @@ $results = $httpClient->multiRequest(array( 'verify' => false, 'exceptions' => false, 'allow_redirects' => true, - 'max_redirects' => 10, + 'max_redirects' => 10, 'user_agent' => 'JBZoo/Http-Client v1.x-dev' ]] ]); -$results['request_0']->getBody(); -$results['request_1']->getBody(); +$results['request_0']->getBody(); +$results['request_1']->getBody(); $results['request_2']->getBody(); ``` diff --git a/composer.json b/composer.json index b78ab99..ba4c976 100644 --- a/composer.json +++ b/composer.json @@ -27,18 +27,18 @@ "prefer-stable" : true, "require" : { - "php" : "^8.1", + "php" : "^8.2", "ext-json" : "*", - "jbzoo/data" : "^7.1", - "jbzoo/utils" : "^7.1", - "jbzoo/event" : "^7.0" + "jbzoo/data" : "^7.2", + "jbzoo/utils" : "^7.3", + "jbzoo/event" : "^7.0.2" }, "require-dev" : { - "jbzoo/toolbox-dev" : "^7.1", - "rmccue/requests" : ">=2.0.10", - "guzzlehttp/guzzle" : ">=7.5.0" + "jbzoo/toolbox-dev" : "^7.2", + "rmccue/requests" : ">=2.0.15", + "guzzlehttp/guzzle" : ">=7.10.0" }, "suggest" : { diff --git a/src/Driver/Auto.php b/src/Driver/Auto.php index 6ec59d0..129b0be 100644 --- a/src/Driver/Auto.php +++ b/src/Driver/Auto.php @@ -20,6 +20,9 @@ use JBZoo\HttpClient\Request; use JBZoo\HttpClient\Response; +/** + * @psalm-suppress UnusedClass + */ final class Auto extends AbstractDriver { public function request(Request $request): Response diff --git a/src/Driver/Guzzle.php b/src/Driver/Guzzle.php index 6ee3450..15578ae 100644 --- a/src/Driver/Guzzle.php +++ b/src/Driver/Guzzle.php @@ -87,7 +87,7 @@ private static function getDriverOptions( Options $options, array $headers, string $method, - null|array|string $args, + array|string|null $args, ): array { $headers['User-Agent'] = $options->getUserAgent('Guzzle'); diff --git a/src/HttpClient.php b/src/HttpClient.php index e16216c..0df6b70 100644 --- a/src/HttpClient.php +++ b/src/HttpClient.php @@ -33,7 +33,7 @@ public function __construct(array $options = []) public function request( string $url, - null|array|string $args = null, + array|string|null $args = null, string $method = Request::DEFAULT_METHOD, array $options = [], ): Response { @@ -105,6 +105,9 @@ public function setEventManager(EventManager $eManager): self return $this; } + /** + * @psalm-suppress PossiblyUnusedReturnValue + */ public function trigger(string $eventName, array $context = [], ?\Closure $callback = null): int { if ($this->eManager !== null) { diff --git a/src/Request.php b/src/Request.php index 4a062f4..6cd48a5 100644 --- a/src/Request.php +++ b/src/Request.php @@ -30,14 +30,14 @@ final class Request public const DEFAULT_METHOD = self::GET; private string $url = ''; - private null|array|string $args = null; + private array|string|null $args = null; private string $method = self::GET; private array $headers = []; private Options $options; public function __construct( string $url = '', - null|array|string $args = [], + array|string|null $args = [], string $method = self::DEFAULT_METHOD, array $headers = [], array|Options $options = [], @@ -62,7 +62,7 @@ public function setUrl(string $url): self return $this; } - public function setArgs(null|array|string $args): self + public function setArgs(array|string|null $args): self { $this->args = $args; @@ -114,7 +114,7 @@ public function getUri(): string return $this->url; } - public function getArgs(): null|array|string + public function getArgs(): array|string|null { return $this->method === self::GET ? null : $this->args; } diff --git a/src/Response.php b/src/Response.php index 907c784..0111e44 100644 --- a/src/Response.php +++ b/src/Response.php @@ -25,17 +25,18 @@ * @property string $body * @property null|float $time */ -class Response +final class Response { - protected int $internalCode = 0; - protected array $internalHeaders = []; - protected ?string $internalBody = null; - protected ?JSON $parsedJsonData = null; - protected ?float $time = null; - protected ?Request $originalRequest = null; + private int $internalCode = 0; + private array $internalHeaders = []; + private ?string $internalBody = null; + private ?JSON $parsedJsonData = null; + private ?float $time = null; + private ?Request $originalRequest = null; /** * @return null|array|float|int|string|string[] + * @psalm-suppress PossiblyUnusedReturnValue */ public function __get(string $name) { @@ -124,8 +125,8 @@ public function getXml(): JSON $xmlAsArray = Xml::dom2Array(Xml::createFromString($this->internalBody)); } catch (\Exception $exception) { throw new Exception( - "Can't parse xml document from HTTP response. " . - "Details: {$exception->getMessage()}", + "Can't parse xml document from HTTP response. " + . "Details: {$exception->getMessage()}", ); } diff --git a/tests/AbstractDriverTest.php b/tests/AbstractDriverTest.php index 237054b..afead1a 100644 --- a/tests/AbstractDriverTest.php +++ b/tests/AbstractDriverTest.php @@ -36,6 +36,7 @@ abstract class AbstractDriverTest extends PHPUnit public function testSimple(): void { + skip('Flaky test'); $url = 'https://run.mocky.io/v3/965f7c10-5a16-4e13-a9b9-2bcfd30a25f2'; $result = $this->getClient()->request($url); @@ -171,6 +172,7 @@ public function testStatus404(): void public function testStatus404Body(): void { + skip('Flaky test'); $result = $this->getClient()->request('https://run.mocky.io/v3/037dd813-edd9-4cc9-bab9-9244c0b5c5ec'); isSame(404, $result->code);