Skip to content

fix code to actually be compatible with psr/http-message 2 #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']

steps:
- name: Checkout code
Expand All @@ -31,12 +31,37 @@ jobs:
- name: Execute tests
run: composer test

psr-7_2:
name: PHP PSR-7 2.0
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
tools: composer
coverage: none

- name: Install dependencies
run: |
rm src/MessageFactory/SlimMessageFactory.php src/StreamFactory/SlimStreamFactory.php src/UriFactory/SlimUriFactory.php spec/MessageFactory/SlimMessageFactorySpec.php spec/StreamFactory/SlimStreamFactorySpec.php spec/UriFactory/SlimUriFactorySpec.php
composer remove --dev "slim/slim" --no-interaction --no-update
composer require "psr/http-message:^2.0" --no-interaction --no-update
composer update --prefer-dist --prefer-stable --no-interaction --no-progress

- name: Execute tests
run: composer test

lowest:
name: PHP ${{ matrix.php }} Lowest
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.1', '7.2', '7.3', '7.4']
php: ['7.2', '7.3', '7.4']

steps:
- name: Checkout code
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.14.0] - 2023-04-14
## [1.15.0] - 2023-05-10

- Actually make compatible with PSR-7 1.1 and 2.0
- Drop support for PHP 7.1

## [1.14.0] - 2023-04-14 (broken)

**This release is not actually compatible with PSR-7 1.1 or 2.0**

- Allow installation with http-message (PSR-7) version 2 in addition to version 1.
- Support for PHP 8.2
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
}
],
"require": {
"php": "^7.1 || ^8.0",
"php": "^7.2 || ^8.0",
"clue/stream-filter": "^1.5",
"php-http/message-factory": "^1.0.2",
"psr/http-message": "^1.0 || ^2.0"
"psr/http-message": "^1.1 || ^2.0"
},
"provide": {
"php-http/message-factory-implementation": "1.0"
},
"require-dev": {
"ext-zlib": "*",
"ergebnis/composer-normalize": "^2.6",
"guzzlehttp/psr7": "^1.0",
"guzzlehttp/psr7": "^1.0 || ^2.0",
"phpspec/phpspec": "^5.1 || ^6.3 || ^7.1",
"slim/slim": "^3.0",
"laminas/laminas-diactoros": "^2.0"
"laminas/laminas-diactoros": "^2.0 || ^3.0"
},
"suggest": {
"ext-zlib": "Used with compressor/decompressor streams",
Expand Down
65 changes: 0 additions & 65 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,6 @@ parameters:
count: 1
path: src/CookieUtil.php

-
message: "#^Method Http\\\\Message\\\\Encoding\\\\ChunkStream\\:\\:fill\\(\\) has no return type specified\\.$#"
count: 1
path: src/Encoding/ChunkStream.php

-
message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:fill\\(\\) has no return type specified\\.$#"
count: 1
path: src/Encoding/FilteredStream.php

-
message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:rewind\\(\\) has no return type specified\\.$#"
count: 1
path: src/Encoding/FilteredStream.php

-
message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:seek\\(\\) has no return type specified\\.$#"
count: 1
path: src/Encoding/FilteredStream.php

-
message: "#^Method Http\\\\Message\\\\MessageFactory\\\\DiactorosMessageFactory\\:\\:createRequest\\(\\) has parameter \\$headers with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -180,26 +160,11 @@ parameters:
count: 1
path: src/RequestMatcher/RequestMatcher.php

-
message: "#^Property Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:\\$size \\(int\\) does not accept int\\|null\\.$#"
count: 1
path: src/Stream/BufferedStream.php

-
message: "#^Property Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:\\$resource \\(resource\\) does not accept resource\\|false\\.$#"
count: 2
path: src/Stream/BufferedStream.php

-
message: "#^Dead catch \\- Exception is already caught#"
count: 1
path: src/Stream/BufferedStream.php

-
message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:detach\\(\\) should return resource\\|null but empty return statement found\\.$#"
count: 1
path: src/Stream/BufferedStream.php

-
message: "#^Property Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:\\$stream \\(Psr\\\\Http\\\\Message\\\\StreamInterface\\) does not accept null\\.$#"
count: 1
Expand All @@ -210,36 +175,6 @@ parameters:
count: 1
path: src/Stream/BufferedStream.php

-
message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:getSize\\(\\) should return int\\|null but empty return statement found\\.$#"
count: 1
path: src/Stream/BufferedStream.php

-
message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:tell\\(\\) should return int but returns int\\|false\\.$#"
count: 1
path: src/Stream/BufferedStream.php

-
message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:seek\\(\\) has no return type specified\\.$#"
count: 1
path: src/Stream/BufferedStream.php

-
message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:rewind\\(\\) has no return type specified\\.$#"
count: 1
path: src/Stream/BufferedStream.php

-
message: "#^Parameter \\#1 \\$string of function strlen expects string, string\\|false given\\.$#"
count: 1
path: src/Stream/BufferedStream.php

-
message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:read\\(\\) should return string but returns string\\|false\\.$#"
count: 1
path: src/Stream/BufferedStream.php

-
message: "#^Parameter \\#1 \\$stream of class Slim\\\\Http\\\\Stream constructor expects resource, resource\\|false given\\.$#"
count: 1
Expand Down
4 changes: 2 additions & 2 deletions spec/Decorator/MessageDecoratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public function it_can_check_a_header(MessageInterface $message)

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

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

public function it_has_a_header_line(MessageInterface $message)
Expand Down
2 changes: 1 addition & 1 deletion spec/Decorator/StreamDecoratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function it_checks_whether_the_stream_is_writable(StreamInterface $stream

public function it_writes_to_the_stream(StreamInterface $stream)
{
$stream->write('body')->shouldBeCalled();
$stream->write('body')->shouldBeCalled()->willReturn(4);

$this->write('body');
}
Expand Down
4 changes: 2 additions & 2 deletions spec/Encoding/FilteredStreamStubSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public function it_does_not_know_the_content_size()

class FilteredStreamStub extends FilteredStream
{
protected function readFilter()
protected function readFilter(): string
{
return 'convert.base64-encode';
}

protected function writeFilter()
protected function writeFilter(): string
{
return 'convert.base64-encode';
}
Expand Down
30 changes: 15 additions & 15 deletions spec/Encoding/MemoryStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public function __construct($body = '', $chunkSize = 8192)
$this->chunkSize = $chunkSize;
}

public function __toString()
public function __toString(): string
{
return $this->getContents();
}

public function close()
public function close(): void
{
fclose($this->resource);
}
Expand All @@ -46,64 +46,64 @@ public function detach()
return $resource;
}

public function getSize()
public function getSize(): int
{
return $this->size;
}

public function tell()
public function tell(): int
{
return ftell($this->resource);
}

public function eof()
public function eof(): bool
{
return feof($this->resource);
}

public function isSeekable()
public function isSeekable(): bool
{
return true;
}

public function seek($offset, $whence = SEEK_SET)
public function seek(int $offset, int $whence = SEEK_SET): void
{
fseek($this->resource, $offset, $whence);
}

public function rewind()
public function rewind(): void
{
$this->seek(0);
}

public function isWritable()
public function isWritable(): bool
{
return true;
}

public function write($string)
public function write(string $string): int
{
fwrite($this->resource, $string);
return fwrite($this->resource, $string);
}

public function isReadable()
public function isReadable(): bool
{
return true;
}

public function read($length)
public function read(int $length): string
{
return fread($this->resource, min($this->chunkSize, $length));
}

public function getContents()
public function getContents(): string
{
$this->rewind();

return $this->read($this->size);
}

public function getMetadata($key = null)
public function getMetadata(string $key = null)
{
$metadata = stream_get_meta_data($this->resource);

Expand Down
32 changes: 19 additions & 13 deletions spec/Formatter/CurlCommandFormatterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public function it_formats_the_request(RequestInterface $request, UriInterface $
$request->getUri()->willReturn($uri);
$request->getBody()->willReturn($body);

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

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

$uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar');
$uri->withFragment('')->shouldBeCalled()->willReturn($uri);
$uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar');
$request->getMethod()->willReturn('POST');
$request->getProtocolVersion()->willReturn('2.0');

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

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

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

$uri->withFragment('')->willReturn('http://foo.com/bar');
$uri->withFragment('')->shouldBeCalled()->willReturn($uri);
$uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar');
$request->getMethod()->willReturn('POST');
$request->getProtocolVersion()->willReturn('1.1');
$request->getHeaders()->willReturn([]);
Expand All @@ -100,9 +103,10 @@ public function it_formats_requests_with_line_break(RequestInterface $request, U
$body->__toString()->willReturn("foo\nbar");
$body->getSize()->willReturn(1);
$body->isSeekable()->willReturn(true);
$body->rewind()->willReturn(true);
$body->rewind()->shouldBeCalled();

$uri->withFragment('')->willReturn('http://foo.com/bar');
$uri->withFragment('')->shouldBeCalled()->willReturn($uri);
$uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar');
$request->getMethod()->willReturn('POST');
$request->getProtocolVersion()->willReturn('1.1');
$request->getHeaders()->willReturn([]);
Expand All @@ -120,7 +124,8 @@ public function it_formats_requests_with_nonseekable_body(RequestInterface $requ
$body->__toString()->shouldNotBeCalled();
$body->rewind()->shouldNotBeCalled();

$uri->withFragment('')->willReturn('http://foo.com/bar');
$uri->withFragment('')->shouldBeCalled()->willReturn($uri);
$uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar');
$request->getMethod()->willReturn('POST');
$request->getProtocolVersion()->willReturn('1.1');
$request->getHeaders()->willReturn([]);
Expand All @@ -133,12 +138,13 @@ public function it_formats_requests_with_long_body(RequestInterface $request, Ur
$request->getUri()->willReturn($uri);
$request->getBody()->willReturn($body);

$body->__toString()->willReturn('a very long body');
$body->__toString()->shouldNotBeCalled();
$body->getSize()->willReturn(2097153);
$body->isSeekable()->willReturn(true);
$body->rewind()->willReturn(true);
$body->rewind()->shouldNotBeCalled();

$uri->withFragment('')->willReturn('http://foo.com/bar');
$uri->withFragment('')->shouldBeCalled()->willReturn($uri);
$uri->__toString()->shouldBeCalled()->willReturn('http://foo.com/bar');
$request->getMethod()->willReturn('POST');
$request->getProtocolVersion()->willReturn('1.1');
$request->getHeaders()->willReturn([]);
Expand Down
Loading