Drupal 11 compatibility

Created on 15 May 2024, about 1 month ago
Updated 20 May 2024, about 1 month ago

Problem/Motivation

Drupal 11.0.0 will be released soon. We should make this module Drupal 11 compatible. Note that this issue does not and should not cover PHP/Symfony compatibility for the underlying library that this connects to, simplesamlphp.

Based on my static analysis performed on 2024-05-15, it looks like the majority of code changes are located in testing syntax. It looks like this module still needs to convert from DrupalCI to GitLab CI, so that should be a prerequisite to this issue, so that automated testing can be run against Drupal 11 on a merge request for this issue.

My static code analysis audit follows.

Remaining tasks

  • [ ] Deprecated Drupal code is remediated
  • [ ] Deprecated PHP code is remediated
  • [ ] Custom code is compatible with jQuery 4
  • [ ] Custom code coreversionrequirement indicates Drupal 11 compatibility

References

Composer

  • [ ] This module has a composer.json file. We should manually review it for Drupal 11 compatibility, such as external requirements, core version constraints, and PHP version constraints

PHPStan Audit of Drupal deprecations

 ------ ------------------------------------------------------------------------- 
  Line   src/Form/LocalSettingsForm.php                                           
 ------ ------------------------------------------------------------------------- 
  53     Call to deprecated function user_role_names():                           
         in drupal:10.2.0 and is removed from drupal:11.0.0. Use                  
           \Drupal\user\Entity\Role::loadMultiple() and, if necessary, an inline  
           implementation instead.                                                
 ------ ------------------------------------------------------------------------- 

 ------ ----------------------------------------------------------- 
  Line   src/Service/SimplesamlphpDrupalAuth.php                    
 ------ ----------------------------------------------------------- 
  221    Call to deprecated function watchdog_exception():          
         in drupal:10.1.0 and is removed from drupal:11.0.0. Use    
           Use \Drupal\Core\Utility\Error::logException() instead.  
 ------ ----------------------------------------------------------- 

 [ERROR] Found 2 errors                                                                                                 

Drupal-Rector Audit of Drupal deprecations

4 files with changes
====================

1) web/modules/contrib/simplesamlphp_auth/tests/src/Unit/Service/SimplesamlphpAuthManagerTest.php:28

    ---------- begin diff ----------
@@ @@
   /**
    * A mocked config factory instance.
    *
-   * @var \Drupal\Core\Config\ConfigFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Drupal\Core\Config\ConfigFactoryInterface|\PHPUnit\Framework\MockObject\MockObject
    */
   protected $configFactory;

@@ @@
   /**
    * A mocked SimpleSAML configuration instance.
    *
-   * @var \SimpleSAML\Configuration|\PHPUnit_Framework_MockObject_MockObject
+   * @var \SimpleSAML\Configuration|\PHPUnit\Framework\MockObject\MockObject
    */
   protected $simplesamlConfig;

@@ @@
   /**
    * A mocked SimpleSAML instance.
    *
-   * @var \SimpleSAML\Auth\Simple|\PHPUnit_Framework_MockObject_MockObject
+   * @var \SimpleSAML\Auth\Simple|\PHPUnit\Framework\MockObject\MockObject
    */
   public $instance;

@@ @@
   /**
    * A mocked current user.
    *
-   * @var \Drupal\Core\Session\AccountInterface|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Drupal\Core\Session\AccountInterface|\PHPUnit\Framework\MockObject\MockObject
    */
   protected $currentUser;

@@ @@
   /**
    * A mocked AdminContext.
    *
-   * @var \Drupal\Core\Routing\AdminContext|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Drupal\Core\Routing\AdminContext|\PHPUnit\Framework\MockObject\MockObject
    */
   protected $adminContext;

@@ @@
   /**
    * A mocked ModuleHandlerInterface.
    *
-   * @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit\Framework\MockObject\MockObject
    */
   protected $moduleHandler;

@@ @@
   /**
    * A mocked RequestStack.
    *
-   * @var \Symfony\Component\HttpFoundation\RequestStack|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Symfony\Component\HttpFoundation\RequestStack|\PHPUnit\Framework\MockObject\MockObject
    */
   protected $requestStack;

@@ @@
   /**
    * A mocked messenger.
    *
-   * @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit\Framework\MockObject\MockObject
    */
   protected $messenger;

@@ @@
       ->disableOriginalConstructor()
       ->getMock();

-    $this->currentUser = $this->getMockBuilder(AccountInterface::class)
-      ->disableOriginalConstructor()
-      ->getMock();
+    $this->currentUser = $this->createMock(AccountInterface::class);

-    $this->adminContext = $this->getMockBuilder(AdminContext::class)
-      ->disableOriginalConstructor()
-      ->getMock();
+    $this->adminContext = $this->createMock(AdminContext::class);

-    $this->moduleHandler = $this->getMockBuilder(ModuleHandlerInterface::class)
-      ->disableOriginalConstructor()
-      ->getMock();
+    $this->moduleHandler = $this->createMock(ModuleHandlerInterface::class);

     $this->moduleHandler->expects($this->any())
       ->method('invokeAll')
@@ @@
       ->with($this->equalTo('simplesamlphp_auth_allow_login'))
       ->will($this->returnValue([]));

-    $this->requestStack = $this->getMockBuilder(RequestStack::class)
-      ->disableOriginalConstructor()
-      ->getMock();
+    $this->requestStack = $this->createMock(RequestStack::class);

-    $this->messenger = $this->getMockBuilder(MessengerInterface::class)
-      ->disableOriginalConstructor()
-      ->getMock();
+    $this->messenger = $this->createMock(MessengerInterface::class);

     $this->simplesamlConfig = $this->getMockBuilder(Configuration::class)
       ->setMethods(['getValue'])
@@ @@
       ->getMock();

     $container = new ContainerBuilder();
-    $request = $this->getMockBuilder(Request::class)
-      ->disableOriginalConstructor()
-      ->getMock();
+    $request = $this->createMock(Request::class);

     $this->requestStack->expects($this->any())
       ->method('getCurrentRequest')
    ----------- end diff -----------

Applied rules:
 * ProtectedStaticModulesPropertyRector (https://www.drupal.org/node/2909426)
 * GetMockBuilderGetMockToCreateMockRector (https://github.com/lmc-eu/steward/pull/187/files#diff-c7e8c65e59b8b4ff8b54325814d4ba55L80)
 * RenameClassRector


2) web/modules/contrib/simplesamlphp_auth/tests/src/Unit/Service/SimplesamlphpDrupalAuthTest.php:20

    ---------- begin diff ----------
@@ @@
   /**
    * The mocked SimpleSAMLphp Authentication helper.
    *
-   * @var \Drupal\simplesamlphp_auth\Service\SimplesamlphpAuthManager|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Drupal\simplesamlphp_auth\Service\SimplesamlphpAuthManager|\PHPUnit\Framework\MockObject\MockObject
    */
   protected $simplesaml;

@@ @@
   /**
    * The mocked entity type manager.
    *
-   * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit\Framework\MockObject\MockObject
    */
   protected $entityTypeManager;

@@ @@
   /**
    * The mocked logger instance.
    *
-   * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Psr\Log\LoggerInterface|\PHPUnit\Framework\MockObject\MockObject
    */
   protected $logger;

@@ @@
   /**
    * The mocked config factory instance.
    *
-   * @var \Drupal\Core\Config\ConfigFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Drupal\Core\Config\ConfigFactoryInterface|\PHPUnit\Framework\MockObject\MockObject
    */
   protected $configFactory;

@@ @@
   /**
    * A mocked messenger.
    *
-   * @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit\Framework\MockObject\MockObject
    */
   protected $messenger;

@@ @@
   /**
    * A mocked ModuleHandlerInterface.
    *
-   * @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit\Framework\MockObject\MockObject
    */
   protected $moduleHandler;

@@ @@

     $this->entityTypeManager = $this->createMock('\Drupal\Core\Entity\EntityTypeManagerInterface');

-    $this->logger = $this->getMockBuilder('\Psr\Log\LoggerInterface')
-      ->disableOriginalConstructor()
-      ->getMock();
+    $this->logger = $this->createMock('\Psr\Log\LoggerInterface');

-    $this->messenger = $this->getMockBuilder(MessengerInterface::class)
-      ->disableOriginalConstructor()
-      ->getMock();
+    $this->messenger = $this->createMock(MessengerInterface::class);

-    $this->moduleHandler = $this->getMockBuilder(ModuleHandlerInterface::class)
-      ->disableOriginalConstructor()
-      ->getMock();
+    $this->moduleHandler = $this->createMock(ModuleHandlerInterface::class);

     $this->moduleHandler->expects($this->any())
       ->method('alter');

-    $this->simplesaml = $this->getMockBuilder('\Drupal\simplesamlphp_auth\Service\SimplesamlphpAuthManager')
-      ->disableOriginalConstructor()
-      ->getMock();
+    $this->simplesaml = $this->createMock('\Drupal\simplesamlphp_auth\Service\SimplesamlphpAuthManager');

     $this->configFactory = $this->getConfigFactoryStub([
       'simplesamlphp_auth.settings' => [
    ----------- end diff -----------

Applied rules:
 * ProtectedStaticModulesPropertyRector (https://www.drupal.org/node/2909426)
 * GetMockBuilderGetMockToCreateMockRector (https://github.com/lmc-eu/steward/pull/187/files#diff-c7e8c65e59b8b4ff8b54325814d4ba55L80)
 * RenameClassRector


3) web/modules/contrib/simplesamlphp_auth/simplesamlphp_auth.api.php:0

    ---------- begin diff ----------
@@ @@
 <?php

+use Drupal\user\UserInterface;
 /**
  * @file
  * Hooks for simpleSAMLphp Authentication module.
@@ @@
  * @param \Drupal\user\UserInterface $account
  *   The pre-existing Drupal user to be SAML-enabled.
  */
-function hook_simplesamlphp_auth_account_authname_alter(&$authname, \Drupal\user\UserInterface $account) {
+function hook_simplesamlphp_auth_account_authname_alter(&$authname, UserInterface $account) {
   $authname = $account->mail;
 }

@@ @@
  * @return \Drupal\user\UserInterface|bool
  *   The altered Drupal account or FALSE if nothing was changed.
  */
-function hook_simplesamlphp_auth_user_attributes(\Drupal\user\UserInterface $account, $attributes) {
+function hook_simplesamlphp_auth_user_attributes(UserInterface $account, $attributes) {
   $saml_first_name = $attributes['first_name'];
   if ($saml_first_name) {
     $account->set('field_first_name', $saml_first_name);
    ----------- end diff -----------

4) web/modules/contrib/simplesamlphp_auth/src/Service/SimplesamlphpDrupalAuth.php:1

    ---------- begin diff ----------
@@ @@

 namespace Drupal\simplesamlphp_auth\Service;

+use Drupal\Component\Utility\DeprecationHelper;
+use Drupal\Core\Utility\Error;
 use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Session\AccountInterface;
@@ @@
         $account = $this->externalauth->register($authname, 'simplesamlphp_auth');
       }
       catch (\Exception $ex) {
-        watchdog_exception('simplesamlphp_auth', $ex);
+        DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => Error::logException(\Drupal::logger('simplesamlphp_auth'), $ex), fn() => watchdog_exception('simplesamlphp_auth', $ex));
         $this->messenger
           ->addMessage($this->t('Error registering user: An account with this username already exists.'), 'error');
       }
    ----------- end diff -----------

Applied rules:
 * WatchdogExceptionRector
 * ProtectedStaticModulesPropertyRector (https://www.drupal.org/node/2909426)


 [OK] 4 files would have changed (dry-run) by Rector                                                                    

Audit of deprecated PHP <8.3 calls

If no errors are listed below, php-compatibility did not find any.

................ 16 / 16 (100%)


Time: 173ms; Memory: 10MB

Diff for updating coreversionrequirement

diff --git a/simplesamlphp_auth.info.yml b/simplesamlphp_auth.info.yml
index 893e0ae..0890456 100644
--- a/simplesamlphp_auth.info.yml
+++ b/simplesamlphp_auth.info.yml
@@ -1,7 +1,7 @@
 name: SimpleSAMLphp Authentication
 type: module
 description: Allows users to authenticate to a remote SAML identity provider (IdP) via a locally configured SimpleSAMLphp service point (SP).
-core_version_requirement: ^9.4
+core_version_requirement: ^10 || ^11
 configure: simplesamlphp_auth.admin_settings
 dependencies:
  - drupal:user
📌 Task
Status

Needs review

Version

4.0

Component

Code

Created by

🇺🇸United States mark_fullmer Tucson

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mark_fullmer
  • Status changed to Needs review about 1 month ago
  • 🇮🇳India sarwan

    Hi @mark_fullmer,
    I have fixed this issue "Drupal 11 compatibility" and also attached patch
    kindly review and verify .

Production build 0.69.0 2024