diff --git a/module/oc_telegram_shop/upload/oc_telegram_shop/tests/Unit/Framework/TeleCartPulse/TeleCartPulseServiceHeartbeatTest.php b/module/oc_telegram_shop/upload/oc_telegram_shop/tests/Unit/Framework/TeleCartPulse/TeleCartPulseServiceHeartbeatTest.php new file mode 100755 index 00000000..2db78363 --- /dev/null +++ b/module/oc_telegram_shop/upload/oc_telegram_shop/tests/Unit/Framework/TeleCartPulse/TeleCartPulseServiceHeartbeatTest.php @@ -0,0 +1,74 @@ +shouldNotReceive('get'); + $cache->shouldNotReceive('set'); + + $telegramService = m::mock(TelegramService::class); + $telegramService->shouldNotReceive('getMe'); + + $service = new TeleCartPulseService( + m::mock(TelegramInitDataDecoder::class), + $telegramService, + $cache, + m::mock(LoggerInterface::class), + m::mock(TeleCartEvent::class), + 'some-api-key', + m::mock(PayloadSigner::class), + false + ); + + $service->handleHeartbeat(); + + // shouldNotReceive() expectations are verified on Mockery::close() in tearDown. + $this->addToAssertionCount(1); + } + + public function testEnabledHeartbeatPassesGateAndConsultsCache(): void + { + // Cache hit → метод выходит сразу после проверки кэша, не доходя до getMe()/HTTP. + $cache = m::mock(CacheInterface::class); + $cache->shouldReceive('get')->once()->with('telecart_pulse_heartbeat')->andReturn(time()); + $cache->shouldNotReceive('set'); + + $telegramService = m::mock(TelegramService::class); + $telegramService->shouldNotReceive('getMe'); + + $service = new TeleCartPulseService( + m::mock(TelegramInitDataDecoder::class), + $telegramService, + $cache, + m::mock(LoggerInterface::class), + m::mock(TeleCartEvent::class), + 'some-api-key', + m::mock(PayloadSigner::class), + true + ); + + $service->handleHeartbeat(); + + $this->addToAssertionCount(1); + } +}