From d72b9cf646190f39fcaef7ef9c6bfe3638b7373a Mon Sep 17 00:00:00 2001
From: Alejandro Celaya <alejandro@alejandrocelaya.com>
Date: Fri, 2 Apr 2021 09:46:02 +0200
Subject: [PATCH] Updated to symfony/mercure 0.5

---
 composer.json                                    |  4 ++--
 config/autoload/mercure.global.php               |  8 ++++----
 module/Core/config/event_dispatcher.config.php   |  4 ++--
 .../src/EventDispatcher/NotifyVisitToMercure.php | 10 +++++-----
 .../EventDispatcher/NotifyVisitToMercureTest.php | 16 ++++++++--------
 phpstan.neon                                     |  1 +
 6 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/composer.json b/composer.json
index 8cf48639..c3d8aba4 100644
--- a/composer.json
+++ b/composer.json
@@ -46,7 +46,7 @@
         "predis/predis": "^1.1",
         "pugx/shortid-php": "^0.7",
         "ramsey/uuid": "^3.9",
-        "shlinkio/shlink-common": "^3.6",
+        "shlinkio/shlink-common": "dev-main#3777189 as 3.7",
         "shlinkio/shlink-config": "^1.0",
         "shlinkio/shlink-event-dispatcher": "^2.1",
         "shlinkio/shlink-importer": "^2.2",
@@ -55,7 +55,7 @@
         "symfony/console": "^5.1",
         "symfony/filesystem": "^5.1",
         "symfony/lock": "^5.1",
-        "symfony/mercure": "^0.4.1",
+        "symfony/mercure": "^0.5.1",
         "symfony/process": "^5.1",
         "symfony/string": "^5.1"
     },
diff --git a/config/autoload/mercure.global.php b/config/autoload/mercure.global.php
index 1a404dca..72fafe58 100644
--- a/config/autoload/mercure.global.php
+++ b/config/autoload/mercure.global.php
@@ -4,8 +4,8 @@ declare(strict_types=1);
 
 use Laminas\ServiceManager\Proxy\LazyServiceFactory;
 use Shlinkio\Shlink\Common\Mercure\LcobucciJwtProvider;
-use Symfony\Component\Mercure\Publisher;
-use Symfony\Component\Mercure\PublisherInterface;
+use Symfony\Component\Mercure\Hub;
+use Symfony\Component\Mercure\HubInterface;
 
 return [
 
@@ -21,14 +21,14 @@ return [
             LcobucciJwtProvider::class => [
                 LazyServiceFactory::class,
             ],
-            Publisher::class => [
+            Hub::class => [
                 LazyServiceFactory::class,
             ],
         ],
         'lazy_services' => [
             'class_map' => [
                 LcobucciJwtProvider::class => LcobucciJwtProvider::class,
-                Publisher::class => PublisherInterface::class,
+                Hub::class => HubInterface::class,
             ],
         ],
     ],
diff --git a/module/Core/config/event_dispatcher.config.php b/module/Core/config/event_dispatcher.config.php
index 5c2c88e0..5e1a6c9f 100644
--- a/module/Core/config/event_dispatcher.config.php
+++ b/module/Core/config/event_dispatcher.config.php
@@ -8,7 +8,7 @@ use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory;
 use Psr\EventDispatcher\EventDispatcherInterface;
 use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdater;
 use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
-use Symfony\Component\Mercure\Publisher;
+use Symfony\Component\Mercure\Hub;
 
 return [
 
@@ -57,7 +57,7 @@ return [
             Options\AppOptions::class,
         ],
         EventDispatcher\NotifyVisitToMercure::class => [
-            Publisher::class,
+            Hub::class,
             Mercure\MercureUpdatesGenerator::class,
             'em',
             'Logger_Shlink',
diff --git a/module/Core/src/EventDispatcher/NotifyVisitToMercure.php b/module/Core/src/EventDispatcher/NotifyVisitToMercure.php
index 0cf438ed..33adf965 100644
--- a/module/Core/src/EventDispatcher/NotifyVisitToMercure.php
+++ b/module/Core/src/EventDispatcher/NotifyVisitToMercure.php
@@ -9,7 +9,7 @@ use Psr\Log\LoggerInterface;
 use Shlinkio\Shlink\Core\Entity\Visit;
 use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated;
 use Shlinkio\Shlink\Core\Mercure\MercureUpdatesGeneratorInterface;
-use Symfony\Component\Mercure\PublisherInterface;
+use Symfony\Component\Mercure\HubInterface;
 use Symfony\Component\Mercure\Update;
 use Throwable;
 
@@ -17,18 +17,18 @@ use function Functional\each;
 
 class NotifyVisitToMercure
 {
-    private PublisherInterface $publisher;
+    private HubInterface $hub;
     private MercureUpdatesGeneratorInterface $updatesGenerator;
     private EntityManagerInterface $em;
     private LoggerInterface $logger;
 
     public function __construct(
-        PublisherInterface $publisher,
+        HubInterface $hub,
         MercureUpdatesGeneratorInterface $updatesGenerator,
         EntityManagerInterface $em,
         LoggerInterface $logger
     ) {
-        $this->publisher = $publisher;
+        $this->hub = $hub;
         $this->em = $em;
         $this->logger = $logger;
         $this->updatesGenerator = $updatesGenerator;
@@ -48,7 +48,7 @@ class NotifyVisitToMercure
         }
 
         try {
-            each($this->determineUpdatesForVisit($visit), fn (Update $update) => ($this->publisher)($update));
+            each($this->determineUpdatesForVisit($visit), fn (Update $update) => $this->hub->publish($update));
         } catch (Throwable $e) {
             $this->logger->debug('Error while trying to notify mercure hub with new visit. {e}', [
                 'e' => $e,
diff --git a/module/Core/test/EventDispatcher/NotifyVisitToMercureTest.php b/module/Core/test/EventDispatcher/NotifyVisitToMercureTest.php
index f323a155..0b863b69 100644
--- a/module/Core/test/EventDispatcher/NotifyVisitToMercureTest.php
+++ b/module/Core/test/EventDispatcher/NotifyVisitToMercureTest.php
@@ -17,7 +17,7 @@ use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated;
 use Shlinkio\Shlink\Core\EventDispatcher\NotifyVisitToMercure;
 use Shlinkio\Shlink\Core\Mercure\MercureUpdatesGeneratorInterface;
 use Shlinkio\Shlink\Core\Model\Visitor;
-use Symfony\Component\Mercure\PublisherInterface;
+use Symfony\Component\Mercure\HubInterface;
 use Symfony\Component\Mercure\Update;
 
 class NotifyVisitToMercureTest extends TestCase
@@ -25,20 +25,20 @@ class NotifyVisitToMercureTest extends TestCase
     use ProphecyTrait;
 
     private NotifyVisitToMercure $listener;
-    private ObjectProphecy $publisher;
+    private ObjectProphecy $hub;
     private ObjectProphecy $updatesGenerator;
     private ObjectProphecy $em;
     private ObjectProphecy $logger;
 
     public function setUp(): void
     {
-        $this->publisher = $this->prophesize(PublisherInterface::class);
+        $this->hub = $this->prophesize(HubInterface::class);
         $this->updatesGenerator = $this->prophesize(MercureUpdatesGeneratorInterface::class);
         $this->em = $this->prophesize(EntityManagerInterface::class);
         $this->logger = $this->prophesize(LoggerInterface::class);
 
         $this->listener = new NotifyVisitToMercure(
-            $this->publisher->reveal(),
+            $this->hub->reveal(),
             $this->updatesGenerator->reveal(),
             $this->em->reveal(),
             $this->logger->reveal(),
@@ -60,7 +60,7 @@ class NotifyVisitToMercureTest extends TestCase
         );
         $buildNewOrphanVisitUpdate = $this->updatesGenerator->newOrphanVisitUpdate(Argument::type(Visit::class));
         $buildNewVisitUpdate = $this->updatesGenerator->newVisitUpdate(Argument::type(Visit::class));
-        $publish = $this->publisher->__invoke(Argument::type(Update::class));
+        $publish = $this->hub->publish(Argument::type(Update::class));
 
         ($this->listener)(new VisitLocated($visitId));
 
@@ -86,7 +86,7 @@ class NotifyVisitToMercureTest extends TestCase
         $buildNewShortUrlVisitUpdate = $this->updatesGenerator->newShortUrlVisitUpdate($visit)->willReturn($update);
         $buildNewOrphanVisitUpdate = $this->updatesGenerator->newOrphanVisitUpdate($visit)->willReturn($update);
         $buildNewVisitUpdate = $this->updatesGenerator->newVisitUpdate($visit)->willReturn($update);
-        $publish = $this->publisher->__invoke($update);
+        $publish = $this->hub->publish($update);
 
         ($this->listener)(new VisitLocated($visitId));
 
@@ -115,7 +115,7 @@ class NotifyVisitToMercureTest extends TestCase
         $buildNewShortUrlVisitUpdate = $this->updatesGenerator->newShortUrlVisitUpdate($visit)->willReturn($update);
         $buildNewOrphanVisitUpdate = $this->updatesGenerator->newOrphanVisitUpdate($visit)->willReturn($update);
         $buildNewVisitUpdate = $this->updatesGenerator->newVisitUpdate($visit)->willReturn($update);
-        $publish = $this->publisher->__invoke($update)->willThrow($e);
+        $publish = $this->hub->publish($update)->willThrow($e);
 
         ($this->listener)(new VisitLocated($visitId));
 
@@ -143,7 +143,7 @@ class NotifyVisitToMercureTest extends TestCase
         $buildNewShortUrlVisitUpdate = $this->updatesGenerator->newShortUrlVisitUpdate($visit)->willReturn($update);
         $buildNewOrphanVisitUpdate = $this->updatesGenerator->newOrphanVisitUpdate($visit)->willReturn($update);
         $buildNewVisitUpdate = $this->updatesGenerator->newVisitUpdate($visit)->willReturn($update);
-        $publish = $this->publisher->__invoke($update);
+        $publish = $this->hub->publish($update);
 
         ($this->listener)(new VisitLocated($visitId));
 
diff --git a/phpstan.neon b/phpstan.neon
index 80f1b083..fbddc81c 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -3,3 +3,4 @@ parameters:
 	checkGenericClassInNonGenericObjectType: false
 	ignoreErrors:
 		- '#If condition is always false#'
+		- '#setOrderBy\(\) expects array\<int, string\>, array\<string, string\> given#'