Skip to content

Commit

Permalink
Drop support for older league/uri components
Browse files Browse the repository at this point in the history
Fixes #376.
  • Loading branch information
trowski committed Dec 16, 2024
1 parent 4b87c0f commit c74232a
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 34 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"amphp/pipeline": "^1",
"amphp/socket": "^2.1",
"amphp/sync": "^2.2",
"league/uri": "^6.8 | ^7.1",
"league/uri-interfaces": "^2.3 | ^7.1",
"league/uri": "^7.1",
"league/uri-interfaces": "^7.1",
"psr/http-message": "^1 | ^2",
"psr/log": "^1 | ^2 | ^3",
"revolt/event-loop": "^1"
Expand All @@ -49,7 +49,7 @@
"amphp/http-client": "^5",
"amphp/log": "^2",
"amphp/php-cs-fixer-config": "^2",
"league/uri-components": "^2.4.2 | ^7.1",
"league/uri-components": "^7.1",
"monolog/monolog": "^3",
"phpunit/phpunit": "^9",
"psalm/phar": "~5.23"
Expand Down
12 changes: 4 additions & 8 deletions src/Driver/Http1Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,24 +274,21 @@ public function handleClient(
$target = \substr($target, 0, $position);
}

/** @psalm-suppress DeprecatedMethod */
$uri = Uri\Http::createFromComponents([
$uri = Uri\Http::fromComponents([
"scheme" => $scheme,
"host" => $host,
"port" => $port,
"path" => $target,
"query" => $query,
]);
} elseif ($target === "*") { // asterisk-form
/** @psalm-suppress DeprecatedMethod */
$uri = Uri\Http::createFromComponents([
$uri = Uri\Http::fromComponents([
"scheme" => $scheme,
"host" => $host,
"port" => $port,
]);
} elseif (\preg_match("#^https?://#i", $target)) { // absolute-form
/** @psalm-suppress DeprecatedMethod */
$uri = Uri\Http::createFromString($target);
$uri = Uri\Http::new($target);

if ($uri->getHost() !== $host || $uri->getPort() !== $port) {
throw new ClientException(
Expand Down Expand Up @@ -325,8 +322,7 @@ public function handleClient(
);
}

/** @psalm-suppress DeprecatedMethod */
$uri = Uri\Http::createFromComponents([
$uri = Uri\Http::fromComponents([
"host" => $matches[1],
"port" => (int) $matches[2],
]);
Expand Down
6 changes: 2 additions & 4 deletions src/Driver/Http2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -996,15 +996,13 @@ public function handleHeaders(int $streamId, array $pseudo, array $headers, bool

try {
if ($target === "*") {
/** @psalm-suppress DeprecatedMethod */
$uri = Uri\Http::createFromComponents([
$uri = Uri\Http::fromComponents([
"scheme" => $scheme,
"host" => $host,
"port" => $port,
]);
} else {
/** @psalm-suppress DeprecatedMethod */
$uri = Uri\Http::createFromComponents([
$uri = Uri\Http::fromComponents([
"scheme" => $scheme,
"host" => $host,
"port" => $port,
Expand Down
3 changes: 1 addition & 2 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ public function getPushes(): array
public function push(string $url, array $headers = []): void
{
try {
/** @psalm-suppress DeprecatedMethod */
$uri = Uri\Http::createFromString($url);
$uri = Uri\Http::new($url);
} catch (\Exception $exception) {
throw new \Error("Invalid push URI: " . $exception->getMessage(), 0, $exception);
}
Expand Down
4 changes: 2 additions & 2 deletions test/Driver/Http1DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,15 +756,15 @@ public function testPipelinedRequests(): void

self::assertSame($results[1], $request->getBody()->buffer());

$request = new Request($this->createClientMock(), "GET", Uri\Http::createFromString("/"));
$request = new Request($this->createClientMock(), "GET", Uri\Http::new("/"));

delay(0.01); // Allow parser generator to continue.

self::assertInstanceOf(Request::class, $request);

self::assertSame($results[0], $request->getBody()->buffer());

$request = new Request($this->createClientMock(), "POST", Uri\Http::createFromString("/"));
$request = new Request($this->createClientMock(), "POST", Uri\Http::new("/"));

self::assertSame(3, $responses);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Driver/SocketClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testTrivialHttpRequest(): void
[$address, $server] = $this->startServer(function (Request $req) {
$this->assertEquals("GET", $req->getMethod());
$this->assertEquals("/uri", $req->getUri()->getPath());
$query = Query::createFromUri($req->getUri());
$query = Query::fromUri($req->getUri());
$this->assertEquals(
[["foo", "bar"], ["baz", "1"], ["baz", "2"]],
\iterator_to_array($query->getIterator())
Expand Down
2 changes: 1 addition & 1 deletion test/Middleware/ExceptionHandlerMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ExceptionHandlerMiddlewareTest extends AsyncTestCase
{
private function setupAndInvokeMiddleware(ExceptionHandler $exceptionHandler, \Throwable $exception): Response
{
$request = new Request($this->createMock(Client::class), 'GET', Http::createFromString('/'));
$request = new Request($this->createMock(Client::class), 'GET', Http::new('/'));

$requestHandler = $this->createMock(RequestHandler::class);
$requestHandler->expects(self::once())
Expand Down
2 changes: 1 addition & 1 deletion test/Middleware/StackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class StackTest extends AsyncTestCase
{
public function testStackAppliesMiddlewaresInCorrectOrder(): void
{
$request = new Request($this->createMock(Client::class), "GET", Uri\Http::createFromString("/foobar"));
$request = new Request($this->createMock(Client::class), "GET", Uri\Http::new("/foobar"));

$stack = stackMiddleware(new ClosureRequestHandler(function (Request $request) {
$response = new Response(HttpStatus::OK, [], "OK");
Expand Down
24 changes: 12 additions & 12 deletions test/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class RequestTest extends AsyncTestCase
public function testGetClient(): void
{
$client = $this->createMock(Client::class);
$request = new Request($client, 'GET', Http::createFromString('/'));
$request = new Request($client, 'GET', Http::new('/'));
self::assertSame($client, $request->getClient());
}

public function testSetMethod(): void
{
$client = $this->createMock(Client::class);
$request = new Request($client, 'GET', Http::createFromString('/'));
$request = new Request($client, 'GET', Http::new('/'));
self::assertSame('GET', $request->getMethod());
$request->setMethod('POST');
self::assertSame('POST', $request->getMethod());
Expand All @@ -31,16 +31,16 @@ public function testSetMethod(): void
public function testSetUri(): void
{
$client = $this->createMock(Client::class);
$request = new Request($client, 'GET', Http::createFromString('/'));
$request = new Request($client, 'GET', Http::new('/'));
self::assertSame('/', (string) $request->getUri());
$request->setUri(Http::createFromString('/foobar'));
$request->setUri(Http::new('/foobar'));
self::assertSame('/foobar', (string) $request->getUri());
}

public function testSetProtocolVersion(): void
{
$client = $this->createMock(Client::class);
$request = new Request($client, 'GET', Http::createFromString('/'));
$request = new Request($client, 'GET', Http::new('/'));
self::assertSame('1.1', $request->getProtocolVersion());
$request->setProtocolVersion('1.0');
self::assertSame('1.0', $request->getProtocolVersion());
Expand All @@ -49,7 +49,7 @@ public function testSetProtocolVersion(): void
public function testGetHeader(): void
{
$client = $this->createMock(Client::class);
$request = new Request($client, 'GET', Http::createFromString('/'), [
$request = new Request($client, 'GET', Http::new('/'), [
'foo' => 'bar',
]);

Expand All @@ -65,7 +65,7 @@ public function testGetHeader(): void
public function testAddHeader(): void
{
$client = $this->createMock(Client::class);
$request = new Request($client, 'GET', Http::createFromString('/'), [
$request = new Request($client, 'GET', Http::new('/'), [
'foo' => 'bar',
]);

Expand All @@ -81,7 +81,7 @@ public function testAddHeader(): void
public function testSetHeader(): void
{
$client = $this->createMock(Client::class);
$request = new Request($client, 'GET', Http::createFromString('/'), [
$request = new Request($client, 'GET', Http::new('/'), [
'foo' => 'bar',
]);

Expand All @@ -101,7 +101,7 @@ public function testSetHeader(): void
public function testGetAttribute(): void
{
$client = $this->createMock(Client::class);
$request = new Request($client, 'GET', Http::createFromString('/'));
$request = new Request($client, 'GET', Http::new('/'));

$request->setAttribute('foo', 'bar');
self::assertSame('bar', $request->getAttribute('foo'));
Expand All @@ -124,7 +124,7 @@ public function testGetAttribute(): void
public function testSetBody(): void
{
$client = $this->createMock(Client::class);
$request = new Request($client, 'POST', Http::createFromString('/'), [
$request = new Request($client, 'POST', Http::new('/'), [
'content-length' => '0',
]);

Expand All @@ -140,15 +140,15 @@ public function testSetBody(): void
$request->setBody(new ReadableBuffer('foo'));
self::assertFalse($request->hasHeader('content-length'));

$request = new Request($client, 'GET', Http::createFromString('/'));
$request = new Request($client, 'GET', Http::new('/'));
$request->setBody('');
self::assertFalse($request->hasHeader('content-length'));
}

public function testCookies(): void
{
$client = $this->createMock(Client::class);
$request = new Request($client, 'GET', Http::createFromString('/'), [
$request = new Request($client, 'GET', Http::new('/'), [
'cookie' => (string) new RequestCookie('foo', 'bar'),
]);

Expand Down

0 comments on commit c74232a

Please sign in to comment.