Skip to content

Commit

Permalink
fix deprecation using HttpKernelInterface::MAIN_REQUEST instead of Ht…
Browse files Browse the repository at this point in the history
…tpKernelInterface::MASTER_REQUEST until drop support of Drupal 9.x
  • Loading branch information
WengerK committed May 31, 2024
1 parent 78dd227 commit 6012189
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- fix automated Drupal 10 compatibility fixes - Issue #3329302 by Project Update Bot
- fix library testing path that may be inconsistent between Github Actions & GitlabCI
- fix call to deprecated method withConsecutive() on PHPUnit
- ignore deprecation using HttpKernelInterface::MAIN_REQUEST instead of HttpKernelInterface::MASTER_REQUEST until drop support of Drupal 9.x
- fix deprecation by passing @dataprovider as static function
- fix deprecation using HttpKernelInterface::MAIN_REQUEST instead of HttpKernelInterface::MASTER_REQUEST until drop support of Drupal 9.x

## [1.0.0] - 2022-12-16
### Fixed
Expand Down
5 changes: 1 addition & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ includes:
parameters:
level: 1
reportUnmatchedIgnoredErrors: false
ignoreErrors:
# The module support Drupal 9, Drupal 10 and Drupal 11, so we cannot fix that deprecation without dropping support of Drupal 9.
- "#^Fetching deprecated class constant MASTER_REQUEST of class Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface#"
- "#^Fetching deprecated class constant MASTER_REQUEST of interface Symfony\\\\Component\\\\HttpKernel\\\\HttpKernelInterface#"
# ignoreErrors:
27 changes: 19 additions & 8 deletions tests/src/Unit/HomepageBrowserLanguageRedirectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
class HomepageBrowserLanguageRedirectionTest extends UnitTestCase {

use ProphecyTrait;

/**
* Mimic Symfony MASTER_REQUEST/MAIN_REQUEST from HttpKernelInterface.
*
* In order to keep Drupal 9 compatibility, we need to define this constant by
* ourselves as Drupal 11 (Symfony 7) drop usage of MASTER_REQUEST.
*
* @see https://www.drupal.org/node/3236639
*/
private const MAIN_REQUEST = 1;

/**
* The event subscriber to be tested.
*
Expand Down Expand Up @@ -111,7 +122,7 @@ public function testStopOnFrontpage() {
$kernel = $this->prophesize(HttpKernelInterface::class);
$request = Request::create('/', 'GET');

$event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel->reveal(), $request, self::MAIN_REQUEST);

$this->pathMatcher
->expects($this->once())
Expand All @@ -132,7 +143,7 @@ public function testStopWhenBrowserFallbackDisabled() {
$kernel = $this->prophesize(HttpKernelInterface::class);
$request = Request::create('/', 'GET');

$event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel->reveal(), $request, self::MAIN_REQUEST);

$this->pathMatcher
->expects($this->once())
Expand Down Expand Up @@ -165,7 +176,7 @@ public function testStopWhenNoHeaderAcceptLanguageFromBrowser() {
$kernel = $this->prophesize(HttpKernelInterface::class);
$request = Request::create('/', 'GET');

$event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel->reveal(), $request, self::MAIN_REQUEST);

$this->pathMatcher
->expects($this->once())
Expand Down Expand Up @@ -201,7 +212,7 @@ public function testStopWhenReferrerBypassEnabledAndExternal() {
$this->request->server->set('HTTP_ACCEPT_LANGUAGE', 'fr');
$this->request->server->set('HTTP_REFERER', 'https://www.google.ch');

$event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel->reveal(), $request, self::MAIN_REQUEST);

$currentLanguage = $this->createMock(LanguageInterface::class);
$currentLanguage->expects($this->never())
Expand Down Expand Up @@ -246,7 +257,7 @@ public function testStopWhenCookieExists() {
$this->request->cookies->set('home_redirect_lang_preferred_langcode', 'en');
$this->request->server->set('HTTP_ACCEPT_LANGUAGE', 'fr');

$event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel->reveal(), $request, self::MAIN_REQUEST);

$currentLanguage = $this->createMock(LanguageInterface::class);
$currentLanguage->expects($this->never())
Expand Down Expand Up @@ -294,7 +305,7 @@ public function testStopWhenBrowserLanguageSameAsRequestLanguage() {
$this->request->cookies->set('home_redirect_lang_preferred_langcode', '');
$this->request->server->set('HTTP_ACCEPT_LANGUAGE', 'fr');

$event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel->reveal(), $request, self::MAIN_REQUEST);

$currentLanguage = $this->createMock(LanguageInterface::class);
$currentLanguage->expects($this->once())
Expand Down Expand Up @@ -349,7 +360,7 @@ public function testStopWhenBrowserLanguageNotSupported() {
$this->request->cookies->set('home_redirect_lang_preferred_langcode', '');
$this->request->server->set('HTTP_ACCEPT_LANGUAGE', 'en');

$event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel->reveal(), $request, self::MAIN_REQUEST);

$currentLanguage = $this->createMock(LanguageInterface::class);
$currentLanguage->expects($this->once())
Expand Down Expand Up @@ -406,7 +417,7 @@ public function testRedirectPreferredLanguage() {
$this->request->cookies->set('home_redirect_lang_preferred_langcode', '');
$this->request->server->set('HTTP_ACCEPT_LANGUAGE', 'en');

$event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel->reveal(), $request, self::MAIN_REQUEST);

$currentLanguage = $this->createMock(LanguageInterface::class);
$currentLanguage->expects($this->once())
Expand Down
21 changes: 15 additions & 6 deletions tests/src/Unit/HomepageCookieLanguageRedirectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ class HomepageCookieLanguageRedirectionTest extends UnitTestCase {
*/
protected $cookieLanguageRedirectionEventSubscriber;

/**
* Mimic Symfony MASTER_REQUEST/MAIN_REQUEST from HttpKernelInterface.
*
* In order to keep Drupal 9 compatibility, we need to define this constant by
* ourselves as Drupal 11 (Symfony 7) drop usage of MASTER_REQUEST.
*
* @see https://www.drupal.org/node/3236639
*/
private const MAIN_REQUEST = 1;

/**
* The event subscriber to be tested.
Expand Down Expand Up @@ -119,7 +128,7 @@ public function testStopOnFrontpage() {
$kernel = $this->prophesize(HttpKernelInterface::class);
$request = Request::create('/', 'GET');

$event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel->reveal(), $request, self::MAIN_REQUEST);

$this->pathMatcher
->expects($this->once())
Expand All @@ -143,7 +152,7 @@ public function testStopWhenReferrerBypassEnabledAndExternal() {
$this->request->server->set('HTTP_ACCEPT_LANGUAGE', 'fr');
$this->request->server->set('HTTP_REFERER', 'https://www.google.ch');

$event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel->reveal(), $request, self::MAIN_REQUEST);

$currentLanguage = $this->createMock(LanguageInterface::class);
$currentLanguage->expects($this->never())
Expand Down Expand Up @@ -183,7 +192,7 @@ public function testStopWhenCookieNotExists() {

$this->request->server->set('HTTP_ACCEPT_LANGUAGE', 'fr');

$event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel->reveal(), $request, self::MAIN_REQUEST);

$currentLanguage = $this->createMock(LanguageInterface::class);
$currentLanguage->expects($this->never())
Expand Down Expand Up @@ -224,7 +233,7 @@ public function testStopWhenCookieLanguageSameAsRequestLanguage() {
$this->request->server->set('HTTP_ACCEPT_LANGUAGE', 'fr');
$this->request->cookies->set('home_redirect_lang_preferred_langcode', 'fr');

$event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel->reveal(), $request, self::MAIN_REQUEST);

$currentLanguage = $this->createMock(LanguageInterface::class);
$currentLanguage->expects($this->once())
Expand Down Expand Up @@ -266,7 +275,7 @@ public function testStopWhenCookieLanguageNotSupported() {
$this->request->server->set('HTTP_ACCEPT_LANGUAGE', 'fr');
$this->request->cookies->set('home_redirect_lang_preferred_langcode', 'ru');

$event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel->reveal(), $request, self::MAIN_REQUEST);

$currentLanguage = $this->createMock(LanguageInterface::class);
$currentLanguage->expects($this->once())
Expand Down Expand Up @@ -313,7 +322,7 @@ public function testRedirectPreferredLanguage() {
$this->request->server->set('HTTP_ACCEPT_LANGUAGE', 'fr');
$this->request->cookies->set('home_redirect_lang_preferred_langcode', 'en');

$event = new RequestEvent($kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel->reveal(), $request, self::MAIN_REQUEST);

$currentLanguage = $this->createMock(LanguageInterface::class);
$currentLanguage->expects($this->once())
Expand Down

0 comments on commit 6012189

Please sign in to comment.