mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-22 23:23:42 -06:00
Created PathVersionMiddlewareTest
This commit is contained in:
parent
42f86a4a24
commit
31594d47b3
47
module/Rest/test/Middleware/PathVersionMiddlewareTest.php
Normal file
47
module/Rest/test/Middleware/PathVersionMiddlewareTest.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace ShlinkioTest\Shlink\Rest\Middleware;
|
||||
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Shlinkio\Shlink\Rest\Middleware\PathVersionMiddleware;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\ServerRequestFactory;
|
||||
use Zend\Diactoros\Uri;
|
||||
|
||||
class PathVersionMiddlewareTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var PathVersionMiddleware
|
||||
*/
|
||||
protected $middleware;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->middleware = new PathVersionMiddleware();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function whenVersionIsProvidedRequestRemainsUnchanged()
|
||||
{
|
||||
$request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/v2/foo'));
|
||||
$test = $this;
|
||||
$this->middleware->__invoke($request, new Response(), function ($req) use ($request, $test) {
|
||||
$test->assertSame($request, $req);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function versionOneIsPrependedWhenNoVersionIsDefined()
|
||||
{
|
||||
$request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/bar/baz'));
|
||||
$test = $this;
|
||||
$this->middleware->__invoke($request, new Response(), function (Request $req) use ($request, $test) {
|
||||
$test->assertNotSame($request, $req);
|
||||
$this->assertEquals('/rest/v1/bar/baz', $req->getUri()->getPath());
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user