diff --git a/.travis.yml b/.travis.yml index f29481b..28dc454 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: php php: - 7.0 - - 5.5 - 5.6 - 7.1 @@ -35,8 +34,8 @@ before_script: - sh -c "if [ '$PHPCS' = '1' ]; then composer require cakephp/cakephp-codesniffer; fi" script: - - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.* ]]; then phpunit --coverage-clover=clover.xml; fi - - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.* ]]; then phpunit; fi + - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.* ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi + - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.* ]]; then vendor/bin/phpunit; fi - if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi diff --git a/composer.json b/composer.json index b8daf14..4d1c299 100644 --- a/composer.json +++ b/composer.json @@ -23,10 +23,11 @@ "issues":"https://github.com/ADmad/cakephp-i18n/issues" }, "require": { - "cakephp/cakephp": "~3.0" + "cakephp/cakephp": "^3.4" }, "require-dev": { - "cakephp/cakephp": "~3.3" + "cakephp/cakephp": "^3.4", + "phpunit/phpunit": "<6.0" }, "autoload": { "psr-4": { @@ -43,6 +44,5 @@ "dev-master": "1.0.x-dev" } }, - "minimum-stability": "beta", "prefer-stable": true } diff --git a/src/Middleware/I18nMiddleware.php b/src/Middleware/I18nMiddleware.php index 6f9ab0b..2533541 100644 --- a/src/Middleware/I18nMiddleware.php +++ b/src/Middleware/I18nMiddleware.php @@ -112,8 +112,7 @@ public function detectLanguage(ServerRequestInterface $request, $default = null) $lang = $default; } - $cakeRequest = new Request(); - $browserLangs = $cakeRequest->acceptLanguage(); + $browserLangs = $request->acceptLanguage(); foreach ($browserLangs as $k => $langKey) { if (strpos($langKey, '-') !== false) { $browserLangs[$k] = substr($langKey, 0, 2); diff --git a/tests/TestCase/Middleware/I18nMiddlewareTest.php b/tests/TestCase/Middleware/I18nMiddlewareTest.php index ad905e7..359f082 100644 --- a/tests/TestCase/Middleware/I18nMiddlewareTest.php +++ b/tests/TestCase/Middleware/I18nMiddlewareTest.php @@ -2,12 +2,11 @@ namespace ADmad\I18n\Test\TestCase\Middleware; use ADmad\I18n\Middleware\I18nMiddleware; +use Cake\Http\Response; use Cake\Http\ServerRequestFactory; use Cake\I18n\I18n; use Cake\TestSuite\TestCase; use Locale; -use Zend\Diactoros\Request; -use Zend\Diactoros\Response; /** * I18nMiddleware test. @@ -23,6 +22,8 @@ public function setUp() { parent::setUp(); + $this->server = $_SERVER; + $this->locale = Locale::getDefault(); $this->config = [ @@ -30,9 +31,8 @@ public function setUp() 'languages' => ['fr', 'en'], ]; - $this->request = ServerRequestFactory::fromGlobals([ - 'REQUEST_URI' => '/', - ]); + $_SERVER['REQUEST_URI'] = '/'; + $this->request = ServerRequestFactory::fromGlobals(); $this->request = $this->request->withAttribute('webroot', '/'); $this->response = new Response(); $this->next = function ($req, $res) { @@ -50,7 +50,7 @@ public function tearDown() parent::tearDown(); Locale::setDefault($this->locale); - unset($_SERVER['HTTP_ACCEPT_LANGUAGE']); + $_SERVER = $this->server; } /** @@ -68,9 +68,8 @@ public function testRedirectionFromSiteRoot() $this->assertEquals(301, $response->getStatusCode()); $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-US,en;q=0.8,es;q=0.6,da;q=0.4'; - $request = ServerRequestFactory::fromGlobals([ - 'REQUEST_URI' => '/', - ]); + $request = ServerRequestFactory::fromGlobals(); + $request->webroot = '/'; $middleware = new I18nMiddleware($this->config); $response = $middleware($request, $this->response, $this->next); @@ -86,9 +85,8 @@ public function testRedirectionFromSiteRoot() */ public function testLocaleSetting() { - $request = ServerRequestFactory::fromGlobals([ - 'REQUEST_URI' => '/fr', - ]); + $_SERVER['REQUEST_URI'] = '/fr'; + $request = ServerRequestFactory::fromGlobals(); $request = $request->withAttribute('params', ['lang' => 'fr']); $middleware = new I18nMiddleware($this->config); $response = $middleware($request, $this->response, $this->next);