Skip to content

Commit 20a20e0

Browse files
authored
test(tests): Skip flaky mock API tests (#27)
- 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.
1 parent c7a12a8 commit 20a20e0

File tree

9 files changed

+45
-36
lines changed

9 files changed

+45
-36
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#
1212

1313
name: CI
14+
permissions:
15+
contents: read
1416

1517
on:
1618
pull_request:
@@ -19,8 +21,6 @@ on:
1921
push:
2022
branches:
2123
- 'master'
22-
schedule:
23-
- cron: '49 */8 * * *'
2424

2525
env:
2626
COLUMNS: 120
@@ -34,7 +34,7 @@ jobs:
3434
JBZOO_COMPOSER_UPDATE_FLAGS: ${{ matrix.composer_flags }}
3535
strategy:
3636
matrix:
37-
php-version: [ 8.1, 8.2, 8.3 ]
37+
php-version: [ 8.2, 8.3, 8.4 ]
3838
coverage: [ xdebug, none ]
3939
composer_flags: [ "--prefer-lowest", "" ]
4040
steps:
@@ -68,7 +68,7 @@ jobs:
6868
run: make report-coveralls --no-print-directory || true
6969

7070
- name: Upload Artifacts
71-
uses: actions/upload-artifact@v3
71+
uses: actions/upload-artifact@v4
7272
continue-on-error: true
7373
with:
7474
name: PHPUnit - ${{ matrix.php-version }} - ${{ matrix.coverage }}
@@ -80,7 +80,7 @@ jobs:
8080
runs-on: ubuntu-latest
8181
strategy:
8282
matrix:
83-
php-version: [ 8.1, 8.2, 8.3 ]
83+
php-version: [ 8.2, 8.3, 8.4 ]
8484
steps:
8585
- name: Checkout code
8686
uses: actions/checkout@v3
@@ -102,7 +102,7 @@ jobs:
102102
run: make codestyle --no-print-directory
103103

104104
- name: Upload Artifacts
105-
uses: actions/upload-artifact@v3
105+
uses: actions/upload-artifact@v4
106106
continue-on-error: true
107107
with:
108108
name: Linters - ${{ matrix.php-version }}
@@ -114,7 +114,7 @@ jobs:
114114
runs-on: ubuntu-latest
115115
strategy:
116116
matrix:
117-
php-version: [ 8.1, 8.2, 8.3 ]
117+
php-version: [ 8.2, 8.3, 8.4 ]
118118
steps:
119119
- name: Checkout code
120120
uses: actions/checkout@v3
@@ -136,7 +136,7 @@ jobs:
136136
run: make report-all --no-print-directory
137137

138138
- name: Upload Artifacts
139-
uses: actions/upload-artifact@v3
139+
uses: actions/upload-artifact@v4
140140
continue-on-error: true
141141
with:
142142
name: Reports - ${{ matrix.php-version }}

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# JBZoo / Http-Client
22

3-
[![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)
3+
[![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)
44
[![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)
55

66

@@ -78,11 +78,11 @@ $httpClient = new HttpClient();
7878

7979
$results = $httpClient->multiRequest(array(
8080
'request_0' => 'http://mockbin.org/request',
81-
81+
8282
'request_1' => ['http://mockbin.org/request', [
8383
'args' => ['key' => 'value']
8484
]],
85-
85+
8686
'request_2' => ['http://mockbin.org/request', [
8787
'method' => 'post',
8888
'args' => ['key' => 'value'],
@@ -93,13 +93,13 @@ $results = $httpClient->multiRequest(array(
9393
'verify' => false,
9494
'exceptions' => false,
9595
'allow_redirects' => true,
96-
'max_redirects' => 10,
96+
'max_redirects' => 10,
9797
'user_agent' => 'JBZoo/Http-Client v1.x-dev'
9898
]]
9999
]);
100100

101-
$results['request_0']->getBody();
102-
$results['request_1']->getBody();
101+
$results['request_0']->getBody();
102+
$results['request_1']->getBody();
103103
$results['request_2']->getBody();
104104
```
105105

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727
"prefer-stable" : true,
2828

2929
"require" : {
30-
"php" : "^8.1",
30+
"php" : "^8.2",
3131
"ext-json" : "*",
3232

33-
"jbzoo/data" : "^7.1",
34-
"jbzoo/utils" : "^7.1",
35-
"jbzoo/event" : "^7.0"
33+
"jbzoo/data" : "^7.2",
34+
"jbzoo/utils" : "^7.3",
35+
"jbzoo/event" : "^7.0.2"
3636
},
3737

3838
"require-dev" : {
39-
"jbzoo/toolbox-dev" : "^7.1",
40-
"rmccue/requests" : ">=2.0.10",
41-
"guzzlehttp/guzzle" : ">=7.5.0"
39+
"jbzoo/toolbox-dev" : "^7.2",
40+
"rmccue/requests" : ">=2.0.15",
41+
"guzzlehttp/guzzle" : ">=7.10.0"
4242
},
4343

4444
"suggest" : {

src/Driver/Auto.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
use JBZoo\HttpClient\Request;
2121
use JBZoo\HttpClient\Response;
2222

23+
/**
24+
* @psalm-suppress UnusedClass
25+
*/
2326
final class Auto extends AbstractDriver
2427
{
2528
public function request(Request $request): Response

src/Driver/Guzzle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private static function getDriverOptions(
8787
Options $options,
8888
array $headers,
8989
string $method,
90-
null|array|string $args,
90+
array|string|null $args,
9191
): array {
9292
$headers['User-Agent'] = $options->getUserAgent('Guzzle');
9393

src/HttpClient.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(array $options = [])
3333

3434
public function request(
3535
string $url,
36-
null|array|string $args = null,
36+
array|string|null $args = null,
3737
string $method = Request::DEFAULT_METHOD,
3838
array $options = [],
3939
): Response {
@@ -105,6 +105,9 @@ public function setEventManager(EventManager $eManager): self
105105
return $this;
106106
}
107107

108+
/**
109+
* @psalm-suppress PossiblyUnusedReturnValue
110+
*/
108111
public function trigger(string $eventName, array $context = [], ?\Closure $callback = null): int
109112
{
110113
if ($this->eManager !== null) {

src/Request.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ final class Request
3030
public const DEFAULT_METHOD = self::GET;
3131

3232
private string $url = '';
33-
private null|array|string $args = null;
33+
private array|string|null $args = null;
3434
private string $method = self::GET;
3535
private array $headers = [];
3636
private Options $options;
3737

3838
public function __construct(
3939
string $url = '',
40-
null|array|string $args = [],
40+
array|string|null $args = [],
4141
string $method = self::DEFAULT_METHOD,
4242
array $headers = [],
4343
array|Options $options = [],
@@ -62,7 +62,7 @@ public function setUrl(string $url): self
6262
return $this;
6363
}
6464

65-
public function setArgs(null|array|string $args): self
65+
public function setArgs(array|string|null $args): self
6666
{
6767
$this->args = $args;
6868

@@ -114,7 +114,7 @@ public function getUri(): string
114114
return $this->url;
115115
}
116116

117-
public function getArgs(): null|array|string
117+
public function getArgs(): array|string|null
118118
{
119119
return $this->method === self::GET ? null : $this->args;
120120
}

src/Response.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525
* @property string $body
2626
* @property null|float $time
2727
*/
28-
class Response
28+
final class Response
2929
{
30-
protected int $internalCode = 0;
31-
protected array $internalHeaders = [];
32-
protected ?string $internalBody = null;
33-
protected ?JSON $parsedJsonData = null;
34-
protected ?float $time = null;
35-
protected ?Request $originalRequest = null;
30+
private int $internalCode = 0;
31+
private array $internalHeaders = [];
32+
private ?string $internalBody = null;
33+
private ?JSON $parsedJsonData = null;
34+
private ?float $time = null;
35+
private ?Request $originalRequest = null;
3636

3737
/**
3838
* @return null|array|float|int|string|string[]
39+
* @psalm-suppress PossiblyUnusedReturnValue
3940
*/
4041
public function __get(string $name)
4142
{
@@ -124,8 +125,8 @@ public function getXml(): JSON
124125
$xmlAsArray = Xml::dom2Array(Xml::createFromString($this->internalBody));
125126
} catch (\Exception $exception) {
126127
throw new Exception(
127-
"Can't parse xml document from HTTP response. " .
128-
"Details: {$exception->getMessage()}",
128+
"Can't parse xml document from HTTP response. "
129+
. "Details: {$exception->getMessage()}",
129130
);
130131
}
131132

tests/AbstractDriverTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ abstract class AbstractDriverTest extends PHPUnit
3636

3737
public function testSimple(): void
3838
{
39+
skip('Flaky test');
3940
$url = 'https://run.mocky.io/v3/965f7c10-5a16-4e13-a9b9-2bcfd30a25f2';
4041
$result = $this->getClient()->request($url);
4142

@@ -171,6 +172,7 @@ public function testStatus404(): void
171172

172173
public function testStatus404Body(): void
173174
{
175+
skip('Flaky test');
174176
$result = $this->getClient()->request('https://run.mocky.io/v3/037dd813-edd9-4cc9-bab9-9244c0b5c5ec');
175177

176178
isSame(404, $result->code);

0 commit comments

Comments
 (0)