mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-09 08:43:13 +08:00
Test behavior to track redirect URL
This commit is contained in:
@@ -4,7 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\ErrorHandler;
|
||||
|
||||
use Laminas\Diactoros\Response;
|
||||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -14,6 +16,8 @@ use Shlinkio\Shlink\Core\ErrorHandler\Model\NotFoundType;
|
||||
use Shlinkio\Shlink\Core\ErrorHandler\NotFoundTrackerMiddleware;
|
||||
use Shlinkio\Shlink\Core\Visit\RequestTrackerInterface;
|
||||
|
||||
use const Shlinkio\Shlink\REDIRECT_URL_REQUEST_ATTRIBUTE;
|
||||
|
||||
class NotFoundTrackerMiddlewareTest extends TestCase
|
||||
{
|
||||
private NotFoundTrackerMiddleware $middleware;
|
||||
@@ -33,12 +37,22 @@ class NotFoundTrackerMiddlewareTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function delegatesIntoRequestTracker(): void
|
||||
#[Test, DataProvider('provideResponses')]
|
||||
public function delegatesIntoRequestTracker(Response $resp, string|null $expectedRedirectUrl): void
|
||||
{
|
||||
$this->handler->expects($this->once())->method('handle')->with($this->request);
|
||||
$this->requestTracker->expects($this->once())->method('trackNotFoundIfApplicable')->with($this->request);
|
||||
$this->handler->expects($this->once())->method('handle')->with($this->request)->willReturn($resp);
|
||||
$this->requestTracker->expects($this->once())->method('trackNotFoundIfApplicable')->with(
|
||||
$this->request->withAttribute(REDIRECT_URL_REQUEST_ATTRIBUTE, $expectedRedirectUrl),
|
||||
);
|
||||
|
||||
$this->middleware->process($this->request, $this->handler);
|
||||
$result = $this->middleware->process($this->request, $this->handler);
|
||||
|
||||
self::assertSame($resp, $result);
|
||||
}
|
||||
|
||||
public static function provideResponses(): iterable
|
||||
{
|
||||
yield 'no location response' => [new Response(), null];
|
||||
yield 'location response' => [new Response\RedirectResponse('the_location'), 'the_location'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user