diff --git a/composer.json b/composer.json index 86e35f3f..d733ba89 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,7 @@ "laminas/laminas-servicemanager": "^3.4", "laminas/laminas-stdlib": "^3.2", "lcobucci/jwt": "^4.0@alpha", + "league/uri": "^6.2", "lstrojny/functional-php": "^1.9", "mezzio/mezzio": "^3.2", "mezzio/mezzio-fastroute": "^3.0", diff --git a/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php index bcf00acb..689a5e7c 100644 --- a/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php @@ -8,7 +8,6 @@ use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; -use Psr\Http\Message\UriInterface; use Shlinkio\Shlink\CLI\Command\ShortUrl\GenerateShortUrlCommand; use Shlinkio\Shlink\CLI\Util\ExitCodes; use Shlinkio\Shlink\Core\Entity\ShortUrl; @@ -88,7 +87,7 @@ class GenerateShortUrlCommandTest extends TestCase { $shortUrl = new ShortUrl(''); $urlToShortCode = $this->urlShortener->urlToShortCode( - Argument::type(UriInterface::class), + Argument::type('string'), Argument::that(function (array $tags) { Assert::assertEquals(['foo', 'bar', 'baz', 'boo', 'zar'], $tags); return $tags; diff --git a/module/Core/src/Action/AbstractTrackingAction.php b/module/Core/src/Action/AbstractTrackingAction.php index 4d883794..4bf391c7 100644 --- a/module/Core/src/Action/AbstractTrackingAction.php +++ b/module/Core/src/Action/AbstractTrackingAction.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Action; use Fig\Http\Message\RequestMethodInterface; -use Laminas\Diactoros\Uri; +use League\Uri\Uri; use Mezzio\Router\Middleware\ImplicitHeadMiddleware; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -67,7 +67,7 @@ abstract class AbstractTrackingAction implements MiddlewareInterface, RequestMet private function buildUrlToRedirectTo(ShortUrl $shortUrl, array $currentQuery, ?string $disableTrackParam): string { - $uri = new Uri($shortUrl->getLongUrl()); + $uri = Uri::createFromString($shortUrl->getLongUrl()); $hardcodedQuery = parse_query($uri->getQuery()); if ($disableTrackParam !== null) { unset($currentQuery[$disableTrackParam]); diff --git a/module/Core/test/Service/UrlShortenerTest.php b/module/Core/test/Service/UrlShortenerTest.php index 2c67bf27..f1ef88af 100644 --- a/module/Core/test/Service/UrlShortenerTest.php +++ b/module/Core/test/Service/UrlShortenerTest.php @@ -9,7 +9,6 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\ORMException; -use Laminas\Diactoros\Uri; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; @@ -65,7 +64,7 @@ class UrlShortenerTest extends TestCase public function urlIsProperlyShortened(): void { $shortUrl = $this->urlShortener->urlToShortCode( - new Uri('http://foobar.com/12345/hello?foo=bar'), + 'http://foobar.com/12345/hello?foo=bar', [], ShortUrlMeta::createEmpty(), ); @@ -89,7 +88,7 @@ class UrlShortenerTest extends TestCase $getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal()); $shortUrl = $this->urlShortener->urlToShortCode( - new Uri('http://foobar.com/12345/hello?foo=bar'), + 'http://foobar.com/12345/hello?foo=bar', [], ShortUrlMeta::createEmpty(), ); @@ -112,7 +111,7 @@ class UrlShortenerTest extends TestCase $this->expectException(ORMException::class); $this->urlShortener->urlToShortCode( - new Uri('http://foobar.com/12345/hello?foo=bar'), + 'http://foobar.com/12345/hello?foo=bar', [], ShortUrlMeta::createEmpty(), ); @@ -131,7 +130,7 @@ class UrlShortenerTest extends TestCase $this->expectException(NonUniqueSlugException::class); $this->urlShortener->urlToShortCode( - new Uri('http://foobar.com/12345/hello?foo=bar'), + 'http://foobar.com/12345/hello?foo=bar', [], ShortUrlMeta::fromRawData(['customSlug' => 'custom-slug']), ); @@ -151,7 +150,7 @@ class UrlShortenerTest extends TestCase $findExisting = $repo->findBy(Argument::any())->willReturn([$expected]); $getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal()); - $result = $this->urlShortener->urlToShortCode(new Uri($url), $tags, $meta); + $result = $this->urlShortener->urlToShortCode($url, $tags, $meta); $findExisting->shouldHaveBeenCalledOnce(); $getRepo->shouldHaveBeenCalledOnce(); @@ -235,7 +234,7 @@ class UrlShortenerTest extends TestCase ]); $getRepo = $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal()); - $result = $this->urlShortener->urlToShortCode(new Uri($url), $tags, $meta); + $result = $this->urlShortener->urlToShortCode($url, $tags, $meta); $this->assertSame($expected, $result); $findExisting->shouldHaveBeenCalledOnce(); diff --git a/module/Rest/src/Action/ShortUrl/SingleStepCreateShortUrlAction.php b/module/Rest/src/Action/ShortUrl/SingleStepCreateShortUrlAction.php index 0a6a45d4..46385556 100644 --- a/module/Rest/src/Action/ShortUrl/SingleStepCreateShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/SingleStepCreateShortUrlAction.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Rest\Action\ShortUrl; -use Laminas\Diactoros\Uri; use Psr\Http\Message\ServerRequestInterface as Request; use Shlinkio\Shlink\Core\Exception\ValidationException; use Shlinkio\Shlink\Core\Model\CreateShortUrlData; diff --git a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php index 3a343d60..66f1eaaa 100644 --- a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php @@ -7,7 +7,6 @@ namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl; use Cake\Chronos\Chronos; use Laminas\Diactoros\ServerRequest; use Laminas\Diactoros\ServerRequestFactory; -use Laminas\Diactoros\Uri; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; @@ -50,7 +49,7 @@ class CreateShortUrlActionTest extends TestCase { $shortUrl = new ShortUrl(''); $shorten = $this->urlShortener->urlToShortCode( - Argument::type(Uri::class), + Argument::type('string'), Argument::type('array'), $expectedMeta, )->willReturn($shortUrl); diff --git a/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php index 1af4aeba..d63a83b9 100644 --- a/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php @@ -9,7 +9,6 @@ use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; -use Psr\Http\Message\UriInterface; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Exception\ValidationException; use Shlinkio\Shlink\Core\Model\ShortUrlMeta; @@ -71,8 +70,8 @@ class SingleStepCreateShortUrlActionTest extends TestCase ]); $findApiKey = $this->apiKeyService->check('abc123')->willReturn(true); $generateShortCode = $this->urlShortener->urlToShortCode( - Argument::that(function (UriInterface $argument) { - Assert::assertEquals('http://foobar.com', (string) $argument); + Argument::that(function (string $argument): string { + Assert::assertEquals('http://foobar.com', $argument); return $argument; }), [],