mirror of
https://github.com/shlinkio/shlink.git
synced 2025-12-10 11:05:50 -06:00
Add test to cover when short URL updates topic is disabled
This commit is contained in:
parent
26fef87f3b
commit
733b2e5647
@ -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 : []),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user