Skip to content

Commit

Permalink
Add support for PHPUnit 10 and PHPUnit 11
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Apr 12, 2024
1 parent bedb6e5 commit 7a14542
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 215 deletions.
62 changes: 21 additions & 41 deletions BaseUriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@

use GuzzleHttp\Psr7\Utils;
use Nyholm\Psr7\Factory\Psr17Factory;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UriInterface as Psr7UriInterface;

/**
* @group modifier
* @coversDefaultClass \League\Uri\BaseUri
*/
#[CoversClass(BaseUri::class)]
#[Group('modifier')]
final class BaseUriTest extends TestCase
{
private const BASE_URI = 'http://a/b/c/d;p?q';
Expand All @@ -32,9 +33,7 @@ public function testItCanBeJsonSerialized(): void
);
}

/**
* @dataProvider resolveProvider
*/
#[DataProvider('resolveProvider')]
public function testCreateResolve(string $baseUri, string $uri, string $expected): void
{
$uriResolved = BaseUri::from($baseUri)->resolve($uri);
Expand Down Expand Up @@ -100,9 +99,7 @@ public function testRelativizeIsNotMade(): void
self::assertEquals($uri, BaseUri::from('https://example.com/path')->relativize($uri)->getUriString());
}

/**
* @dataProvider relativizeProvider
*/
#[DataProvider('relativizeProvider')]
public function testRelativize(string $uri, string $resolved, string $expected): void
{
self::assertSame(
Expand Down Expand Up @@ -154,9 +151,7 @@ public static function relativizeProvider(): array
];
}

/**
* @dataProvider relativizeAndResolveProvider
*/
#[DataProvider('relativizeAndResolveProvider')]
public function testRelativizeAndResolve(
string $baseUri,
string $uri,
Expand Down Expand Up @@ -187,10 +182,9 @@ public static function relativizeAndResolveProvider(): array
}

/**
* @dataProvider uriProvider
*
* @param array<bool> $infos
*/
#[DataProvider('uriProvider')]
public function testInfo(
Psr7UriInterface|Uri $uri,
Psr7UriInterface|Uri|null $base_uri,
Expand Down Expand Up @@ -263,9 +257,7 @@ public function testIsFunctionsThrowsTypeError(): void
self::assertTrue(BaseUri::from('example.com#foobar')->isRelativePath());
}

/**
* @dataProvider sameValueAsProvider
*/
#[DataProvider('sameValueAsProvider')]
public function testSameValueAs(Psr7UriInterface|Uri $uri1, Psr7UriInterface|Uri $uri2, bool $expected): void
{
self::assertSame($expected, BaseUri::from($uri2)->isSameDocument($uri1));
Expand Down Expand Up @@ -322,9 +314,7 @@ public static function sameValueAsProvider(): array
];
}

/**
* @dataProvider getOriginProvider
*/
#[DataProvider('getOriginProvider')]
public function testGetOrigin(Psr7UriInterface|Uri|string $uri, ?string $expectedOrigin): void
{
self::assertSame($expectedOrigin, BaseUri::from($uri)->origin()?->__toString());
Expand Down Expand Up @@ -372,9 +362,7 @@ public static function getOriginProvider(): array
];
}

/**
* @dataProvider getCrossOriginExamples
*/
#[DataProvider('getCrossOriginExamples')]
public function testIsCrossOrigin(string $original, string $modified, bool $expected): void
{
self::assertSame($expected, BaseUri::from($original)->isCrossOrigin($modified));
Expand Down Expand Up @@ -403,9 +391,7 @@ public static function getCrossOriginExamples(): array
];
}

/**
* @dataProvider resolveProvider
*/
#[DataProvider('resolveProvider')]
public function testResolveWithPsr7Implementation(string $baseUri, string $uri, string $expected): void
{
$resolvedUri = BaseUri::from(Utils::uriFor($baseUri))->resolve($uri);
Expand All @@ -414,9 +400,7 @@ public function testResolveWithPsr7Implementation(string $baseUri, string $uri,
self::assertSame($expected, (string) $resolvedUri);
}

/**
* @dataProvider relativizeProvider
*/
#[DataProvider('relativizeProvider')]
public function testRelativizeWithPsr7Implementation(string $uriString, string $resolved, string $expected): void
{
$uri = Utils::uriFor($uriString);
Expand All @@ -436,9 +420,7 @@ public function testRelativizeWithPsr7Implementation(string $uriString, string $
self::assertSame($expected, (string) $relativizeUri);
}

/**
* @dataProvider getOriginProvider
*/
#[DataProvider('getOriginProvider')]
public function testGetOriginWithPsr7Implementation(Psr7UriInterface|Uri|string $uri, ?string $expectedOrigin): void
{
$origin = BaseUri::from(Utils::uriFor((string) $uri), new \GuzzleHttp\Psr7\HttpFactory())->origin();
Expand All @@ -452,9 +434,7 @@ public function testGetOriginWithPsr7Implementation(Psr7UriInterface|Uri|string
self::assertSame($expectedOrigin, $origin);
}

/**
* @dataProvider provideIDNUri
*/
#[DataProvider('provideIDNUri')]
public function testHostIsIDN(string $uri, bool $expected): void
{
self::assertSame($expected, BaseUri::from($uri)->hasIdn());
Expand Down Expand Up @@ -489,7 +469,7 @@ public static function provideIDNUri(): iterable
];
}

/** @dataProvider unixpathProvider */
#[DataProvider('unixpathProvider')]
public function testReturnsUnixPath(?string $expected, string $input): void
{
self::assertSame($expected, BaseUri::from($input)->unixPath());
Expand All @@ -505,11 +485,11 @@ public static function unixpathProvider(): array
],
'absolute path' => [
'expected' => '/path',
'inout' => 'file:///path',
'input' => 'file:///path',
],
'path with empty char' => [
'expected' => '/path empty/bar',
'inout' => 'file:///path%20empty/bar',
'input' => 'file:///path%20empty/bar',
],
'relative path with dot segments' => [
'expected' => 'path/./relative',
Expand All @@ -526,7 +506,7 @@ public static function unixpathProvider(): array
];
}

/** @dataProvider windowLocalPathProvider */
#[DataProvider('windowLocalPathProvider')]
public function testReturnsWindowsPath(?string $expected, string $input): void
{
self::assertSame($expected, BaseUri::from($input)->windowsPath());
Expand Down Expand Up @@ -575,7 +555,7 @@ public static function windowLocalPathProvider(): array
];
}

/** @dataProvider rfc8089UriProvider */
#[DataProvider('rfc8089UriProvider')]
public function testReturnsRFC8089UriString(?string $expected, string $input): void
{
self::assertSame($expected, BaseUri::from($input)->toRfc8089());
Expand Down
23 changes: 9 additions & 14 deletions DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
namespace League\Uri;

use League\Uri\Exceptions\SyntaxError;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;

/**
* @group data
* @group uri
* @coversDefaultClass \League\Uri\Uri
*/
#[CoversClass(\League\Uri\Uri::class)]
#[Group('data')]
#[Group('uri')]
final class DataTest extends TestCase
{
public function testDefaultConstructor(): void
Expand All @@ -29,9 +30,7 @@ public function testDefaultConstructor(): void
);
}

/**
* @dataProvider validUrlProvider
*/
#[DataProvider('validUrlProvider')]
public function testCreateFromString(string $uri, string $path): void
{
self::assertSame($path, Uri::new($uri)->getPath());
Expand Down Expand Up @@ -63,9 +62,7 @@ public static function validUrlProvider(): array
];
}

/**
* @dataProvider invalidUrlProvider
*/
#[DataProvider('invalidUrlProvider')]
public function testCreateFromStringFailed(string $uri): void
{
self::expectException(SyntaxError::class);
Expand All @@ -80,9 +77,7 @@ public static function invalidUrlProvider(): array
}


/**
* @dataProvider invalidComponentProvider
*/
#[DataProvider('invalidComponentProvider')]
public function testCreateFromStringFailedWithWrongComponent(string $uri): void
{
self::expectException(SyntaxError::class);
Expand Down
47 changes: 18 additions & 29 deletions FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@

use League\Uri\Exceptions\SyntaxError;
use Nyholm\Psr7\Uri as NyholmUri;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Stringable;

/**
* @group factory
* @coversDefaultClass \League\Uri\Uri
*/
#[CoversClass(Uri::class)]
#[Group('factory')]
final class FactoryTest extends TestCase
{
/**
* @dataProvider invalidDataPath
*/
#[DataProvider('invalidDataPath')]
public function testCreateFromPathFailed(string $path): void
{
self::expectException(SyntaxError::class);
Expand All @@ -38,9 +37,7 @@ public static function invalidDataPath(): array
];
}

/**
* @dataProvider validFilePath
*/
#[DataProvider('validFilePath')]
public function testCreateFromPath(string $path, string $expected): void
{
$context = stream_context_create([
Expand All @@ -62,7 +59,7 @@ public static function validFilePath(): array
];
}

/** @dataProvider provideValidData */
#[DataProvider('provideValidData')]
public function testFromData(string $data, string $mimetype, string $parameters, string $expected): void
{
self::assertSame($expected, Uri::fromData($data, $mimetype, $parameters)->toString());
Expand Down Expand Up @@ -141,12 +138,10 @@ public function testFromDataFailsWithMalformedParameters(): void
Uri::fromData('Hello World!', 'text/plain', 'foobar');
}

/**
* @dataProvider unixpathProvider
*/
public function testCreateFromUnixPath(string $uri, string $expected): void
#[DataProvider('unixpathProvider')]
public function testCreateFromUnixPath(string $input, string $expected): void
{
self::assertSame($expected, Uri::fromUnixPath($uri)->toString());
self::assertSame($expected, Uri::fromUnixPath($input)->toString());
}

public static function unixpathProvider(): array
Expand Down Expand Up @@ -175,12 +170,10 @@ public static function unixpathProvider(): array
];
}

/**
* @dataProvider windowLocalPathProvider
*/
public function testCreateFromWindowsLocalPath(string $uri, string $expected): void
#[DataProvider('windowLocalPathProvider')]
public function testCreateFromWindowsLocalPath(string $input, string $expected): void
{
self::assertSame($expected, Uri::fromWindowsPath($uri)->toString());
self::assertSame($expected, Uri::fromWindowsPath($input)->toString());
}

public static function windowLocalPathProvider(): array
Expand Down Expand Up @@ -221,7 +214,7 @@ public static function windowLocalPathProvider(): array
];
}

/** @dataProvider rfc8089UriProvider */
#[DataProvider('rfc8089UriProvider')]
public function testCreateFromRfc8089(string $expected, string $uri): void
{
self::assertSame($expected, Uri::fromRfc8089($uri)->toString());
Expand All @@ -245,7 +238,7 @@ public static function rfc8089UriProvider(): iterable
];
}

/** @dataProvider invalidRfc8089UriProvider */
#[DataProvider('invalidRfc8089UriProvider')]
public function testIfFailsToGenerateAnUriFromRfc8089(string $invalidUri): void
{
$this->expectException(SyntaxError::class);
Expand Down Expand Up @@ -281,9 +274,7 @@ public function testCreateFromUri(): void
self::assertSame((string) $uribis, Uri::new($uribis)->toString());
}

/**
* @dataProvider validServerArray
*/
#[DataProvider('validServerArray')]
public function testCreateFromServer(string $expected, array $input): void
{
self::assertSame($expected, Uri::fromServer($input)->toString());
Expand Down Expand Up @@ -459,9 +450,7 @@ public function testFailCreateFromServerWithoutInvalidUserInfo(): void
]);
}

/**
* @dataProvider createProvider
*/
#[DataProvider('createProvider')]
public function testCreateFromBaseUri(Stringable|string $baseUri, Stringable|string $uri, string $expected): void
{
self::assertSame($expected, Uri::fromBaseUri($uri, $baseUri)->toString());
Expand Down
19 changes: 8 additions & 11 deletions FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,22 @@
namespace League\Uri;

use League\Uri\Exceptions\SyntaxError;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;

/**
* @group file
* @group uri
* @coversDefaultClass \League\Uri\Uri
*/
#[CoversClass(\League\Uri\Uri::class)]
#[Group('file')]
#[Group('uri')]
final class FileTest extends TestCase
{
public function testDefaultConstructor(): void
{
self::assertSame('', (string) Uri::new());
}

/**
* @dataProvider validUrlProvider
*/
#[DataProvider('validUrlProvider')]
public function testCreateFromString(string $uri, string $expected): void
{
self::assertSame($expected, (string) Uri::new($uri));
Expand Down Expand Up @@ -80,9 +79,7 @@ public static function validUrlProvider(): array
];
}

/**
* @dataProvider invalidUrlProvider
*/
#[DataProvider('invalidUrlProvider')]
public function testConstructorThrowsException(string $uri): void
{
self::expectException(SyntaxError::class);
Expand Down
Loading

0 comments on commit 7a14542

Please sign in to comment.