Migrated LocaleMiddleware to psr-15 middleware

This commit is contained in:
Alejandro Celaya
2017-03-24 21:49:31 +01:00
parent d1018b6da7
commit c3c03a3a3b
3 changed files with 54 additions and 38 deletions

View File

@@ -3,7 +3,7 @@ namespace ShlinkioTest\Shlink\Common\Middleware;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Common\Middleware\LocaleMiddleware;
use Zend\Diactoros\Response;
use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
@@ -30,9 +30,7 @@ class LocaleMiddlewareTest extends TestCase
public function whenNoHeaderIsPresentLocaleIsNotChanged()
{
$this->assertEquals('ru', $this->translator->getLocale());
$this->middleware->__invoke(ServerRequestFactory::fromGlobals(), new Response(), function ($req, $resp) {
return $resp;
});
$this->middleware->process(ServerRequestFactory::fromGlobals(), TestUtils::createDelegateMock()->reveal());
$this->assertEquals('ru', $this->translator->getLocale());
}
@@ -43,9 +41,7 @@ class LocaleMiddlewareTest extends TestCase
{
$this->assertEquals('ru', $this->translator->getLocale());
$request = ServerRequestFactory::fromGlobals()->withHeader('Accept-Language', 'es');
$this->middleware->__invoke($request, new Response(), function ($req, $resp) {
return $resp;
});
$this->middleware->process($request, TestUtils::createDelegateMock()->reveal());
$this->assertEquals('es', $this->translator->getLocale());
}
@@ -54,18 +50,16 @@ class LocaleMiddlewareTest extends TestCase
*/
public function localeGetsNormalized()
{
$delegate = TestUtils::createDelegateMock();
$this->assertEquals('ru', $this->translator->getLocale());
$request = ServerRequestFactory::fromGlobals()->withHeader('Accept-Language', 'es_ES');
$this->middleware->__invoke($request, new Response(), function ($req, $resp) {
return $resp;
});
$this->middleware->process($request, $delegate->reveal());
$this->assertEquals('es', $this->translator->getLocale());
$request = ServerRequestFactory::fromGlobals()->withHeader('Accept-Language', 'en-US');
$this->middleware->__invoke($request, new Response(), function ($req, $resp) {
return $resp;
});
$this->middleware->process($request, $delegate->reveal());
$this->assertEquals('en', $this->translator->getLocale());
}
}