Skip to content

Commit 6e23cdd

Browse files
committed
adjust code to be compatible with psr/http-message 2.0
1 parent 250fc9f commit 6e23cdd

24 files changed

+148
-403
lines changed

Diff for: CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
77
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
88

9-
## [1.14.0] - 2023-04-14
9+
## [1.15.0] - 2023-05-10
10+
11+
- Actually make compatible with PSR-7 1.1 and 2.0
12+
- Drop support for PHP 7.1
13+
14+
## [1.14.0] - 2023-04-14 (broken)
15+
16+
**This release is not actually compatible with PSR-7 1.1 or 2.0**
1017

1118
- Allow installation with http-message (PSR-7) version 2 in addition to version 1.
1219
- Support for PHP 8.2

Diff for: composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^7.1 || ^8.0",
18+
"php": "^7.2 || ^8.0",
1919
"clue/stream-filter": "^1.5",
2020
"php-http/message-factory": "^1.0.2",
21-
"psr/http-message": "^1.0 || ^2.0"
21+
"psr/http-message": "^1.1 || ^2.0"
2222
},
2323
"provide": {
2424
"php-http/message-factory-implementation": "1.0"
@@ -28,7 +28,7 @@
2828
"ergebnis/composer-normalize": "^2.6",
2929
"guzzlehttp/psr7": "^1.0 || ^2.0",
3030
"phpspec/phpspec": "^5.1 || ^6.3 || ^7.1",
31-
"slim/slim": "^3.0 || ^4.0",
31+
"slim/slim": "^3.0",
3232
"laminas/laminas-diactoros": "^2.0 || ^3.0"
3333
},
3434
"suggest": {

Diff for: phpstan-baseline.neon

-65
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,6 @@ parameters:
115115
count: 1
116116
path: src/CookieUtil.php
117117

118-
-
119-
message: "#^Method Http\\\\Message\\\\Encoding\\\\ChunkStream\\:\\:fill\\(\\) has no return type specified\\.$#"
120-
count: 1
121-
path: src/Encoding/ChunkStream.php
122-
123-
-
124-
message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:fill\\(\\) has no return type specified\\.$#"
125-
count: 1
126-
path: src/Encoding/FilteredStream.php
127-
128-
-
129-
message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:rewind\\(\\) has no return type specified\\.$#"
130-
count: 1
131-
path: src/Encoding/FilteredStream.php
132-
133-
-
134-
message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:seek\\(\\) has no return type specified\\.$#"
135-
count: 1
136-
path: src/Encoding/FilteredStream.php
137-
138118
-
139119
message: "#^Method Http\\\\Message\\\\MessageFactory\\\\DiactorosMessageFactory\\:\\:createRequest\\(\\) has parameter \\$headers with no value type specified in iterable type array\\.$#"
140120
count: 1
@@ -180,26 +160,11 @@ parameters:
180160
count: 1
181161
path: src/RequestMatcher/RequestMatcher.php
182162

183-
-
184-
message: "#^Property Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:\\$size \\(int\\) does not accept int\\|null\\.$#"
185-
count: 1
186-
path: src/Stream/BufferedStream.php
187-
188163
-
189164
message: "#^Property Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:\\$resource \\(resource\\) does not accept resource\\|false\\.$#"
190165
count: 2
191166
path: src/Stream/BufferedStream.php
192167

193-
-
194-
message: "#^Dead catch \\- Exception is already caught#"
195-
count: 1
196-
path: src/Stream/BufferedStream.php
197-
198-
-
199-
message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:detach\\(\\) should return resource\\|null but empty return statement found\\.$#"
200-
count: 1
201-
path: src/Stream/BufferedStream.php
202-
203168
-
204169
message: "#^Property Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:\\$stream \\(Psr\\\\Http\\\\Message\\\\StreamInterface\\) does not accept null\\.$#"
205170
count: 1
@@ -210,36 +175,6 @@ parameters:
210175
count: 1
211176
path: src/Stream/BufferedStream.php
212177

213-
-
214-
message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:getSize\\(\\) should return int\\|null but empty return statement found\\.$#"
215-
count: 1
216-
path: src/Stream/BufferedStream.php
217-
218-
-
219-
message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:tell\\(\\) should return int but returns int\\|false\\.$#"
220-
count: 1
221-
path: src/Stream/BufferedStream.php
222-
223-
-
224-
message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:seek\\(\\) has no return type specified\\.$#"
225-
count: 1
226-
path: src/Stream/BufferedStream.php
227-
228-
-
229-
message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:rewind\\(\\) has no return type specified\\.$#"
230-
count: 1
231-
path: src/Stream/BufferedStream.php
232-
233-
-
234-
message: "#^Parameter \\#1 \\$string of function strlen expects string, string\\|false given\\.$#"
235-
count: 1
236-
path: src/Stream/BufferedStream.php
237-
238-
-
239-
message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:read\\(\\) should return string but returns string\\|false\\.$#"
240-
count: 1
241-
path: src/Stream/BufferedStream.php
242-
243178
-
244179
message: "#^Parameter \\#1 \\$stream of class Slim\\\\Http\\\\Stream constructor expects resource, resource\\|false given\\.$#"
245180
count: 1

Diff for: spec/Decorator/MessageDecoratorSpec.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ public function it_can_check_a_header(MessageInterface $message)
6969

7070
public function it_has_a_header(MessageInterface $message)
7171
{
72-
$message->getHeader('Content-Type')->willReturn('application/xml');
72+
$message->getHeader('Content-Type')->willReturn(['application/xml']);
7373

74-
$this->getHeader('Content-Type')->shouldReturn('application/xml');
74+
$this->getHeader('Content-Type')->shouldReturn(['application/xml']);
7575
}
7676

7777
public function it_has_a_header_line(MessageInterface $message)

Diff for: spec/Decorator/StreamDecoratorSpec.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function it_checks_whether_the_stream_is_writable(StreamInterface $stream
9595

9696
public function it_writes_to_the_stream(StreamInterface $stream)
9797
{
98-
$stream->write('body')->shouldBeCalled();
98+
$stream->write('body')->shouldBeCalled()->willReturn(4);
9999

100100
$this->write('body');
101101
}

Diff for: spec/Encoding/FilteredStreamStubSpec.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ public function it_does_not_know_the_content_size()
5757

5858
class FilteredStreamStub extends FilteredStream
5959
{
60-
protected function readFilter()
60+
protected function readFilter(): string
6161
{
6262
return 'convert.base64-encode';
6363
}
6464

65-
protected function writeFilter()
65+
protected function writeFilter(): string
6666
{
6767
return 'convert.base64-encode';
6868
}

Diff for: spec/Encoding/MemoryStream.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public function __construct($body = '', $chunkSize = 8192)
2828
$this->chunkSize = $chunkSize;
2929
}
3030

31-
public function __toString()
31+
public function __toString(): string
3232
{
3333
return $this->getContents();
3434
}
3535

36-
public function close()
36+
public function close(): void
3737
{
3838
fclose($this->resource);
3939
}
@@ -46,64 +46,64 @@ public function detach()
4646
return $resource;
4747
}
4848

49-
public function getSize()
49+
public function getSize(): int
5050
{
5151
return $this->size;
5252
}
5353

54-
public function tell()
54+
public function tell(): int
5555
{
5656
return ftell($this->resource);
5757
}
5858

59-
public function eof()
59+
public function eof(): bool
6060
{
6161
return feof($this->resource);
6262
}
6363

64-
public function isSeekable()
64+
public function isSeekable(): bool
6565
{
6666
return true;
6767
}
6868

69-
public function seek($offset, $whence = SEEK_SET)
69+
public function seek(int $offset, int $whence = SEEK_SET): void
7070
{
7171
fseek($this->resource, $offset, $whence);
7272
}
7373

74-
public function rewind()
74+
public function rewind(): void
7575
{
7676
$this->seek(0);
7777
}
7878

79-
public function isWritable()
79+
public function isWritable(): bool
8080
{
8181
return true;
8282
}
8383

84-
public function write($string)
84+
public function write(string $string): int
8585
{
86-
fwrite($this->resource, $string);
86+
return fwrite($this->resource, $string);
8787
}
8888

89-
public function isReadable()
89+
public function isReadable(): bool
9090
{
9191
return true;
9292
}
9393

94-
public function read($length)
94+
public function read(int $length): string
9595
{
9696
return fread($this->resource, min($this->chunkSize, $length));
9797
}
9898

99-
public function getContents()
99+
public function getContents(): string
100100
{
101101
$this->rewind();
102102

103103
return $this->read($this->size);
104104
}
105105

106-
public function getMetadata($key = null)
106+
public function getMetadata(string $key = null)
107107
{
108108
$metadata = stream_get_meta_data($this->resource);
109109

Diff for: spec/Formatter/CurlCommandFormatterSpec.php

+19-13
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public function it_formats_the_request(RequestInterface $request, UriInterface $
2525
$request->getUri()->willReturn($uri);
2626
$request->getBody()->willReturn($body);
2727

28-
$uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar');
28+
$uri->withFragment('')->shouldBeCalled()->willReturn($uri);
29+
$uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar');
2930
$request->getMethod()->willReturn('GET');
3031
$request->getProtocolVersion()->willReturn('1.1');
3132

@@ -43,9 +44,10 @@ public function it_formats_post_request(RequestInterface $request, UriInterface
4344
$body->__toString()->willReturn('body " data'." test' bar");
4445
$body->getSize()->willReturn(1);
4546
$body->isSeekable()->willReturn(true);
46-
$body->rewind()->willReturn(true);
47+
$body->rewind()->shouldBeCalled();
4748

48-
$uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar');
49+
$uri->withFragment('')->shouldBeCalled()->willReturn($uri);
50+
$uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar');
4951
$request->getMethod()->willReturn('POST');
5052
$request->getProtocolVersion()->willReturn('2.0');
5153

@@ -65,10 +67,10 @@ public function it_formats_the_request_with_user_agent(RequestInterface $request
6567
$request->getUri()->willReturn($uri);
6668
$request->getBody()->willReturn($body);
6769

68-
$uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar');
70+
$uri->withFragment('')->shouldBeCalled()->willReturn($uri);
71+
$uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar');
6972
$request->getMethod()->willReturn('GET');
7073
$request->getProtocolVersion()->willReturn('1.1');
71-
$uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar');
7274
$request->getHeaders()->willReturn(['user-agent' => ['foobar-browser']]);
7375

7476
$this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' -A 'foobar-browser'");
@@ -82,9 +84,10 @@ public function it_formats_requests_with_null_bytes(RequestInterface $request, U
8284
$body->__toString()->willReturn("\0");
8385
$body->getSize()->willReturn(1);
8486
$body->isSeekable()->willReturn(true);
85-
$body->rewind()->willReturn(true);
87+
$body->rewind()->shouldBeCalled();
8688

87-
$uri->withFragment('')->willReturn('http://foo.com/bar');
89+
$uri->withFragment('')->shouldBeCalled()->willReturn($uri);
90+
$uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar');
8891
$request->getMethod()->willReturn('POST');
8992
$request->getProtocolVersion()->willReturn('1.1');
9093
$request->getHeaders()->willReturn([]);
@@ -100,9 +103,10 @@ public function it_formats_requests_with_line_break(RequestInterface $request, U
100103
$body->__toString()->willReturn("foo\nbar");
101104
$body->getSize()->willReturn(1);
102105
$body->isSeekable()->willReturn(true);
103-
$body->rewind()->willReturn(true);
106+
$body->rewind()->shouldBeCalled();
104107

105-
$uri->withFragment('')->willReturn('http://foo.com/bar');
108+
$uri->withFragment('')->shouldBeCalled()->willReturn($uri);
109+
$uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar');
106110
$request->getMethod()->willReturn('POST');
107111
$request->getProtocolVersion()->willReturn('1.1');
108112
$request->getHeaders()->willReturn([]);
@@ -120,7 +124,8 @@ public function it_formats_requests_with_nonseekable_body(RequestInterface $requ
120124
$body->__toString()->shouldNotBeCalled();
121125
$body->rewind()->shouldNotBeCalled();
122126

123-
$uri->withFragment('')->willReturn('http://foo.com/bar');
127+
$uri->withFragment('')->shouldBeCalled()->willReturn($uri);
128+
$uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar');
124129
$request->getMethod()->willReturn('POST');
125130
$request->getProtocolVersion()->willReturn('1.1');
126131
$request->getHeaders()->willReturn([]);
@@ -133,12 +138,13 @@ public function it_formats_requests_with_long_body(RequestInterface $request, Ur
133138
$request->getUri()->willReturn($uri);
134139
$request->getBody()->willReturn($body);
135140

136-
$body->__toString()->willReturn('a very long body');
141+
$body->__toString()->shouldNotBeCalled();
137142
$body->getSize()->willReturn(2097153);
138143
$body->isSeekable()->willReturn(true);
139-
$body->rewind()->willReturn(true);
144+
$body->rewind()->shouldNotBeCalled();
140145

141-
$uri->withFragment('')->willReturn('http://foo.com/bar');
146+
$uri->withFragment('')->shouldBeCalled()->willReturn($uri);
147+
$uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar');
142148
$request->getMethod()->willReturn('POST');
143149
$request->getProtocolVersion()->willReturn('1.1');
144150
$request->getHeaders()->willReturn([]);

0 commit comments

Comments
 (0)