Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b814750

Browse files
committed
version 3
1 parent f975ce1 commit b814750

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2307
-190
lines changed

‎.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
*.yml text eol=lf
55
*.dist text eol=lf
66
LICENCE text eol=lf
7-
stuff/ export-ignore
87
tests/ export-ignore
98
*.dist export-ignore

‎.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ assignees: ddrv
1515

1616
### Additional info
1717

18-
| Q | A
19-
|---------------- | ---
20-
| Library version | 1.?
21-
| PHP version | ?
22-
| Operating system | ?
18+
| Q | A|
19+
|------------------|-----|
20+
| Library version | 3.? |
21+
| PHP version | ?|
22+
| Operating system | ?|

‎.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@ jobs:
3939
- name: Check code style
4040
run: vendor/bin/phpcs
4141

42+
- name: Stat Analise
43+
run: vendor/bin/psalm
44+
4245
- name: Run test suite
4346
run: vendor/bin/phpunit

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ vendor/
22
composer.lock
33
phpcs.xml
44
phpunit.xml
5+
psalm.xml

‎README.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Mock for PSR-18 HTTP client
1212
Add package to project
1313

1414
```bash
15-
composer require --dev webclient/fake-http-client:^2.0
15+
composer require --dev webclient/fake-http-client:^3.0
1616
```
1717

1818
Set autoload
@@ -40,16 +40,56 @@ $client = new FakeHttpClient($handler);
4040

4141
$response = $client->sendRequest($request);
4242
```
43+
# Handlers
4344

44-
# Routing
45+
## SpecHandler
46+
47+
This package provides universal handler `\Webclient\Fake\Handler\SpecHandler\SpecHandler`
48+
and builder `\Webclient\Fake\Handler\SpecHandler\SpecHandlerBuilder`.
49+
With it, you can customize the client for almost any need.
50+
51+
```php
52+
<?php
53+
54+
use Psr\Http\Message\ResponseInterface;
55+
use Webclient\Fake\FakeHttpClient;
56+
use Webclient\Fake\Handler\SpecHandler\SpecHandlerBuilder;
57+
use Webclient\Fake\Handler\SpecHandler\Rule;
58+
59+
$builder = SpecHandlerBuilder::create();
60+
61+
$builder
62+
->route(function (Rule $rule) {
63+
$rule->notEqual('header.authorization', 'bearer xxx');
64+
$rule->oneOf(function (Rule $rule) {
65+
$rule->allOf(function (Rule $rule) {
66+
$rule->equal('uri.path', '/api/v1/posts');
67+
$rule->equal('method', 'POST');
68+
});
69+
$rule->allOf(function (Rule $rule) {
70+
$rule->match('uri.path', '^/api/v1/posts/([a-zA-Z0-9\-]+)$');
71+
$rule->match('method', '^(PUT|DELETE)$');
72+
});
73+
});
74+
})
75+
->response(function (ResponseInterface $response): ResponseInterface {
76+
return $response->withStatus(403);
77+
});
78+
79+
$handler = $builder->build();
80+
81+
$client = new FakeHttpClient($handler);
82+
```
83+
84+
## SimpleRoutingHandler
4585

4686
This package provides simple routing.
4787

4888
```php
4989
<?php
5090

5191
use Webclient\Fake\FakeHttpClient;
52-
use Webclient\Fake\Handler\SimpleRoutingHandler;
92+
use Webclient\Fake\Handler\SimpleRoutingHandler\SimpleRoutingHandler;
5393
use Psr\Http\Message\RequestInterface;
5494
use Psr\Http\Server\RequestHandlerInterface;
5595

‎composer.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
"ext-mbstring": "*",
1818
"psr/http-client": "^1.0",
1919
"psr/http-message": "^1.0",
20+
"psr/http-factory": "^1.0",
2021
"psr/http-server-handler": "^1.0"
2122
},
2223
"require-dev": {
23-
"psr/http-factory": "^1.0",
2424
"nyholm/psr7": "^1.5",
2525
"phpunit/phpunit": "^6.5 || ^7.5 || 8.5 || 9.5",
26-
"squizlabs/php_codesniffer": "^3.5"
26+
"squizlabs/php_codesniffer": "^3.5",
27+
"vimeo/psalm": "^4.30"
2728
},
2829
"provide": {
2930
"psr/http-client-implementation": "1.0"
@@ -35,14 +36,19 @@
3536
},
3637
"autoload-dev": {
3738
"psr-4": {
38-
"Webclient\\Stuff\\Fake\\": "stuff/",
39-
"Webclient\\Tests\\Fake\\": "tests/"
39+
"Tests\\Webclient\\Fake\\Tools\\": "tests/src",
40+
"Tests\\Webclient\\Fake\\Unit\\": "tests/unit"
4041
}
4142
},
4243
"funding": [
4344
{
4445
"type": "other",
4546
"url": "https://www.paypal.me/ddrv"
4647
}
47-
]
48+
],
49+
"config": {
50+
"allow-plugins": {
51+
"composer/package-versions-deprecated": true
52+
}
53+
}
4854
}

‎phpcs.xml.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@
1212

1313
<!-- Paths to check -->
1414
<file>src</file>
15-
<file>stuff</file>
1615
<file>tests</file>
1716
</ruleset>

‎phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<phpunit bootstrap="vendor/autoload.php" colors="true" cacheResult="false">
33
<testsuites>
44
<testsuite name="all">
5-
<directory>tests</directory>
5+
<directory>tests/unit</directory>
66
</testsuite>
77
</testsuites>
88
</phpunit>

‎psalm.xml.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="1"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
>
9+
<projectFiles>
10+
<directory name="src" />
11+
<ignoreFiles>
12+
<directory name="vendor" />
13+
</ignoreFiles>
14+
</projectFiles>
15+
</psalm>

‎src/Exception/NetworkError.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Psr\Http\Message\RequestInterface;
1010
use Throwable;
1111

12-
class NetworkError extends Exception implements NetworkExceptionInterface
12+
finalclass NetworkError extends Exception implements NetworkExceptionInterface
1313
{
1414
private RequestInterface $request;
1515

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /