From 34b3acd67056a5af77ab7f439ecebdb03e9a9d03 Mon Sep 17 00:00:00 2001
From: Stephen Mustgrave <smustgrave@gmail.com>
Date: Tue, 24 Dec 2024 11:34:44 -0500
Subject: [PATCH] Issue #3495439: Fix tests

---
 src/Service/RestrictIpService.php | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/Service/RestrictIpService.php b/src/Service/RestrictIpService.php
index e1d885c..c9b2066 100644
--- a/src/Service/RestrictIpService.php
+++ b/src/Service/RestrictIpService.php
@@ -71,20 +71,20 @@ class RestrictIpService implements RestrictIpServiceInterface, ContainerInjectio
    *   The Path Matcher service.
    * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
    *   The Module Handler service.
-   * @param \Drupal\user\UserDataInterface $userData
+   * @param \Drupal\user\UserDataInterface|null $userData
    *   The User Data service.
    * @param \Drupal\ip2country\Ip2CountryLookup|null $ip2CountryLookupService
    *   An ip2CountryLookupService object.
    */
   public function __construct(
     protected AccountProxyInterface $currentUser,
-    CurrentPathStack $currentPathStack,
+    protected CurrentPathStack $currentPathStack,
     protected ConfigFactoryInterface $configFactory,
     protected RequestStack $requestStack,
     protected RestrictIpMapperInterface $mapper,
     protected PathMatcherInterface $pathMatcher,
     protected ModuleHandlerInterface $moduleHandler,
-    protected UserDataInterface $userData,
+    protected ?UserDataInterface $userData = NULL,
     ?Ip2CountryLookup $ip2CountryLookupService = NULL,
   ) {
     $this->currentPath = strtolower($currentPathStack->getPath());
@@ -97,16 +97,21 @@ class RestrictIpService implements RestrictIpServiceInterface, ContainerInjectio
    * {@inheritDoc}
    */
   public static function create(ContainerInterface $container): static {
+    $ip2CountryLookupService = NULL;
+    if ($container->has('ip2country.lookup')) {
+      $ip2CountryLookupService = $container->get('ip2country.lookup');
+    }
+
     return new static(
       $container->get('current_user'),
+      $container->get('path.current'),
+      $container->get('config.factory'),
+      $container->get('request_stack'),
       $container->get('restrict_ip.mapper'),
       $container->get('path.matcher'),
       $container->get('module_handler'),
       $container->get('user.data'),
-      $container->get('path.current'),
-      $container->get('config.factory'),
-      $container->get('request_stack'),
-      $container->get('ip2country.lookup'),
+      $ip2CountryLookupService
     );
   }
 
-- 
GitLab