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

Add support for PHPUnit10 and remove support for PHPUnit8 #60

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
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",
nyamsprod marked this conversation as resolved.
Show resolved Hide resolved
"phpunit/phpunit": "^9.3 || ^10.0",
nyamsprod marked this conversation as resolved.
Show resolved Hide resolved
nyamsprod marked this conversation as resolved.
Show resolved Hide resolved
"psr/http-message": "^1.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"psr/http-message": "^1.0"
"psr/http-message": "^1.0 || ^2.0"

we should keep allowing http-message 2.0. i think this was one of the merge conflicts.

},
"require-dev": {
Expand Down
24 changes: 15 additions & 9 deletions src/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
use GuzzleHttp\Psr7\Stream as GuzzleStream;
use GuzzleHttp\Psr7\UploadedFile as GuzzleUploadedFile;
use GuzzleHttp\Psr7\Uri as GuzzleUri;
use GuzzleHttp\Psr7\Utils;
use Http\Message\StreamFactory;
use Http\Message\UriFactory;
use Laminas\Diactoros\Stream as ZendStream;
use Laminas\Diactoros\Uri as ZendUri;
use Laminas\Diactoros\UploadedFile as ZendUploadedFile;
dbu marked this conversation as resolved.
Show resolved Hide resolved
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UploadedFileFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;
use Psr\Http\Message\UriInterface;
use Slim\Psr7\Uri as SlimUri;
use Zend\Diactoros\Stream as ZendStream;
use Zend\Diactoros\Uri as ZendUri;
use Zend\Diactoros\UploadedFile as ZendUploadedFile;

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
Expand All @@ -27,10 +33,10 @@ protected function buildUri($uri)
if (defined('URI_FACTORY')) {
$factoryClass = URI_FACTORY;
$factory = new $factoryClass();
if ($factory instanceof \Http\Message\UriFactory) {
if ($factory instanceof UriFactory) {
nyamsprod marked this conversation as resolved.
Show resolved Hide resolved
return $factory->createUri($uri);
}
if ($factory instanceof \Psr\Http\Message\UriFactoryInterface) {
nyamsprod marked this conversation as resolved.
Show resolved Hide resolved
if ($factory instanceof UriFactoryInterface) {
if ($uri instanceof UriInterface) {
return $uri;
}
Expand Down Expand Up @@ -61,10 +67,10 @@ protected function buildStream($data)
if (defined('STREAM_FACTORY')) {
$factoryClass = STREAM_FACTORY;
$factory = new $factoryClass();
if ($factory instanceof \Http\Message\StreamFactory) {
if ($factory instanceof StreamFactory) {
nyamsprod marked this conversation as resolved.
Show resolved Hide resolved
return $factory->createStream($data);
}
if ($factory instanceof \Psr\Http\Message\StreamFactoryInterface) {
if ($factory instanceof StreamFactoryInterface) {
nyamsprod marked this conversation as resolved.
Show resolved Hide resolved
if (is_string($data)) {
return $factory->createStream($data);
} else {
Expand All @@ -76,7 +82,7 @@ protected function buildStream($data)
}

if (class_exists(GuzzleStream::class)) {
return \GuzzleHttp\Psr7\Utils::streamFor($data);
return Utils::streamFor($data);
nyamsprod marked this conversation as resolved.
Show resolved Hide resolved
}

if (class_exists(ZendStream::class)) {
Expand All @@ -91,7 +97,7 @@ protected function buildUploadableFile($data)
if (defined('UPLOADED_FILE_FACTORY')) {
$factoryClass = UPLOADED_FILE_FACTORY;
$factory = new $factoryClass();
if (!$factory instanceof \Psr\Http\Message\UploadedFileFactoryInterface) {
if (!$factory instanceof UploadedFileFactoryInterface) {
nyamsprod marked this conversation as resolved.
Show resolved Hide resolved
throw new \RuntimeException('Constant "UPLOADED_FILE_FACTORY" must be a reference to a Psr\Http\Message\UploadedFileFactoryInterface');
}

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

public function getInvalidHeaderArguments()
public static function getInvalidHeaderArguments()
nyamsprod marked this conversation as resolved.
Show resolved Hide resolved
{
return [
[[], 'foo'],
Expand Down Expand Up @@ -254,11 +254,6 @@ public function testBody()

private function assertMatchesRegexp(string $pattern, string $string, string $message = ''): void
{
// @TODO remove when package require phpunit 9.1
nyamsprod marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -100,7 +100,7 @@ public function testMethodWithInvalidArguments($method)
$this->request->withMethod($method);
}

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

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

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

public function invalidParsedBodyParams()
public static function invalidParsedBodyParams()
{
return [
[4711],
Expand Down
7 changes: 1 addition & 6 deletions src/UploadedFileIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,7 @@ public function testGetSize()
$file = $this->createSubject();
$size = $file->getSize();
if ($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);
}
$this->assertMatchesRegularExpression('|^[0-9]+$|', (string) $size);
} else {
$this->assertNull($size);
}
Expand Down
50 changes: 25 additions & 25 deletions src/UriIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testWithSchemeInvalidArguments($schema)
$this->createUri('/')->withScheme($schema);
}

public function getInvalidSchemaArguments()
public static function getInvalidSchemaArguments()
{
return [
[true],
Expand Down Expand Up @@ -134,69 +134,69 @@ public function testPort()
/**
* @dataProvider getPaths
*/
public function testPath(UriInterface $uri, $expected)
public function testPath(string $uri, string $expected)
{
if (isset($this->skippedTests[__FUNCTION__])) {
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
}

$this->assertSame($expected, $uri->getPath());
$this->assertSame($expected, $this->createUri($uri)->getPath());
}

public function getPaths()
public static function getPaths()
{
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'],
['http://www.foo.com/', '/'],
['http://www.foo.com', ''],
['foo/bar', 'foo/bar'],
['http://www.foo.com/foo bar', '/foo%20bar'],
['http://www.foo.com/foo%20bar', '/foo%20bar'],
['http://www.foo.com/foo%2fbar', '/foo%2fbar'],
];
}

/**
* @dataProvider getQueries
*/
public function testQuery(UriInterface $uri, $expected)
public function testQuery(string $uri, string $expected)
{
if (isset($this->skippedTests[__FUNCTION__])) {
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
}

$this->assertSame($expected, $uri->getQuery());
$this->assertSame($expected, $this->createUri($uri)->getQuery());
}

public function getQueries()
public static function getQueries()
{
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'],
['http://www.foo.com', ''],
['http://www.foo.com?', ''],
['http://www.foo.com?foo=bar', 'foo=bar'],
['http://www.foo.com?foo=bar%26baz', 'foo=bar%26baz'],
['http://www.foo.com?foo=bar&baz=biz', 'foo=bar&baz=biz'],
];
}

/**
* @dataProvider getFragments
*/
public function testFragment(UriInterface $uri, $expected)
public function testFragment(string $uri, string $expected)
{
if (isset($this->skippedTests[__FUNCTION__])) {
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
}

$this->assertEquals($expected, $uri->getFragment());
$this->assertEquals($expected, $this->createUri($uri)->getFragment());
}

public function getFragments()
public static function getFragments()
{
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'],
['http://www.foo.com', ''],
['http://www.foo.com#', ''],
['http://www.foo.com#foo', 'foo'],
['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
2 changes: 1 addition & 1 deletion tests/Guzzle/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function createSubject()
return new Response();
}

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

Expand Down