diff --git a/module/Core/test/EventDispatcher/Mercure/NotifyNewShortUrlToMercureTest.php b/module/Core/test/EventDispatcher/Mercure/NotifyNewShortUrlToMercureTest.php index c6b67727..3294e929 100644 --- a/module/Core/test/EventDispatcher/Mercure/NotifyNewShortUrlToMercureTest.php +++ b/module/Core/test/EventDispatcher/Mercure/NotifyNewShortUrlToMercureTest.php @@ -20,7 +20,6 @@ use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; class NotifyNewShortUrlToMercureTest extends TestCase { - private NotifyNewShortUrlToMercure $listener; private MockObject & PublishingHelperInterface $helper; private MockObject & PublishingUpdatesGeneratorInterface $updatesGenerator; private MockObject & EntityManagerInterface $em; @@ -32,14 +31,6 @@ class NotifyNewShortUrlToMercureTest extends TestCase $this->updatesGenerator = $this->createMock(PublishingUpdatesGeneratorInterface::class); $this->em = $this->createMock(EntityManagerInterface::class); $this->logger = $this->createMock(LoggerInterface::class); - - $this->listener = new NotifyNewShortUrlToMercure( - $this->helper, - $this->updatesGenerator, - $this->em, - $this->logger, - new RealTimeUpdatesOptions(), - ); } #[Test] @@ -54,7 +45,7 @@ class NotifyNewShortUrlToMercureTest extends TestCase ); $this->logger->expects($this->never())->method('debug'); - ($this->listener)(new ShortUrlCreated('123')); + $this->listener()(new ShortUrlCreated('123')); } #[Test] @@ -71,7 +62,7 @@ class NotifyNewShortUrlToMercureTest extends TestCase $this->logger->expects($this->never())->method('warning'); $this->logger->expects($this->never())->method('debug'); - ($this->listener)(new ShortUrlCreated('123')); + $this->listener()(new ShortUrlCreated('123')); } #[Test] @@ -95,6 +86,30 @@ class NotifyNewShortUrlToMercureTest extends TestCase ['e' => $e, 'name' => 'Mercure'], ); - ($this->listener)(new ShortUrlCreated('123')); + $this->listener()(new ShortUrlCreated('123')); + } + + #[Test] + public function publishingIsSkippedIfNewShortUrlTopicIsNotEnabled(): void + { + $shortUrl = ShortUrl::withLongUrl('https://longUrl'); + $update = Update::forTopicAndPayload('', []); + + $this->em->expects($this->once())->method('find')->with(ShortUrl::class, '123')->willReturn($shortUrl); + $this->updatesGenerator->expects($this->never())->method('newShortUrlUpdate'); + $this->helper->expects($this->never())->method('publishUpdate'); + + $this->listener(enableShortUrlTopic: false)(new ShortUrlCreated('123')); + } + + private function listener(bool $enableShortUrlTopic = true): NotifyNewShortUrlToMercure + { + return new NotifyNewShortUrlToMercure( + $this->helper, + $this->updatesGenerator, + $this->em, + $this->logger, + new RealTimeUpdatesOptions(enabledTopics: $enableShortUrlTopic ? null : []), + ); } }