helper = $this->prophesize(PublishingHelperInterface::class); $this->updatesGenerator = $this->prophesize(PublishingUpdatesGeneratorInterface::class); $this->em = $this->prophesize(EntityManagerInterface::class); $this->logger = $this->prophesize(LoggerInterface::class); } /** @test */ public function doesNothingWhenTheFeatureIsNotEnabled(): void { $this->createListener(false)(new VisitLocated('123')); $this->em->find(Argument::cetera())->shouldNotHaveBeenCalled(); $this->logger->warning(Argument::cetera())->shouldNotHaveBeenCalled(); $this->logger->debug(Argument::cetera())->shouldNotHaveBeenCalled(); $this->helper->publishUpdate(Argument::cetera())->shouldNotHaveBeenCalled(); } /** * @test * @dataProvider provideExceptions */ public function printsDebugMessageInCaseOfError(Throwable $e): void { $visitId = '123'; $findVisit = $this->em->find(Visit::class, $visitId)->willReturn(Visit::forBasePath(Visitor::emptyInstance())); $generateUpdate = $this->updatesGenerator->newOrphanVisitUpdate(Argument::type(Visit::class))->willReturn( Update::forTopicAndPayload('', []), ); $publish = $this->helper->publishUpdate(Argument::cetera())->willThrow($e); $this->createListener()(new VisitLocated($visitId)); $this->logger->debug( 'Error while trying to notify {name} with new visit. {e}', ['e' => $e, 'name' => 'Redis pub/sub'], )->shouldHaveBeenCalledOnce(); $findVisit->shouldHaveBeenCalledOnce(); $generateUpdate->shouldHaveBeenCalledOnce(); $publish->shouldHaveBeenCalledOnce(); } public function provideExceptions(): iterable { yield [new RuntimeException('RuntimeException Error')]; yield [new Exception('Exception Error')]; yield [new DomainException('DomainException Error')]; } private function createListener(bool $enabled = true): NotifyVisitToRedis { return new NotifyVisitToRedis( $this->helper->reveal(), $this->updatesGenerator->reveal(), $this->em->reveal(), $this->logger->reveal(), $enabled, ); } }