Fixed tests

This commit is contained in:
Alejandro Celaya 2018-03-26 19:02:41 +02:00
parent 16dd1838aa
commit a27b01b895
25 changed files with 104 additions and 148 deletions

View file

@ -5,13 +5,8 @@ use Shlinkio\Shlink\Common\Factory\EmptyResponseImplicitOptionsMiddlewareFactory
use Zend\Expressive; use Zend\Expressive;
use Zend\Expressive\Container; use Zend\Expressive\Container;
use Zend\Expressive\Helper; use Zend\Expressive\Helper;
use Zend\Expressive\Middleware;
use Zend\Expressive\Plates;
use Zend\Expressive\Router;
use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware; use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware;
use Zend\Expressive\Template;
use Zend\ServiceManager\Factory\InvokableFactory; use Zend\ServiceManager\Factory\InvokableFactory;
use Zend\Stratigility\Middleware\ErrorHandler;
return [ return [

View file

@ -38,8 +38,8 @@ class EmptyResponseImplicitOptionsMiddlewareFactoryTest extends TestCase
$instance = $this->factory->__invoke(new ServiceManager(), ''); $instance = $this->factory->__invoke(new ServiceManager(), '');
$ref = new \ReflectionObject($instance); $ref = new \ReflectionObject($instance);
$prop = $ref->getProperty('response'); $prop = $ref->getProperty('responseFactory');
$prop->setAccessible(true); $prop->setAccessible(true);
$this->assertInstanceOf(EmptyResponse::class, $prop->getValue($instance)); $this->assertInstanceOf(EmptyResponse::class, $prop->getValue($instance)());
} }
} }

View file

@ -32,7 +32,7 @@ class LocaleMiddlewareTest extends TestCase
public function whenNoHeaderIsPresentLocaleIsNotChanged() public function whenNoHeaderIsPresentLocaleIsNotChanged()
{ {
$this->assertEquals('ru', $this->translator->getLocale()); $this->assertEquals('ru', $this->translator->getLocale());
$this->middleware->process(ServerRequestFactory::fromGlobals(), TestUtils::createDelegateMock()->reveal()); $this->middleware->process(ServerRequestFactory::fromGlobals(), TestUtils::createReqHandlerMock()->reveal());
$this->assertEquals('ru', $this->translator->getLocale()); $this->assertEquals('ru', $this->translator->getLocale());
} }
@ -43,7 +43,7 @@ class LocaleMiddlewareTest extends TestCase
{ {
$this->assertEquals('ru', $this->translator->getLocale()); $this->assertEquals('ru', $this->translator->getLocale());
$request = ServerRequestFactory::fromGlobals()->withHeader('Accept-Language', 'es'); $request = ServerRequestFactory::fromGlobals()->withHeader('Accept-Language', 'es');
$this->middleware->process($request, TestUtils::createDelegateMock()->reveal()); $this->middleware->process($request, TestUtils::createReqHandlerMock()->reveal());
$this->assertEquals('es', $this->translator->getLocale()); $this->assertEquals('es', $this->translator->getLocale());
} }
@ -52,7 +52,7 @@ class LocaleMiddlewareTest extends TestCase
*/ */
public function localeGetsNormalized() public function localeGetsNormalized()
{ {
$delegate = TestUtils::createDelegateMock(); $delegate = TestUtils::createReqHandlerMock();
$this->assertEquals('ru', $this->translator->getLocale()); $this->assertEquals('ru', $this->translator->getLocale());

View file

@ -7,18 +7,18 @@ use Prophecy\Argument;
use Prophecy\Prophet; use Prophecy\Prophet;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface; use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
class TestUtils class TestUtils
{ {
private static $prophet; private static $prophet;
public static function createDelegateMock(ResponseInterface $response = null, RequestInterface $request = null) public static function createReqHandlerMock(ResponseInterface $response = null, RequestInterface $request = null)
{ {
$argument = $request ?: Argument::any(); $argument = $request ?: Argument::any();
$delegate = static::getProphet()->prophesize(DelegateInterface::class); $delegate = static::getProphet()->prophesize(RequestHandlerInterface::class);
$delegate->process($argument)->willReturn($response ?: new Response()); $delegate->handle($argument)->willReturn($response ?: new Response());
return $delegate; return $delegate;
} }

View file

@ -7,7 +7,7 @@ use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface; use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Common\Service\PreviewGenerator; use Shlinkio\Shlink\Common\Service\PreviewGenerator;
use Shlinkio\Shlink\Core\Action\PreviewAction; use Shlinkio\Shlink\Core\Action\PreviewAction;
use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException; use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException;
@ -47,8 +47,8 @@ class PreviewActionTest extends TestCase
$shortCode = 'abc123'; $shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class) $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class)
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$delegate->process(Argument::cetera())->shouldBeCalledTimes(1) $delegate->handle(Argument::cetera())->shouldBeCalledTimes(1)
->willReturn(new Response()); ->willReturn(new Response());
$this->action->process( $this->action->process(
@ -70,7 +70,7 @@ class PreviewActionTest extends TestCase
$resp = $this->action->process( $resp = $this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode), ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
TestUtils::createDelegateMock()->reveal() TestUtils::createReqHandlerMock()->reveal()
); );
$this->assertEquals(filesize($path), $resp->getHeaderLine('Content-length')); $this->assertEquals(filesize($path), $resp->getHeaderLine('Content-length'));
@ -85,9 +85,9 @@ class PreviewActionTest extends TestCase
$shortCode = 'abc123'; $shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class) $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class)
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */ /** @var MethodProphecy $process */
$process = $delegate->process(Argument::any())->willReturn(new Response()); $process = $delegate->handle(Argument::any())->willReturn(new Response());
$this->action->process( $this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode), ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),

View file

@ -7,7 +7,7 @@ use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface; use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Common\Response\QrCodeResponse; use Shlinkio\Shlink\Common\Response\QrCodeResponse;
use Shlinkio\Shlink\Core\Action\QrCodeAction; use Shlinkio\Shlink\Core\Action\QrCodeAction;
use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException; use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException;
@ -46,8 +46,8 @@ class QrCodeActionTest extends TestCase
$shortCode = 'abc123'; $shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class) $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class)
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$process = $delegate->process(Argument::any())->willReturn(new Response()); $process = $delegate->handle(Argument::any())->willReturn(new Response());
$this->action->process( $this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode), ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
@ -65,9 +65,9 @@ class QrCodeActionTest extends TestCase
$shortCode = 'abc123'; $shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class) $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class)
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */ /** @var MethodProphecy $process */
$process = $delegate->process(Argument::any())->willReturn(new Response()); $process = $delegate->handle(Argument::any())->willReturn(new Response());
$this->action->process( $this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode), ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
@ -84,7 +84,7 @@ class QrCodeActionTest extends TestCase
{ {
$shortCode = 'abc123'; $shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn('')->shouldBeCalledTimes(1); $this->urlShortener->shortCodeToUrl($shortCode)->willReturn('')->shouldBeCalledTimes(1);
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$resp = $this->action->process( $resp = $this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode), ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
@ -93,6 +93,6 @@ class QrCodeActionTest extends TestCase
$this->assertInstanceOf(QrCodeResponse::class, $resp); $this->assertInstanceOf(QrCodeResponse::class, $resp);
$this->assertEquals(200, $resp->getStatusCode()); $this->assertEquals(200, $resp->getStatusCode());
$delegate->process(Argument::any())->shouldHaveBeenCalledTimes(0); $delegate->handle(Argument::any())->shouldHaveBeenCalledTimes(0);
} }
} }

View file

@ -7,7 +7,7 @@ use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface; use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Core\Action\RedirectAction; use Shlinkio\Shlink\Core\Action\RedirectAction;
use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException; use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException;
use Shlinkio\Shlink\Core\Options\AppOptions; use Shlinkio\Shlink\Core\Options\AppOptions;
@ -57,7 +57,7 @@ class RedirectActionTest extends TestCase
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal());
$this->assertInstanceOf(Response\RedirectResponse::class, $response); $this->assertInstanceOf(Response\RedirectResponse::class, $response);
$this->assertEquals(302, $response->getStatusCode()); $this->assertEquals(302, $response->getStatusCode());
@ -76,9 +76,9 @@ class RedirectActionTest extends TestCase
$this->visitTracker->track(Argument::cetera())->willReturn(null) $this->visitTracker->track(Argument::cetera())->willReturn(null)
->shouldNotBeCalled(); ->shouldNotBeCalled();
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */ /** @var MethodProphecy $process */
$process = $delegate->process(Argument::any())->willReturn(new Response()); $process = $delegate->handle(Argument::any())->willReturn(new Response());
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$this->action->process($request, $delegate->reveal()); $this->action->process($request, $delegate->reveal());
@ -100,7 +100,7 @@ class RedirectActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode) $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)
->withQueryParams(['foobar' => true]); ->withQueryParams(['foobar' => true]);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal());
$this->assertInstanceOf(Response\RedirectResponse::class, $response); $this->assertInstanceOf(Response\RedirectResponse::class, $response);
$this->assertEquals(302, $response->getStatusCode()); $this->assertEquals(302, $response->getStatusCode());

View file

@ -7,7 +7,7 @@ use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\Cache; use Doctrine\Common\Cache\Cache;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface; use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Core\Middleware\QrCodeCacheMiddleware; use Shlinkio\Shlink\Core\Middleware\QrCodeCacheMiddleware;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
@ -35,8 +35,8 @@ class QrCodeCacheMiddlewareTest extends TestCase
*/ */
public function noCachedPathFallsBackToNextMiddleware() public function noCachedPathFallsBackToNextMiddleware()
{ {
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$delegate->process(Argument::any())->willReturn(new Response())->shouldBeCalledTimes(1); $delegate->handle(Argument::any())->willReturn(new Response())->shouldBeCalledTimes(1);
$this->middleware->process(ServerRequestFactory::fromGlobals()->withUri( $this->middleware->process(ServerRequestFactory::fromGlobals()->withUri(
new Uri('/foo/bar') new Uri('/foo/bar')
@ -53,7 +53,7 @@ class QrCodeCacheMiddlewareTest extends TestCase
$isCalled = false; $isCalled = false;
$uri = (new Uri())->withPath('/foo'); $uri = (new Uri())->withPath('/foo');
$this->cache->save('/foo', ['body' => 'the body', 'content-type' => 'image/png']); $this->cache->save('/foo', ['body' => 'the body', 'content-type' => 'image/png']);
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$resp = $this->middleware->process( $resp = $this->middleware->process(
ServerRequestFactory::fromGlobals()->withUri($uri), ServerRequestFactory::fromGlobals()->withUri($uri),
@ -64,6 +64,6 @@ class QrCodeCacheMiddlewareTest extends TestCase
$resp->getBody()->rewind(); $resp->getBody()->rewind();
$this->assertEquals('the body', $resp->getBody()->getContents()); $this->assertEquals('the body', $resp->getBody()->getContents());
$this->assertEquals('image/png', $resp->getHeaderLine('Content-Type')); $this->assertEquals('image/png', $resp->getHeaderLine('Content-Type'));
$delegate->process(Argument::any())->shouldHaveBeenCalledTimes(0); $delegate->handle(Argument::any())->shouldHaveBeenCalledTimes(0);
} }
} }

View file

@ -43,7 +43,7 @@ class NotFoundDelegateTest extends TestCase
/** @var MethodProphecy $render */ /** @var MethodProphecy $render */
$render = $this->renderer->render(Argument::cetera())->willReturn(''); $render = $this->renderer->render(Argument::cetera())->willReturn('');
$resp = $this->delegate->process($request); $resp = $this->delegate->handle($request);
$this->assertInstanceOf($expectedResponse, $resp); $this->assertInstanceOf($expectedResponse, $resp);
$render->shouldHaveBeenCalledTimes($renderCalls); $render->shouldHaveBeenCalledTimes($renderCalls);

View file

@ -5,7 +5,6 @@ namespace Shlinkio\Shlink\Rest\Action\Tag;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Shlinkio\Shlink\Rest\Action\AbstractRestAction; use Shlinkio\Shlink\Rest\Action\AbstractRestAction;

View file

@ -10,7 +10,6 @@ use Shlinkio\Shlink\Rest\Action\AuthenticateAction;
use Shlinkio\Shlink\Rest\Authentication\JWTService; use Shlinkio\Shlink\Rest\Authentication\JWTService;
use Shlinkio\Shlink\Rest\Entity\ApiKey; use Shlinkio\Shlink\Rest\Entity\ApiKey;
use Shlinkio\Shlink\Rest\Service\ApiKeyService; use Shlinkio\Shlink\Rest\Service\ApiKeyService;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator; use Zend\I18n\Translator\Translator;
@ -47,7 +46,7 @@ class AuthenticateActionTest extends TestCase
*/ */
public function notProvidingAuthDataReturnsError() public function notProvidingAuthDataReturnsError()
{ {
$resp = $this->action->process(ServerRequestFactory::fromGlobals(), TestUtils::createDelegateMock()->reveal()); $resp = $this->action->handle(ServerRequestFactory::fromGlobals());
$this->assertEquals(400, $resp->getStatusCode()); $this->assertEquals(400, $resp->getStatusCode());
} }
@ -62,7 +61,7 @@ class AuthenticateActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withParsedBody([ $request = ServerRequestFactory::fromGlobals()->withParsedBody([
'apiKey' => 'foo', 'apiKey' => 'foo',
]); ]);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->action->handle($request);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$response->getBody()->rewind(); $response->getBody()->rewind();
@ -80,7 +79,7 @@ class AuthenticateActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withParsedBody([ $request = ServerRequestFactory::fromGlobals()->withParsedBody([
'apiKey' => 'foo', 'apiKey' => 'foo',
]); ]);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->action->handle($request);
$this->assertEquals(401, $response->getStatusCode()); $this->assertEquals(401, $response->getStatusCode());
} }
} }

View file

@ -11,7 +11,6 @@ use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException;
use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\Service\UrlShortener;
use Shlinkio\Shlink\Rest\Action\CreateShortcodeAction; use Shlinkio\Shlink\Rest\Action\CreateShortcodeAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\Diactoros\Uri; use Zend\Diactoros\Uri;
use Zend\I18n\Translator\Translator; use Zend\I18n\Translator\Translator;
@ -41,10 +40,7 @@ class CreateShortcodeActionTest extends TestCase
*/ */
public function missingLongUrlParamReturnsError() public function missingLongUrlParamReturnsError()
{ {
$response = $this->action->process( $response = $this->action->handle(ServerRequestFactory::fromGlobals());
ServerRequestFactory::fromGlobals(),
TestUtils::createDelegateMock()->reveal()
);
$this->assertEquals(400, $response->getStatusCode()); $this->assertEquals(400, $response->getStatusCode());
} }
@ -60,7 +56,7 @@ class CreateShortcodeActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withParsedBody([ $request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar', 'longUrl' => 'http://www.domain.com/foo/bar',
]); ]);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->action->handle($request);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), 'http://foo.com/abc123') > 0); $this->assertTrue(strpos($response->getBody()->getContents(), 'http://foo.com/abc123') > 0);
} }
@ -77,7 +73,7 @@ class CreateShortcodeActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withParsedBody([ $request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar', 'longUrl' => 'http://www.domain.com/foo/bar',
]); ]);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->action->handle($request);
$this->assertEquals(400, $response->getStatusCode()); $this->assertEquals(400, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_URL_ERROR) > 0); $this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_URL_ERROR) > 0);
} }
@ -100,7 +96,7 @@ class CreateShortcodeActionTest extends TestCase
'longUrl' => 'http://www.domain.com/foo/bar', 'longUrl' => 'http://www.domain.com/foo/bar',
'customSlug' => 'foo', 'customSlug' => 'foo',
]); ]);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->action->handle($request);
$this->assertEquals(400, $response->getStatusCode()); $this->assertEquals(400, $response->getStatusCode());
$this->assertContains(RestUtils::INVALID_SLUG_ERROR, (string) $response->getBody()); $this->assertContains(RestUtils::INVALID_SLUG_ERROR, (string) $response->getBody());
} }
@ -117,7 +113,7 @@ class CreateShortcodeActionTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withParsedBody([ $request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar', 'longUrl' => 'http://www.domain.com/foo/bar',
]); ]);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->action->handle($request);
$this->assertEquals(500, $response->getStatusCode()); $this->assertEquals(500, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::UNKNOWN_ERROR) > 0); $this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::UNKNOWN_ERROR) > 0);
} }

View file

@ -6,7 +6,6 @@ namespace ShlinkioTest\Shlink\Rest\Action;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface;
use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException; use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface; use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
@ -43,7 +42,7 @@ class EditShortCodeActionTest extends TestCase
]); ]);
/** @var JsonResponse $resp */ /** @var JsonResponse $resp */
$resp = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal()); $resp = $this->action->handle($request);
$payload = $resp->getPayload(); $payload = $resp->getPayload();
$this->assertEquals(400, $resp->getStatusCode()); $this->assertEquals(400, $resp->getStatusCode());
@ -65,7 +64,7 @@ class EditShortCodeActionTest extends TestCase
); );
/** @var JsonResponse $resp */ /** @var JsonResponse $resp */
$resp = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal()); $resp = $this->action->handle($request);
$payload = $resp->getPayload(); $payload = $resp->getPayload();
$this->assertEquals(404, $resp->getStatusCode()); $this->assertEquals(404, $resp->getStatusCode());
@ -85,7 +84,7 @@ class EditShortCodeActionTest extends TestCase
]); ]);
$updateMeta = $this->shortUrlService->updateMetadataByShortCode(Argument::cetera())->willReturn(new ShortUrl()); $updateMeta = $this->shortUrlService->updateMetadataByShortCode(Argument::cetera())->willReturn(new ShortUrl());
$resp = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal()); $resp = $this->action->handle($request);
$this->assertEquals(204, $resp->getStatusCode()); $this->assertEquals(204, $resp->getStatusCode());
$updateMeta->shouldHaveBeenCalled(); $updateMeta->shouldHaveBeenCalled();

View file

@ -9,7 +9,6 @@ use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException; use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Service\ShortUrlService; use Shlinkio\Shlink\Core\Service\ShortUrlService;
use Shlinkio\Shlink\Rest\Action\EditShortcodeTagsAction; use Shlinkio\Shlink\Rest\Action\EditShortcodeTagsAction;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator; use Zend\I18n\Translator\Translator;
@ -35,10 +34,7 @@ class EditShortcodeTagsActionTest extends TestCase
*/ */
public function notProvidingTagsReturnsError() public function notProvidingTagsReturnsError()
{ {
$response = $this->action->process( $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123'));
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123'),
TestUtils::createDelegateMock()->reveal()
);
$this->assertEquals(400, $response->getStatusCode()); $this->assertEquals(400, $response->getStatusCode());
} }
@ -51,10 +47,9 @@ class EditShortcodeTagsActionTest extends TestCase
$this->shortUrlService->setTagsByShortCode($shortCode, [])->willThrow(InvalidShortCodeException::class) $this->shortUrlService->setTagsByShortCode($shortCode, [])->willThrow(InvalidShortCodeException::class)
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$response = $this->action->process( $response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123') ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123')
->withParsedBody(['tags' => []]), ->withParsedBody(['tags' => []])
TestUtils::createDelegateMock()->reveal()
); );
$this->assertEquals(404, $response->getStatusCode()); $this->assertEquals(404, $response->getStatusCode());
} }
@ -68,10 +63,9 @@ class EditShortcodeTagsActionTest extends TestCase
$this->shortUrlService->setTagsByShortCode($shortCode, [])->willReturn(new ShortUrl()) $this->shortUrlService->setTagsByShortCode($shortCode, [])->willReturn(new ShortUrl())
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$response = $this->action->process( $response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123') ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123')
->withParsedBody(['tags' => []]), ->withParsedBody(['tags' => []])
TestUtils::createDelegateMock()->reveal()
); );
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
} }

View file

@ -10,7 +10,6 @@ use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Common\Util\DateRange;
use Shlinkio\Shlink\Core\Service\VisitsTracker; use Shlinkio\Shlink\Core\Service\VisitsTracker;
use Shlinkio\Shlink\Rest\Action\GetVisitsAction; use Shlinkio\Shlink\Rest\Action\GetVisitsAction;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator; use Zend\I18n\Translator\Translator;
@ -40,10 +39,7 @@ class GetVisitsActionTest extends TestCase
$this->visitsTracker->info($shortCode, Argument::type(DateRange::class))->willReturn([]) $this->visitsTracker->info($shortCode, Argument::type(DateRange::class))->willReturn([])
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$response = $this->action->process( $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
TestUtils::createDelegateMock()->reveal()
);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
} }
@ -57,10 +53,7 @@ class GetVisitsActionTest extends TestCase
InvalidArgumentException::class InvalidArgumentException::class
)->shouldBeCalledTimes(1); )->shouldBeCalledTimes(1);
$response = $this->action->process( $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
TestUtils::createDelegateMock()->reveal()
);
$this->assertEquals(404, $response->getStatusCode()); $this->assertEquals(404, $response->getStatusCode());
} }
@ -74,10 +67,7 @@ class GetVisitsActionTest extends TestCase
\Exception::class \Exception::class
)->shouldBeCalledTimes(1); )->shouldBeCalledTimes(1);
$response = $this->action->process( $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
TestUtils::createDelegateMock()->reveal()
);
$this->assertEquals(500, $response->getStatusCode()); $this->assertEquals(500, $response->getStatusCode());
} }
@ -91,10 +81,9 @@ class GetVisitsActionTest extends TestCase
->willReturn([]) ->willReturn([])
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$response = $this->action->process( $response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode) ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)
->withQueryParams(['endDate' => '2016-01-01 00:00:00']), ->withQueryParams(['endDate' => '2016-01-01 00:00:00'])
TestUtils::createDelegateMock()->reveal()
); );
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
} }

View file

@ -7,7 +7,6 @@ use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Service\ShortUrlService; use Shlinkio\Shlink\Core\Service\ShortUrlService;
use Shlinkio\Shlink\Rest\Action\ListShortcodesAction; use Shlinkio\Shlink\Rest\Action\ListShortcodesAction;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator; use Zend\I18n\Translator\Translator;
use Zend\Paginator\Adapter\ArrayAdapter; use Zend\Paginator\Adapter\ArrayAdapter;
@ -39,12 +38,9 @@ class ListShortCodesActionTest extends TestCase
$this->service->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter())) $this->service->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$response = $this->action->process( $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
ServerRequestFactory::fromGlobals()->withQueryParams([ 'page' => $page,
'page' => $page, ]));
]),
TestUtils::createDelegateMock()->reveal()
);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
} }
@ -57,12 +53,9 @@ class ListShortCodesActionTest extends TestCase
$this->service->listShortUrls($page, null, [], null)->willThrow(\Exception::class) $this->service->listShortUrls($page, null, [], null)->willThrow(\Exception::class)
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$response = $this->action->process( $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
ServerRequestFactory::fromGlobals()->withQueryParams([ 'page' => $page,
'page' => $page, ]));
]),
TestUtils::createDelegateMock()->reveal()
);
$this->assertEquals(500, $response->getStatusCode()); $this->assertEquals(500, $response->getStatusCode());
} }
} }

View file

@ -10,7 +10,6 @@ use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\Service\UrlShortener;
use Shlinkio\Shlink\Rest\Action\ResolveUrlAction; use Shlinkio\Shlink\Rest\Action\ResolveUrlAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator; use Zend\I18n\Translator\Translator;
@ -41,7 +40,7 @@ class ResolveUrlActionTest extends TestCase
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->action->handle($request);
$this->assertEquals(404, $response->getStatusCode()); $this->assertEquals(404, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_ARGUMENT_ERROR) > 0); $this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_ARGUMENT_ERROR) > 0);
} }
@ -56,7 +55,7 @@ class ResolveUrlActionTest extends TestCase
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->action->handle($request);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), 'http://domain.com/foo/bar') > 0); $this->assertTrue(strpos($response->getBody()->getContents(), 'http://domain.com/foo/bar') > 0);
} }
@ -71,7 +70,7 @@ class ResolveUrlActionTest extends TestCase
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->action->handle($request);
$this->assertEquals(400, $response->getStatusCode()); $this->assertEquals(400, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_SHORTCODE_ERROR) > 0); $this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_SHORTCODE_ERROR) > 0);
} }
@ -86,7 +85,7 @@ class ResolveUrlActionTest extends TestCase
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->action->handle($request);
$this->assertEquals(500, $response->getStatusCode()); $this->assertEquals(500, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::UNKNOWN_ERROR) > 0); $this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::UNKNOWN_ERROR) > 0);
} }

View file

@ -7,7 +7,6 @@ use Doctrine\Common\Collections\ArrayCollection;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Shlinkio\Shlink\Rest\Action\Tag\CreateTagsAction; use Shlinkio\Shlink\Rest\Action\Tag\CreateTagsAction;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
@ -40,7 +39,7 @@ class CreateTagsActionTest extends TestCase
/** @var MethodProphecy $deleteTags */ /** @var MethodProphecy $deleteTags */
$deleteTags = $this->tagService->createTags($tags ?: [])->willReturn(new ArrayCollection()); $deleteTags = $this->tagService->createTags($tags ?: [])->willReturn(new ArrayCollection());
$response = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal()); $response = $this->action->handle($request);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$deleteTags->shouldHaveBeenCalled(); $deleteTags->shouldHaveBeenCalled();

View file

@ -6,7 +6,6 @@ namespace ShlinkioTest\Shlink\Rest\Action\Tag;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Shlinkio\Shlink\Rest\Action\Tag\DeleteTagsAction; use Shlinkio\Shlink\Rest\Action\Tag\DeleteTagsAction;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
@ -39,7 +38,7 @@ class DeleteTagsActionTest extends TestCase
/** @var MethodProphecy $deleteTags */ /** @var MethodProphecy $deleteTags */
$deleteTags = $this->tagService->deleteTags($tags ?: []); $deleteTags = $this->tagService->deleteTags($tags ?: []);
$response = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal()); $response = $this->action->handle($request);
$this->assertEquals(204, $response->getStatusCode()); $this->assertEquals(204, $response->getStatusCode());
$deleteTags->shouldHaveBeenCalled(); $deleteTags->shouldHaveBeenCalled();

View file

@ -6,7 +6,6 @@ namespace ShlinkioTest\Shlink\Rest\Action\Tag;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface;
use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Shlinkio\Shlink\Rest\Action\Tag\ListTagsAction; use Shlinkio\Shlink\Rest\Action\Tag\ListTagsAction;
@ -37,10 +36,7 @@ class ListTagsActionTest extends TestCase
/** @var MethodProphecy $listTags */ /** @var MethodProphecy $listTags */
$listTags = $this->tagService->listTags()->willReturn([new Tag('foo'), new Tag('bar')]); $listTags = $this->tagService->listTags()->willReturn([new Tag('foo'), new Tag('bar')]);
$resp = $this->action->process( $resp = $this->action->handle(ServerRequestFactory::fromGlobals());
ServerRequestFactory::fromGlobals(),
$this->prophesize(DelegateInterface::class)->reveal()
);
$this->assertEquals([ $this->assertEquals([
'tags' => [ 'tags' => [

View file

@ -6,7 +6,6 @@ namespace ShlinkioTest\Shlink\Rest\Action\Tag;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface;
use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException; use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
@ -39,7 +38,7 @@ class UpdateTagActionTest extends TestCase
public function whenInvalidParamsAreProvidedAnErrorIsReturned(array $bodyParams) public function whenInvalidParamsAreProvidedAnErrorIsReturned(array $bodyParams)
{ {
$request = ServerRequestFactory::fromGlobals()->withParsedBody($bodyParams); $request = ServerRequestFactory::fromGlobals()->withParsedBody($bodyParams);
$resp = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal()); $resp = $this->action->handle($request);
$this->assertEquals(400, $resp->getStatusCode()); $this->assertEquals(400, $resp->getStatusCode());
} }
@ -65,7 +64,7 @@ class UpdateTagActionTest extends TestCase
/** @var MethodProphecy $rename */ /** @var MethodProphecy $rename */
$rename = $this->tagService->renameTag('foo', 'bar')->willThrow(EntityDoesNotExistException::class); $rename = $this->tagService->renameTag('foo', 'bar')->willThrow(EntityDoesNotExistException::class);
$resp = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal()); $resp = $this->action->handle($request);
$this->assertEquals(404, $resp->getStatusCode()); $this->assertEquals(404, $resp->getStatusCode());
$rename->shouldHaveBeenCalled(); $rename->shouldHaveBeenCalled();
@ -83,7 +82,7 @@ class UpdateTagActionTest extends TestCase
/** @var MethodProphecy $rename */ /** @var MethodProphecy $rename */
$rename = $this->tagService->renameTag('foo', 'bar')->willReturn(new Tag()); $rename = $this->tagService->renameTag('foo', 'bar')->willReturn(new Tag());
$resp = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal()); $resp = $this->action->handle($request);
$this->assertEquals(204, $resp->getStatusCode()); $this->assertEquals(204, $resp->getStatusCode());
$rename->shouldHaveBeenCalled(); $rename->shouldHaveBeenCalled();

View file

@ -7,7 +7,7 @@ use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\MethodProphecy;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface; use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Rest\Middleware\BodyParserMiddleware; use Shlinkio\Shlink\Rest\Middleware\BodyParserMiddleware;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
@ -31,9 +31,9 @@ class BodyParserMiddlewareTest extends TestCase
public function requestsFromOtherMethodsJustFallbackToNextMiddleware() public function requestsFromOtherMethodsJustFallbackToNextMiddleware()
{ {
$request = ServerRequestFactory::fromGlobals()->withMethod('GET'); $request = ServerRequestFactory::fromGlobals()->withMethod('GET');
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */ /** @var MethodProphecy $process */
$process = $delegate->process($request)->willReturn(new Response()); $process = $delegate->handle($request)->willReturn(new Response());
$this->middleware->process($request, $delegate->reveal()); $this->middleware->process($request, $delegate->reveal());
@ -51,9 +51,9 @@ class BodyParserMiddlewareTest extends TestCase
$request = ServerRequestFactory::fromGlobals()->withMethod('PUT') $request = ServerRequestFactory::fromGlobals()->withMethod('PUT')
->withBody($body) ->withBody($body)
->withHeader('content-type', 'application/json'); ->withHeader('content-type', 'application/json');
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */ /** @var MethodProphecy $process */
$process = $delegate->process(Argument::type(ServerRequestInterface::class))->will( $process = $delegate->handle(Argument::type(ServerRequestInterface::class))->will(
function (array $args) use ($test) { function (array $args) use ($test) {
/** @var ServerRequestInterface $req */ /** @var ServerRequestInterface $req */
$req = array_shift($args); $req = array_shift($args);
@ -82,9 +82,9 @@ class BodyParserMiddlewareTest extends TestCase
$body->write('foo=bar&bar[]=one&bar[]=5'); $body->write('foo=bar&bar[]=one&bar[]=5');
$request = ServerRequestFactory::fromGlobals()->withMethod('PUT') $request = ServerRequestFactory::fromGlobals()->withMethod('PUT')
->withBody($body); ->withBody($body);
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */ /** @var MethodProphecy $process */
$process = $delegate->process(Argument::type(ServerRequestInterface::class))->will( $process = $delegate->handle(Argument::type(ServerRequestInterface::class))->will(
function (array $args) use ($test) { function (array $args) use ($test) {
/** @var ServerRequestInterface $req */ /** @var ServerRequestInterface $req */
$req = array_shift($args); $req = array_shift($args);

View file

@ -6,7 +6,7 @@ namespace ShlinkioTest\Shlink\Rest\Middleware;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface; use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Rest\Action\AuthenticateAction; use Shlinkio\Shlink\Rest\Action\AuthenticateAction;
use Shlinkio\Shlink\Rest\Authentication\JWTService; use Shlinkio\Shlink\Rest\Authentication\JWTService;
use Shlinkio\Shlink\Rest\Middleware\CheckAuthenticationMiddleware; use Shlinkio\Shlink\Rest\Middleware\CheckAuthenticationMiddleware;
@ -49,9 +49,9 @@ class CheckAuthenticationMiddlewareTest extends TestCase
public function someWhiteListedSituationsFallbackToNextMiddleware() public function someWhiteListedSituationsFallbackToNextMiddleware()
{ {
$request = ServerRequestFactory::fromGlobals(); $request = ServerRequestFactory::fromGlobals();
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */ /** @var MethodProphecy $process */
$process = $delegate->process($request)->willReturn(new Response()); $process = $delegate->handle($request)->willReturn(new Response());
$this->middleware->process($request, $delegate->reveal()); $this->middleware->process($request, $delegate->reveal());
$process->shouldHaveBeenCalledTimes(1); $process->shouldHaveBeenCalledTimes(1);
@ -60,9 +60,9 @@ class CheckAuthenticationMiddlewareTest extends TestCase
RouteResult::class, RouteResult::class,
RouteResult::fromRouteFailure(['GET']) RouteResult::fromRouteFailure(['GET'])
); );
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */ /** @var MethodProphecy $process */
$process = $delegate->process($request)->willReturn(new Response()); $process = $delegate->handle($request)->willReturn(new Response());
$this->middleware->process($request, $delegate->reveal()); $this->middleware->process($request, $delegate->reveal());
$process->shouldHaveBeenCalledTimes(1); $process->shouldHaveBeenCalledTimes(1);
@ -75,9 +75,9 @@ class CheckAuthenticationMiddlewareTest extends TestCase
AuthenticateAction::class AuthenticateAction::class
)) ))
); );
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */ /** @var MethodProphecy $process */
$process = $delegate->process($request)->willReturn(new Response()); $process = $delegate->handle($request)->willReturn(new Response());
$this->middleware->process($request, $delegate->reveal()); $this->middleware->process($request, $delegate->reveal());
$process->shouldHaveBeenCalledTimes(1); $process->shouldHaveBeenCalledTimes(1);
@ -85,9 +85,9 @@ class CheckAuthenticationMiddlewareTest extends TestCase
RouteResult::class, RouteResult::class,
RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), []) RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), [])
)->withMethod('OPTIONS'); )->withMethod('OPTIONS');
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */ /** @var MethodProphecy $process */
$process = $delegate->process($request)->willReturn(new Response()); $process = $delegate->handle($request)->willReturn(new Response());
$this->middleware->process($request, $delegate->reveal()); $this->middleware->process($request, $delegate->reveal());
$process->shouldHaveBeenCalledTimes(1); $process->shouldHaveBeenCalledTimes(1);
} }
@ -101,7 +101,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase
RouteResult::class, RouteResult::class,
RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), []) RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), [])
); );
$response = $this->middleware->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->middleware->process($request, TestUtils::createReqHandlerMock()->reveal());
$this->assertEquals(401, $response->getStatusCode()); $this->assertEquals(401, $response->getStatusCode());
} }
@ -116,7 +116,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase
RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), []) RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), [])
)->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, $authToken); )->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, $authToken);
$response = $this->middleware->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->middleware->process($request, TestUtils::createReqHandlerMock()->reveal());
$this->assertEquals(401, $response->getStatusCode()); $this->assertEquals(401, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), 'You need to provide the Bearer type') > 0); $this->assertTrue(strpos($response->getBody()->getContents(), 'You need to provide the Bearer type') > 0);
@ -133,7 +133,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase
RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), []) RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), [])
)->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'Basic ' . $authToken); )->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'Basic ' . $authToken);
$response = $this->middleware->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->middleware->process($request, TestUtils::createReqHandlerMock()->reveal());
$this->assertEquals(401, $response->getStatusCode()); $this->assertEquals(401, $response->getStatusCode());
$this->assertTrue( $this->assertTrue(
@ -153,7 +153,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase
)->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'Bearer ' . $authToken); )->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'Bearer ' . $authToken);
$this->jwtService->verify($authToken)->willReturn(false)->shouldBeCalledTimes(1); $this->jwtService->verify($authToken)->willReturn(false)->shouldBeCalledTimes(1);
$response = $this->middleware->process($request, TestUtils::createDelegateMock()->reveal()); $response = $this->middleware->process($request, TestUtils::createReqHandlerMock()->reveal());
$this->assertEquals(401, $response->getStatusCode()); $this->assertEquals(401, $response->getStatusCode());
} }
@ -170,9 +170,9 @@ class CheckAuthenticationMiddlewareTest extends TestCase
$this->jwtService->verify($authToken)->willReturn(true)->shouldBeCalledTimes(1); $this->jwtService->verify($authToken)->willReturn(true)->shouldBeCalledTimes(1);
$this->jwtService->refresh($authToken)->willReturn($authToken)->shouldBeCalledTimes(1); $this->jwtService->refresh($authToken)->willReturn($authToken)->shouldBeCalledTimes(1);
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */ /** @var MethodProphecy $process */
$process = $delegate->process($request)->willReturn(new Response()); $process = $delegate->handle($request)->willReturn(new Response());
$resp = $this->middleware->process($request, $delegate->reveal()); $resp = $this->middleware->process($request, $delegate->reveal());
$process->shouldHaveBeenCalledTimes(1); $process->shouldHaveBeenCalledTimes(1);

View file

@ -6,7 +6,7 @@ namespace ShlinkioTest\Shlink\Rest\Middleware;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface; use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Rest\Middleware\CrossDomainMiddleware; use Shlinkio\Shlink\Rest\Middleware\CrossDomainMiddleware;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
@ -25,7 +25,7 @@ class CrossDomainMiddlewareTest extends TestCase
public function setUp() public function setUp()
{ {
$this->middleware = new CrossDomainMiddleware(); $this->middleware = new CrossDomainMiddleware();
$this->delegate = $this->prophesize(DelegateInterface::class); $this->delegate = $this->prophesize(RequestHandlerInterface::class);
} }
/** /**
@ -34,7 +34,7 @@ class CrossDomainMiddlewareTest extends TestCase
public function nonCrossDomainRequestsAreNotAffected() public function nonCrossDomainRequestsAreNotAffected()
{ {
$originalResponse = new Response(); $originalResponse = new Response();
$this->delegate->process(Argument::any())->willReturn($originalResponse)->shouldbeCalledTimes(1); $this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldbeCalledTimes(1);
$response = $this->middleware->process(ServerRequestFactory::fromGlobals(), $this->delegate->reveal()); $response = $this->middleware->process(ServerRequestFactory::fromGlobals(), $this->delegate->reveal());
$this->assertSame($originalResponse, $response); $this->assertSame($originalResponse, $response);
@ -50,7 +50,7 @@ class CrossDomainMiddlewareTest extends TestCase
public function anyRequestIncludesTheAllowAccessHeader() public function anyRequestIncludesTheAllowAccessHeader()
{ {
$originalResponse = new Response(); $originalResponse = new Response();
$this->delegate->process(Argument::any())->willReturn($originalResponse)->shouldbeCalledTimes(1); $this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldbeCalledTimes(1);
$response = $this->middleware->process( $response = $this->middleware->process(
ServerRequestFactory::fromGlobals()->withHeader('Origin', 'local'), ServerRequestFactory::fromGlobals()->withHeader('Origin', 'local'),
@ -70,7 +70,7 @@ class CrossDomainMiddlewareTest extends TestCase
{ {
$originalResponse = new Response(); $originalResponse = new Response();
$request = ServerRequestFactory::fromGlobals()->withMethod('OPTIONS')->withHeader('Origin', 'local'); $request = ServerRequestFactory::fromGlobals()->withMethod('OPTIONS')->withHeader('Origin', 'local');
$this->delegate->process(Argument::any())->willReturn($originalResponse)->shouldbeCalledTimes(1); $this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldbeCalledTimes(1);
$response = $this->middleware->process($request, $this->delegate->reveal()); $response = $this->middleware->process($request, $this->delegate->reveal());
$this->assertNotSame($originalResponse, $response); $this->assertNotSame($originalResponse, $response);

View file

@ -7,7 +7,7 @@ use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as DelegateInterface; use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Rest\Middleware\PathVersionMiddleware; use Shlinkio\Shlink\Rest\Middleware\PathVersionMiddleware;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequestFactory;
@ -32,8 +32,8 @@ class PathVersionMiddlewareTest extends TestCase
{ {
$request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/v2/foo')); $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/v2/foo'));
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$process = $delegate->process($request)->willReturn(new Response()); $process = $delegate->handle($request)->willReturn(new Response());
$this->middleware->process($request, $delegate->reveal()); $this->middleware->process($request, $delegate->reveal());
@ -47,8 +47,8 @@ class PathVersionMiddlewareTest extends TestCase
{ {
$request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/foo')); $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/foo'));
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$process = $delegate->process($request)->willReturn(new Response()); $process = $delegate->handle($request)->willReturn(new Response());
$this->middleware->process($request, $delegate->reveal()); $this->middleware->process($request, $delegate->reveal());
@ -62,8 +62,8 @@ class PathVersionMiddlewareTest extends TestCase
{ {
$request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/bar/baz')); $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/bar/baz'));
$delegate = $this->prophesize(DelegateInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$delegate->process(Argument::type(Request::class))->will(function (array $args) use ($request) { $delegate->handle(Argument::type(Request::class))->will(function (array $args) use ($request) {
$req = \array_shift($args); $req = \array_shift($args);
Assert::assertNotSame($request, $req); Assert::assertNotSame($request, $req);