From 0db72c16fa79edf21bed1a748a90d0c1c5d8fe5c Mon Sep 17 00:00:00 2001 From: Ignace Nyamagana Butera Date: Sat, 28 May 2022 07:31:10 +0200 Subject: [PATCH] Adding PSR-7 integration tests --- composer.json | 7 ++++--- src/HttpTest.php | 3 +-- src/Uri.php | 2 +- src/UriPsr7IntegrationTest.php | 25 +++++++++++++++++++++++++ src/UriTest.php | 3 ++- 5 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 src/UriPsr7IntegrationTest.php diff --git a/composer.json b/composer.json index ef2e0dd1..2059a5f4 100644 --- a/composer.json +++ b/composer.json @@ -51,11 +51,12 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^v3.3.2", - "phpunit/phpunit" : "^9.5.10", + "php-http/psr7-integration-tests": "^1.1", "phpstan/phpstan": "^1.2.0", - "phpstan/phpstan-strict-rules": "^1.1.0", - "phpstan/phpstan-phpunit": "^1.0.0", "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.0.0", + "phpstan/phpstan-strict-rules": "^1.1.0", + "phpunit/phpunit": "^9.5.10", "psr/http-factory": "^1.0" }, "autoload": { diff --git a/src/HttpTest.php b/src/HttpTest.php index a70a7b0d..10aa961a 100644 --- a/src/HttpTest.php +++ b/src/HttpTest.php @@ -14,7 +14,6 @@ use InvalidArgumentException; use League\Uri\Exceptions\SyntaxError; use PHPUnit\Framework\TestCase; -use TypeError; /** * @group http @@ -52,7 +51,7 @@ public function testInvalidPort(): void */ public function testThrowTypeErrorOnWrongType(): void { - self::expectException(TypeError::class); + self::expectException(InvalidArgumentException::class); Http::createFromString('https://example.com')->withFragment([]); } diff --git a/src/Uri.php b/src/Uri.php index 49c198ee..42127304 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -1199,7 +1199,7 @@ private function filterString($str): ?string } if (!is_scalar($str)) { - throw new TypeError(sprintf('The component must be a string, a scalar or a stringable object %s given.', gettype($str))); + throw new SyntaxError(sprintf('The component must be a string, a scalar or a stringable object; `%s` given.', gettype($str))); } $str = (string) $str; diff --git a/src/UriPsr7IntegrationTest.php b/src/UriPsr7IntegrationTest.php new file mode 100644 index 00000000..112529fa --- /dev/null +++ b/src/UriPsr7IntegrationTest.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace League\Uri; + +use Http\Psr7Test\UriIntegrationTest; +use Psr\Http\Message\UriInterface; + +final class UriPsr7IntegrationTest extends UriIntegrationTest +{ + public function createUri($uri): UriInterface + { + return (new HttpFactory())->createUri($uri); + } +} diff --git a/src/UriTest.php b/src/UriTest.php index 5dfd5546..b11913f7 100644 --- a/src/UriTest.php +++ b/src/UriTest.php @@ -11,6 +11,7 @@ namespace League\Uri; +use InvalidArgumentException; use League\Uri\Exceptions\SyntaxError; use PHPUnit\Framework\TestCase; use TypeError; @@ -253,7 +254,7 @@ public function testWithSchemeFailedWithInvalidSchemeValue(): void */ public function testWithInvalidCharacters(): void { - self::expectException(TypeError::class); + self::expectException(InvalidArgumentException::class); Uri::createFromString('')->withPath(date_create()); }