Skip to content

Commit 6b0e65a

Browse files
committed
Replace dev-requirement nyholm/psr7 to pluf/http2 for support php 7.0
1 parent fd73851 commit 6b0e65a

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"psr/http-client": "^1.0"
1717
},
1818
"require-dev": {
19-
"nyholm/psr7": "^1.3",
19+
"pluf/http2": "^7.0",
2020
"phpunit/phpunit": ">=6.5",
2121
"squizlabs/php_codesniffer": "^3.5",
2222
"webclient/fake-http-client": "^1.0"

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php" colors="true">
2+
<phpunit bootstrap="vendor/autoload.php" colors="true" cacheResult="false">
33
<testsuites>
44
<testsuite name="all">
55
<directory>tests</directory>

stuff/Handler.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Stuff\Webclient\Extension\Redirect;
66

7-
use Nyholm\Psr7\Response;
7+
use Pluf\Http\Response;
88
use Psr\Http\Message\ResponseInterface;
99
use Psr\Http\Message\ServerRequestInterface;
1010
use Psr\Http\Server\RequestHandlerInterface;
@@ -40,6 +40,11 @@ public function handle(ServerRequestInterface $request): ResponseInterface
4040
$headers['Location'] = $request->getUri()->withQuery($get)->__toString();
4141
$status = 302;
4242
}
43-
return new Response($status, $headers, (string)$visit, '1.1');
43+
$response = new Response($status);
44+
foreach ($headers as $header => $value) {
45+
$response = $response->withHeader($header, $value);
46+
}
47+
$response->getBody()->write((string)$visit);
48+
return $response->withProtocolVersion('1.1');
4449
}
4550
}

tests/RedirectClientTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
namespace Tests\Webclient\Extension\Redirect;
66

7+
use Pluf\Http\Headers;
8+
use Pluf\Http\Stream;
9+
use Pluf\Http\Uri;
710
use Stuff\Webclient\Extension\Redirect\Handler;
8-
use Nyholm\Psr7\Request;
11+
use Pluf\Http\Request;
912
use PHPUnit\Framework\TestCase;
1013
use Psr\Http\Client\ClientExceptionInterface;
1114
use Webclient\Extension\Redirect\Client;
@@ -28,10 +31,14 @@ public function testRedirects(int $maxRedirects, int $needRedirects, int $expect
2831

2932
$client = new Client(new FakeClient(new Handler()), $maxRedirects);
3033

31-
$request = new Request('GET', 'http://localhost?redirects=' . $needRedirects, ['Accept' => 'text/plain']);
34+
$headers = new Headers(['Accept' => 'text/plain']);
35+
$uri = new Uri('http', 'localhost', 80, '/', 'redirects=' . $needRedirects);
36+
$resource = fopen('php://temp', 'w+');
37+
$body = new Stream($resource);
38+
$request = new Request('GET', $uri, $headers, [], [], $body);
3239

3340
$response = $client->sendRequest($request);
34-
41+
fclose($resource);
3542
$this->assertSame($expectRedirects, (int)$response->getBody()->__toString());
3643
}
3744

0 commit comments

Comments
 (0)