Migrated QrCodeCacheMiddleware to psr-15 middleware

This commit is contained in:
Alejandro Celaya
2017-03-24 23:34:17 +01:00
parent 734dac9456
commit 6c87436a96
2 changed files with 25 additions and 41 deletions

View File

@@ -4,7 +4,9 @@ namespace ShlinkioTest\Shlink\Core\Middleware;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\Cache;
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;
@@ -29,18 +31,15 @@ class QrCodeCacheMiddlewareTest extends TestCase
/**
* @test
*/
public function noCachedPathFallbacksToNextMiddleware()
public function noCachedPathFallsBackToNextMiddleware()
{
$isCalled = false;
$this->middleware->__invoke(
ServerRequestFactory::fromGlobals(),
new Response(),
function ($req, $resp) use (&$isCalled) {
$isCalled = true;
return $resp;
}
);
$this->assertTrue($isCalled);
$delegate = TestUtils::createDelegateMock();
$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);
}
/**
@@ -51,19 +50,17 @@ 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();
$resp = $this->middleware->__invoke(
$resp = $this->middleware->process(
ServerRequestFactory::fromGlobals()->withUri($uri),
new Response(),
function ($req, $resp) use (&$isCalled) {
$isCalled = true;
return $resp;
}
$delegate->reveal()
);
$this->assertFalse($isCalled);
$resp->getBody()->rewind();
$this->assertEquals('the body', $resp->getBody()->getContents());
$this->assertEquals('image/png', $resp->getHeaderLine('Content-Type'));
$delegate->process(Argument::any())->shouldHaveBeenCalledTimes(0);
}
}