Migrated BodyParserMiddleware to psr-15 middleware

This commit is contained in:
Alejandro Celaya
2017-03-25 09:22:00 +01:00
parent 6c87436a96
commit 22c76df8e6
6 changed files with 86 additions and 72 deletions
@@ -1,16 +1,15 @@
<?php
namespace ShlinkioTest\Shlink\Core\Action;
use Interop\Http\ServerMiddleware\DelegateInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Common\Exception\PreviewGenerationException;
use Shlinkio\Shlink\Common\Service\PreviewGenerator;
use Shlinkio\Shlink\Core\Action\PreviewAction;
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Service\UrlShortener;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory;
class PreviewActionTest extends TestCase
@@ -42,14 +41,13 @@ class PreviewActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn(null)->shouldBeCalledTimes(1);
$delegate = TestUtils::createDelegateMock();
$delegate = $this->prophesize(DelegateInterface::class);
$delegate->process(Argument::cetera())->shouldBeCalledTimes(1);
$this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
$delegate->reveal()
);
$delegate->process(Argument::cetera())->shouldHaveBeenCalledTimes(1);
}
/**
@@ -75,12 +73,12 @@ class PreviewActionTest extends TestCase
/**
* @test
*/
public function invalidShortcodeExceptionFallsBackToNextMiddleware()
public function invalidShortCodeExceptionFallsBackToNextMiddleware()
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class)
->shouldBeCalledTimes(1);
$delegate = TestUtils::createDelegateMock();
$delegate = $this->prophesize(DelegateInterface::class);
$this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
+4 -4
View File
@@ -1,6 +1,7 @@
<?php
namespace ShlinkioTest\Shlink\Core\Action;
use Interop\Http\ServerMiddleware\DelegateInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
@@ -9,7 +10,6 @@ use Shlinkio\Shlink\Core\Action\QrCodeAction;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Service\UrlShortener;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory;
use Zend\Expressive\Router\RouterInterface;
@@ -41,7 +41,7 @@ class QrCodeActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn(null)->shouldBeCalledTimes(1);
$delegate = TestUtils::createDelegateMock();
$delegate = $this->prophesize(DelegateInterface::class);
$this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
@@ -59,7 +59,7 @@ class QrCodeActionTest extends TestCase
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class)
->shouldBeCalledTimes(1);
$delegate = TestUtils::createDelegateMock();
$delegate = $this->prophesize(DelegateInterface::class);
$this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
@@ -76,7 +76,7 @@ class QrCodeActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn(new ShortUrl())->shouldBeCalledTimes(1);
$delegate = TestUtils::createDelegateMock();
$delegate = $this->prophesize(DelegateInterface::class);
$resp = $this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
@@ -1,6 +1,7 @@
<?php
namespace ShlinkioTest\Shlink\Core\Action;
use Interop\Http\ServerMiddleware\DelegateInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
@@ -57,7 +58,7 @@ class RedirectActionTest extends TestCase
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn(null)
->shouldBeCalledTimes(1);
$delegate = TestUtils::createDelegateMock();
$delegate = $this->prophesize(DelegateInterface::class);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$this->action->process($request, $delegate->reveal());
@@ -73,7 +74,7 @@ class RedirectActionTest extends TestCase
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(\Exception::class)
->shouldBeCalledTimes(1);
$delegate = TestUtils::createDelegateMock();
$delegate = $this->prophesize(DelegateInterface::class);
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$this->action->process($request, $delegate->reveal());
@@ -3,10 +3,10 @@ namespace ShlinkioTest\Shlink\Core\Middleware;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\Cache;
use Interop\Http\ServerMiddleware\DelegateInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Shlinkio\Shlink\Core\Middleware\QrCodeCacheMiddleware;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory;
use Zend\Diactoros\Uri;
@@ -33,13 +33,14 @@ class QrCodeCacheMiddlewareTest extends TestCase
*/
public function noCachedPathFallsBackToNextMiddleware()
{
$delegate = TestUtils::createDelegateMock();
$delegate = $this->prophesize(DelegateInterface::class);
$delegate->process(Argument::any())->willReturn(new Response())->shouldBeCalledTimes(1);
$this->middleware->process(ServerRequestFactory::fromGlobals()->withUri(
new Uri('/foo/bar')
), $delegate->reveal());
$this->assertTrue($this->cache->contains('/foo/bar'));
$delegate->process(Argument::any())->shouldHaveBeenCalledTimes(1);
}
/**
@@ -50,7 +51,7 @@ class QrCodeCacheMiddlewareTest extends TestCase
$isCalled = false;
$uri = (new Uri())->withPath('/foo');
$this->cache->save('/foo', ['body' => 'the body', 'content-type' => 'image/png']);
$delegate = TestUtils::createDelegateMock();
$delegate = $this->prophesize(DelegateInterface::class);
$resp = $this->middleware->process(
ServerRequestFactory::fromGlobals()->withUri($uri),