Skip to content

Commit

Permalink
Merge pull request #75 from php-http/feature/support-phpunit-10
Browse files Browse the repository at this point in the history
Feature/support phpunit 10
  • Loading branch information
dbu authored Mar 25, 2024
2 parents f725461 + 367c2b0 commit 53f658e
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/guzzle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
php: [ '7.3', '7.4', '8.0', '8.1', '8.2' ]
uses: ./.github/workflows/integration.yml
with:
php: ${{ matrix.php }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/laminas-legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4' ]
php: [ '7.3', '7.4' ]
uses: ./.github/workflows/integration.yml
with:
php: ${{ matrix.php }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nyholm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
php: [ '7.3', '7.4', '8.0', '8.1', '8.2' ]
uses: ./.github/workflows/integration.yml
with:
php: ${{ matrix.php }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ringcentral.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
php: [ '7.3', '7.4', '8.0', '8.1', '8.2' ]
uses: ./.github/workflows/integration.yml
with:
php: ${{ matrix.php }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.tmp
/.phpunit.result.cache
/.phpunit.cache
/behat.yml
/build/
/composer.lock
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
}
],
"require": {
"php": "^7.2 || ^8.0",
"phpunit/phpunit": "^8.0 || ^9.3",
"php": "^7.3 || ^8.0",
"phpunit/phpunit": "^9.3 || ^10.0",
"psr/http-message": "^1.0 || ^2.0"
},
"require-dev": {
Expand Down
47 changes: 19 additions & 28 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="true"
>
<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Guzzle">
<directory>./tests/Guzzle/</directory>
</testsuite>

<testsuite name="RingCentral">
<directory>./tests/RingCentral/</directory>
</testsuite>

<testsuite name="Slim">
<directory>./tests/Slim/</directory>
<directory>./tests/Slim/</directory>
</testsuite>

<testsuite name="Laminas">
<directory>./tests/Laminas/</directory>
<directory>./tests/Laminas/</directory>
</testsuite>

<testsuite name="Nyholm">
<directory>./vendor/nyholm/psr7/tests/Integration/</directory>
<directory>./vendor/nyholm/psr7/tests/Integration/</directory>
</testsuite>

<testsuite name="HttpSoft">
<directory>./vendor/httpsoft/http-message/tests/Integration/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
28 changes: 17 additions & 11 deletions src/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@
use Laminas\Diactoros\UploadedFile as LaminasUploadedFile;
use Nyholm\Psr7\Factory\Psr17Factory as NyholmFactory;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UriInterface;
use RingCentral\Psr7\Uri as RingCentralUri;
use function RingCentral\Psr7\stream_for as ring_central_stream_for;
use GuzzleHttp\Psr7\Utils as GuzzleUtils;
use Http\Message\StreamFactory as HttplugStreamFactory;
use Http\Message\UriFactory as HttplugUriFactory;
use Psr\Http\Message\StreamFactoryInterface as PsrStreamFactoryInterface;
use Psr\Http\Message\UploadedFileFactoryInterface as PsrUploadedFileFactoryInterface;
use Psr\Http\Message\UriFactoryInterface as PsrUriFactoryInterface;
use Psr\Http\Message\UriInterface as PsrUriInterface;
use Slim\Psr7\Uri as SlimUri;
use Slim\Psr7\Factory\UriFactory as SlimUriFactory;
use Slim\Psr7\Factory\StreamFactory as SlimStreamFactory;
Expand All @@ -36,18 +42,18 @@ protected function buildUri($uri)
if (defined('URI_FACTORY')) {
$factoryClass = URI_FACTORY;
$factory = new $factoryClass();
if ($factory instanceof \Http\Message\UriFactory) {
if ($factory instanceof HttplugUriFactory) {
return $factory->createUri($uri);
}
if ($factory instanceof \Psr\Http\Message\UriFactoryInterface) {
if ($uri instanceof UriInterface) {
if ($factory instanceof PsrUriFactoryInterface) {
if ($uri instanceof PsrUriInterface) {
return $uri;
}

return $factory->createUri($uri);
}

throw new \RuntimeException('Constant "URI_FACTORY" must be a reference to a Http\Message\UriFactory or \Psr\Http\Message\UriFactoryInterface');
throw new \RuntimeException('Constant "URI_FACTORY" must be a reference to a '.HttplugUriFactory::class.' or '.PsrUriFactoryInterface::class);
}

if (class_exists(HttpSoftUri::class)) {
Expand Down Expand Up @@ -86,22 +92,22 @@ protected function buildStream($data)
if (defined('STREAM_FACTORY')) {
$factoryClass = STREAM_FACTORY;
$factory = new $factoryClass();
if ($factory instanceof \Http\Message\StreamFactory) {
if ($factory instanceof HttplugStreamFactory) {
return $factory->createStream($data);
}
if ($factory instanceof \Psr\Http\Message\StreamFactoryInterface) {
if ($factory instanceof PsrStreamFactoryInterface) {
if (is_string($data)) {
return $factory->createStream($data);
}

return $factory->createStreamFromResource($data);
}

throw new \RuntimeException('Constant "STREAM_FACTORY" must be a reference to a Http\Message\StreamFactory or \Psr\Http\Message\StreamFactoryInterface');
throw new \RuntimeException('Constant "STREAM_FACTORY" must be a reference to a '.HttplugStreamFactory::class.' or '.PsrStreamFactoryInterface::class);
}

if (class_exists(GuzzleStream::class)) {
return \GuzzleHttp\Psr7\Utils::streamFor($data);
return GuzzleUtils::streamFor($data);
}

$factory = null;
Expand Down Expand Up @@ -137,8 +143,8 @@ protected function buildUploadableFile($data)
if (defined('UPLOADED_FILE_FACTORY')) {
$factoryClass = UPLOADED_FILE_FACTORY;
$factory = new $factoryClass();
if (!$factory instanceof \Psr\Http\Message\UploadedFileFactoryInterface) {
throw new \RuntimeException('Constant "UPLOADED_FILE_FACTORY" must be a reference to a Psr\Http\Message\UploadedFileFactoryInterface');
if (!$factory instanceof PsrUploadedFileFactoryInterface) {
throw new \RuntimeException('Constant "UPLOADED_FILE_FACTORY" must be a reference to a '.PsrUploadedFileFactoryInterface::class);
}

$stream = $this->buildStream($data);
Expand Down
9 changes: 2 additions & 7 deletions src/MessageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function testWithHeaderInvalidArguments($name, $value)
}
}

public function getInvalidHeaderArguments()
public static function getInvalidHeaderArguments()
{
return [
[[], 'foo'],
Expand Down Expand Up @@ -288,11 +288,6 @@ public function testBody()

private function assertMatchesRegexp(string $pattern, string $string, string $message = ''): void
{
// @TODO remove when package require phpunit 9.1
if (function_exists('PHPUnit\Framework\assertMatchesRegularExpression')) {
$this->assertMatchesRegularExpression($pattern, $string, $message);
} else {
$this->assertRegExp($pattern, $string, $message);
}
$this->assertMatchesRegularExpression($pattern, $string, $message);
}
}
2 changes: 1 addition & 1 deletion src/RequestIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function testMethodWithInvalidArguments($method)
}
}

public function getInvalidMethods()
public static function getInvalidMethods()
{
return [
'null' => [null],
Expand Down
2 changes: 1 addition & 1 deletion src/ResponseIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function testStatusCodeInvalidArgument($statusCode)
}
}

public function getInvalidStatusCodeArguments()
public static function getInvalidStatusCodeArguments()
{
return [
'true' => [true],
Expand Down
4 changes: 2 additions & 2 deletions src/ServerRequestIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testGetParsedBody($value)
$this->assertEquals($value, $new->getParsedBody());
}

public function validParsedBodyParams()
public static function validParsedBodyParams()
{
return [
[null],
Expand All @@ -125,7 +125,7 @@ public function testGetParsedBodyInvalid($value)
}
}

public function invalidParsedBodyParams()
public static function invalidParsedBodyParams()
{
return [
[4711],
Expand Down
2 changes: 1 addition & 1 deletion src/StreamIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public function testGetContentsError()

fclose($resource);

$this->expectException(\RuntimeException::class);
$this->expectException(class_exists(\Throwable::class) ? \Throwable::class : \RuntimeException::class);
$stream->getContents();
}
}
9 changes: 2 additions & 7 deletions src/UploadedFileIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,8 @@ public function testGetSize()

$file = $this->createSubject();
$size = $file->getSize();
if (false !== $size) {
// @TODO remove when package require phpunit 9.1
if (function_exists('PHPUnit\Framework\assertMatchesRegularExpression')) {
$this->assertMatchesRegularExpression('|^[0-9]+$|', (string) $size);
} else {
$this->assertRegExp('|^[0-9]+$|', (string) $size);
}
if (null !== $size) {
$this->assertMatchesRegularExpression('|^[0-9]+$|', (string) $size);
} else {
$this->assertNull($size);
}
Expand Down
50 changes: 28 additions & 22 deletions src/UriIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function testWithSchemeInvalidArguments($schema)
}
}

public function getInvalidSchemaArguments()
public static function getInvalidSchemaArguments()
{
return [
[true],
Expand Down Expand Up @@ -155,7 +155,7 @@ public function testPort()
/**
* @dataProvider getPaths
*/
public function testPath(UriInterface $uri, $expected)
public function testPath(UriInterface $uri, string $expected)
{
if (isset($this->skippedTests[__FUNCTION__])) {
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
Expand All @@ -164,22 +164,24 @@ public function testPath(UriInterface $uri, $expected)
$this->assertSame($expected, $uri->getPath());
}

public function getPaths()
public static function getPaths()
{
$test = new static('uriprovider');

return [
[$this->createUri('http://www.foo.com/'), '/'],
[$this->createUri('http://www.foo.com'), ''],
[$this->createUri('foo/bar'), 'foo/bar'],
[$this->createUri('http://www.foo.com/foo bar'), '/foo%20bar'],
[$this->createUri('http://www.foo.com/foo%20bar'), '/foo%20bar'],
[$this->createUri('http://www.foo.com/foo%2fbar'), '/foo%2fbar'],
[$test->createUri('http://www.foo.com/'), '/'],
[$test->createUri('http://www.foo.com'), ''],
[$test->createUri('foo/bar'), 'foo/bar'],
[$test->createUri('http://www.foo.com/foo bar'), '/foo%20bar'],
[$test->createUri('http://www.foo.com/foo%20bar'), '/foo%20bar'],
[$test->createUri('http://www.foo.com/foo%2fbar'), '/foo%2fbar'],
];
}

/**
* @dataProvider getQueries
*/
public function testQuery(UriInterface $uri, $expected)
public function testQuery(UriInterface $uri, string $expected)
{
if (isset($this->skippedTests[__FUNCTION__])) {
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
Expand All @@ -188,21 +190,23 @@ public function testQuery(UriInterface $uri, $expected)
$this->assertSame($expected, $uri->getQuery());
}

public function getQueries()
public static function getQueries()
{
$test = new static('uriprovider');

return [
[$this->createUri('http://www.foo.com'), ''],
[$this->createUri('http://www.foo.com?'), ''],
[$this->createUri('http://www.foo.com?foo=bar'), 'foo=bar'],
[$this->createUri('http://www.foo.com?foo=bar%26baz'), 'foo=bar%26baz'],
[$this->createUri('http://www.foo.com?foo=bar&baz=biz'), 'foo=bar&baz=biz'],
[$test->createUri('http://www.foo.com'), ''],
[$test->createUri('http://www.foo.com?'), ''],
[$test->createUri('http://www.foo.com?foo=bar'), 'foo=bar'],
[$test->createUri('http://www.foo.com?foo=bar%26baz'), 'foo=bar%26baz'],
[$test->createUri('http://www.foo.com?foo=bar&baz=biz'), 'foo=bar&baz=biz'],
];
}

/**
* @dataProvider getFragments
*/
public function testFragment(UriInterface $uri, $expected)
public function testFragment(UriInterface $uri, string $expected)
{
if (isset($this->skippedTests[__FUNCTION__])) {
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
Expand All @@ -211,13 +215,15 @@ public function testFragment(UriInterface $uri, $expected)
$this->assertEquals($expected, $uri->getFragment());
}

public function getFragments()
public static function getFragments()
{
$test = new static('uriprovider');

return [
[$this->createUri('http://www.foo.com'), ''],
[$this->createUri('http://www.foo.com#'), ''],
[$this->createUri('http://www.foo.com#foo'), 'foo'],
[$this->createUri('http://www.foo.com#foo%20bar'), 'foo%20bar'],
[$test->createUri('http://www.foo.com'), ''],
[$test->createUri('http://www.foo.com#'), ''],
[$test->createUri('http://www.foo.com#foo'), 'foo'],
[$test->createUri('http://www.foo.com#foo%20bar'), 'foo%20bar'],
];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Guzzle/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function createSubject()
return new Request('GET', '/');
}

public function getInvalidHeaderArguments()
public static function getInvalidHeaderArguments()
{
$testCases = parent::getInvalidHeaderArguments();

Expand Down
Loading

0 comments on commit 53f658e

Please sign in to comment.