Skip to content
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

Make package compatible with stream interface Compatibility stream interface v2 #75

Merged
merged 10 commits into from
Sep 1, 2024
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,9 @@ name: CI
on:
push:
branches:
- 2.x
- '[0-9]+.x'
- '[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.x'
pull_request:

jobs:
@@ -91,7 +93,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.3
tools: composer
coverage: xdebug

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 3.0.0

* Fixed compatibility with `psr/http-message` v2

## 2.2.0

* Allow installation with Symfony 7
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ First launch the http server:
$ ./vendor/bin/http_test_server > /dev/null 2>&1 &
```

Then generate ssh certificates:
Then generate SSL certificates:

```bash
$ composer gen-ssl
18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -9,18 +9,20 @@
}
],
"require": {
"php": "^7.2 || ^8.0",
"nyholm/psr7": "^1.3",
"php-http/httplug": "^2.0",
"php": "^8.1",
"nyholm/psr7": "^1.8.1",
"php-http/httplug": "^2.4",
"psr/http-client": "^1.0",
"psr/http-message": "^1.0 || ^2.0",
"symfony/options-resolver": "^2.6 || ^3.4 || ^4.4 || ^5.0 || ^6.0 || ^7.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.2 || ^3.0",
"php-http/client-integration-tests": "^3.0",
"php-http/message": "^1.9",
"php-http/client-common": "^2.3",
"phpunit/phpunit": "^8.5.23 || ~9.5"
"friendsofphp/php-cs-fixer": "^3.51",
"php-http/client-integration-tests": "^3.1.1",
"php-http/message": "^1.16",
"php-http/client-common": "^2.7",
"phpunit/phpunit": "^8.5.23 || ~9.5",
"php-http/message-factory": "^1.1"
},
"provide": {
"php-http/client-implementation": "1.0",
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@
<testsuites>
<testsuite name="Socket Client Test Suite">
<directory>tests/</directory>
<exclude>tests/SocketClientFeatureTest.php</exclude>
</testsuite>
</testsuites>
<php>
6 changes: 0 additions & 6 deletions src/ResponseReader.php
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@

use Http\Client\Socket\Exception\BrokenPipeException;
use Http\Client\Socket\Exception\TimeoutException;
use Http\Message\ResponseFactory;
use Nyholm\Psr7\Response;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
@@ -18,11 +17,6 @@
*/
trait ResponseReader
{
/**
* @var ResponseFactory For creating response
*/
protected $responseFactory;

/**
* Read a response from a socket.
*
32 changes: 13 additions & 19 deletions src/Stream.php
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@
$this->request = $request;
}

public function __toString()
public function __toString(): string
{
try {
return $this->getContents();
@@ -70,7 +70,7 @@
}
}

public function close()
public function close(): void
{
if ($this->isDetached || null === $this->socket) {
throw new StreamException('Stream is detached');
@@ -93,12 +93,12 @@
/**
* @return int<0, max>|null
*/
public function getSize()
public function getSize(): ?int
{
return $this->size;
}

public function tell()
public function tell(): int
{
if ($this->isDetached || null === $this->socket) {
throw new StreamException('Stream is detached');
@@ -111,7 +111,7 @@
return $tell;
}

public function eof()
public function eof(): bool
{
if ($this->isDetached || null === $this->socket) {
throw new StreamException('Stream is detached');
@@ -120,52 +120,46 @@
return feof($this->socket);
}

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

/**
* @return void
*/
public function seek($offset, $whence = SEEK_SET)
public function seek($offset, $whence = SEEK_SET): void
{
throw new StreamException('This stream is not seekable');
}

/**
* @return void
*/
public function rewind()
public function rewind(): void
{
throw new StreamException('This stream is not seekable');
}

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

public function write($string)
public function write($string): int
{
throw new StreamException('This stream is not writable');
}

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

/**
* @param int<0, max> $length
*/
public function read($length)
public function read($length): string
{
if ($this->isDetached || null === $this->socket) {
throw new StreamException('Stream is detached');
}
if (null === $this->getSize()) {
$read = fread($this->socket, $length);

Check failure on line 162 in src/Stream.php

GitHub Actions / PHPStan

Parameter #2 $length of function fread expects int<1, max>, int<0, max> given.
if (false === $read) {
throw new StreamException('Failed to read from stream');
}
@@ -178,7 +172,7 @@
}

// Even if we request a length a non blocking stream can return less data than asked
$read = fread($this->socket, $length);

Check failure on line 175 in src/Stream.php

GitHub Actions / PHPStan

Parameter #2 $length of function fread expects int<1, max>, int<0, max> given.
if (false === $read) {
// PHP 8
if ($this->getMetadata('timed_out')) {
@@ -197,7 +191,7 @@
return $read;
}

public function getContents()
public function getContents(): string
{
if ($this->isDetached || null === $this->socket) {
throw new StreamException('Stream is detached');
25 changes: 25 additions & 0 deletions tests/SocketClientFeatureTest.php
Original file line number Diff line number Diff line change
@@ -12,4 +12,29 @@ protected function createClient(): ClientInterface
{
return new SocketHttpClient();
}

public function testAutoSetContentLength(): void
{
$this->markTestSkipped('Feature is unsupported');
}

public function testGzip(): void
{
$this->markTestSkipped('Feature is unsupported');
}

public function testDeflate(): void
{
$this->markTestSkipped('Feature is unsupported');
}

public function testChunked(): void
{
$this->markTestSkipped('Feature is unsupported');
}

public function testRedirect(): void
{
$this->markTestSkipped('Feature is unsupported');
}
}
6 changes: 2 additions & 4 deletions tests/SocketHttpClientTest.php
Original file line number Diff line number Diff line change
@@ -6,15 +6,13 @@
use Http\Client\Socket\Client as SocketHttpClient;
use Http\Client\Socket\Exception\NetworkException;
use Http\Client\Socket\Exception\TimeoutException;
use Http\Message\MessageFactory\GuzzleMessageFactory;
use Nyholm\Psr7\Factory\Psr17Factory;

class SocketHttpClientTest extends BaseTestCase
{
public function createClient($options = [])
{
$messageFactory = new GuzzleMessageFactory();

return new HttpMethodsClient(new SocketHttpClient($options), $messageFactory);
return new HttpMethodsClient(new SocketHttpClient($options), new Psr17Factory());
}

public function testTcpSocketDomain()