mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Created and registered middleware which replaces short-code from short-url on rest paths
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Rest\Middleware\ShortUrl;
|
||||
|
||||
use PHPUnit\Framework\Assert;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Shlinkio\Shlink\Rest\Middleware\ShortUrl\ShortCodePathMiddleware;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Uri;
|
||||
|
||||
class ShortCodePathMiddlewareTest extends TestCase
|
||||
{
|
||||
private $middleware;
|
||||
private $requestHandler;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->middleware = new ShortCodePathMiddleware();
|
||||
$this->requestHandler = $this->prophesize(RequestHandlerInterface::class);
|
||||
$this->requestHandler->handle(Argument::type(ServerRequestInterface::class))->willReturn(new Response());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function properlyReplacesTheOldPathByTheNewOne()
|
||||
{
|
||||
$uri = new Uri('/short-codes/foo');
|
||||
|
||||
$request = $this->prophesize(ServerRequestInterface::class);
|
||||
$request->getUri()->willReturn($uri);
|
||||
$withUri = $request->withUri(Argument::that(function (UriInterface $uri) {
|
||||
$path = $uri->getPath();
|
||||
|
||||
Assert::assertContains('/short-urls', $path);
|
||||
Assert::assertNotContains('/short-codes', $path);
|
||||
|
||||
return $uri;
|
||||
}))->willReturn($request->reveal());
|
||||
|
||||
$this->middleware->process($request->reveal(), $this->requestHandler->reveal());
|
||||
|
||||
$withUri->shouldHaveBeenCalledTimes(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user