Improve ExtraPathRedirectMiddlewareTest

This commit is contained in:
Alejandro Celaya 2024-11-14 09:17:41 +01:00
parent 51d838870d
commit fd34332e69
2 changed files with 10 additions and 1 deletions

View File

@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
This change applies both to the `GET /short-urls` endpoint, via the `domain` query parameter, and the `short-url:list` console command, via the `--domain`|`-d` flag. This change applies both to the `GET /short-urls` endpoint, via the `domain` query parameter, and the `short-url:list` console command, via the `--domain`|`-d` flag.
* [#1774](https://github.com/shlinkio/shlink/issues/1774) Add new geolocation redirect rules for the dynamic redirects system.
* `geolocation-country-code`: Allows to perform redirections based on the ISO 3166-1 alpha-2 two-letter country code resolved while geolocating the visitor.
### Changed ### Changed
* [#2193](https://github.com/shlinkio/shlink/issues/2193) API keys are now hashed using SHA256, instead of being saved in plain text. * [#2193](https://github.com/shlinkio/shlink/issues/2193) API keys are now hashed using SHA256, instead of being saved in plain text.

View File

@ -9,6 +9,7 @@ use Laminas\Diactoros\ServerRequestFactory;
use Laminas\Diactoros\Uri; use Laminas\Diactoros\Uri;
use Mezzio\Router\Route; use Mezzio\Router\Route;
use Mezzio\Router\RouteResult; use Mezzio\Router\RouteResult;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
@ -26,6 +27,7 @@ use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
use Shlinkio\Shlink\Core\ShortUrl\ShortUrlResolverInterface; use Shlinkio\Shlink\Core\ShortUrl\ShortUrlResolverInterface;
use Shlinkio\Shlink\Core\Util\RedirectResponseHelperInterface; use Shlinkio\Shlink\Core\Util\RedirectResponseHelperInterface;
use Shlinkio\Shlink\Core\Visit\RequestTrackerInterface; use Shlinkio\Shlink\Core\Visit\RequestTrackerInterface;
use Shlinkio\Shlink\IpGeolocation\Model\Location;
use function Laminas\Stratigility\middleware; use function Laminas\Stratigility\middleware;
use function str_starts_with; use function str_starts_with;
@ -153,7 +155,10 @@ class ExtraPathRedirectMiddlewareTest extends TestCase
); );
$this->redirectionBuilder->expects($this->once())->method('buildShortUrlRedirect')->with( $this->redirectionBuilder->expects($this->once())->method('buildShortUrlRedirect')->with(
$shortUrl, $shortUrl,
$this->isInstanceOf(ServerRequestInterface::class), $this->callback(function (ServerRequestInterface $req) {
Assert::assertArrayHasKey(Location::class, $req->getAttributes());
return true;
}),
$expectedExtraPath, $expectedExtraPath,
)->willReturn('the_built_long_url'); )->willReturn('the_built_long_url');
$this->redirectResponseHelper->expects($this->once())->method('buildRedirectResponse')->with( $this->redirectResponseHelper->expects($this->once())->method('buildRedirectResponse')->with(