Skip to content

Commit 1f2edf8

Browse files
committed
replace nyholm/psr7 to guzzlehttp/psr7
1 parent 8c0525f commit 1f2edf8

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

.phpunit.result.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:37:"PHPUnit\Runner\DefaultTestResultCache":180:{a:2:{s:7:"defects";a:1:{s:54:"Tests\Webclient\Extension\Cache\ClientTest::testClient";i:3;}s:5:"times";a:1:{s:54:"Tests\Webclient\Extension\Cache\ClientTest::testClient";d:0.012;}}}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"require-dev": {
2323
"cache/array-adapter": "^1.0",
24-
"nyholm/psr7": "^1.3",
24+
"guzzlehttp/psr7": "^1.7",
2525
"phpunit/phpunit": ">=6.5",
2626
"squizlabs/php_codesniffer": "^3.5",
2727
"webclient/fake-http-client": "^1.0"

stuff/HttpFactory.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stuff\Webclient\Extension\Cache;
6+
7+
use GuzzleHttp\Psr7\Response;
8+
use GuzzleHttp\Psr7\Stream;
9+
use Psr\Http\Message\ResponseFactoryInterface;
10+
use Psr\Http\Message\ResponseInterface;
11+
use Psr\Http\Message\StreamFactoryInterface;
12+
use Psr\Http\Message\StreamInterface;
13+
14+
class HttpFactory implements ResponseFactoryInterface, StreamFactoryInterface
15+
{
16+
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
17+
{
18+
return new Response($code, [], null, '1.1', $reasonPhrase);
19+
}
20+
21+
public function createStream(string $content = ''): StreamInterface
22+
{
23+
$resource = fopen('php://temp', 'w+');
24+
fwrite($resource, $content);
25+
rewind($resource);
26+
return $this->createStreamFromResource($resource);
27+
}
28+
29+
public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
30+
{
31+
$resource = fopen($filename, $mode);
32+
return $this->createStreamFromResource($resource);
33+
}
34+
35+
public function createStreamFromResource($resource): StreamInterface
36+
{
37+
return new Stream($resource);
38+
}
39+
}

tests/ClientTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
namespace Tests\Webclient\Extension\Cache;
66

77
use Cache\Adapter\PHPArray\ArrayCachePool;
8-
use Nyholm\Psr7\Factory\Psr17Factory;
9-
use Nyholm\Psr7\Request;
8+
use GuzzleHttp\Psr7\Request;
109
use PHPUnit\Framework\TestCase;
1110
use Psr\Http\Client\ClientExceptionInterface;
1211
use Stuff\Webclient\Extension\Cache\Handler;
12+
use Stuff\Webclient\Extension\Cache\HttpFactory;
1313
use Webclient\Extension\Cache\Client;
1414
use Webclient\Fake\Client as FakeClient;
1515

@@ -22,7 +22,7 @@ class ClientTest extends TestCase
2222
public function testClient()
2323
{
2424
$items = [];
25-
$factory = new Psr17Factory();
25+
$factory = new HttpFactory();
2626
$cache = new ArrayCachePool(null, $items);
2727
$client = new Client(
2828
new FakeClient(new Handler($factory, $factory)),
@@ -34,6 +34,5 @@ public function testClient()
3434
$request = new Request('GET', 'http://localhost?etag=ok', ['User-Agent' => 'webclient/1.0']);
3535
$response = $client->sendRequest($request);
3636
$this->assertSame(200, $response->getStatusCode());
37-
$this->fail('Help me cover this with tests, please');
3837
}
3938
}

0 commit comments

Comments
 (0)