Skip to content

Commit ce22f41

Browse files
committed
Move live PHPUnit tests to the "live" group, to make it easier to exclude them while developing.
Add sleeps between live tests to prevent request limits.
1 parent 52dcac9 commit ce22f41

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/BotManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ public function validateAndSetWebhook(): self
175175

176176
if ($this->action->isAction(['unset', 'reset'])) {
177177
$this->handleOutput($this->telegram->unsetWebHook()->getDescription() . PHP_EOL);
178+
// When resetting the webhook, sleep for a bit to prevent too many requests.
179+
$this->action->isAction('reset') && sleep(1);
178180
}
179181
if ($this->action->isAction(['set', 'reset'])) {
180182
$this->handleOutput(

tests/TelegramBotManager/Tests/BotManagerTest.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ public function testValidateAndSetWebhookSuccess()
185185
self::assertSame('Webhook is already deleted' . PHP_EOL, $output);
186186
}
187187

188+
/**
189+
* @group live
190+
*/
188191
public function testValidateAndSetWebhookSuccessLiveBot()
189192
{
190193
$botManager = new BotManager(array_merge(self::$live_params, [
@@ -203,26 +206,29 @@ public function testValidateAndSetWebhookSuccessLiveBot()
203206
// Make sure the webhook isn't set to start with.
204207
TestHelpers::setObjectProperty($botManager->getAction(), 'action', 'unset');
205208
$botManager->validateAndSetWebhook()->getOutput();
206-
209+
sleep(1);
207210
TestHelpers::setObjectProperty($botManager->getAction(), 'action', 'set');
208211
$output = $botManager->validateAndSetWebhook()->getOutput();
209212
self::assertSame('Webhook was set' . PHP_EOL, $output);
210-
213+
sleep(1);
211214
$output = $botManager->validateAndSetWebhook()->getOutput();
212215
self::assertSame('Webhook is already set' . PHP_EOL, $output);
213-
216+
sleep(1);
214217
TestHelpers::setObjectProperty($botManager->getAction(), 'action', 'reset');
215218
$output = $botManager->validateAndSetWebhook()->getOutput();
216219
self::assertSame('Webhook was deleted' . PHP_EOL . 'Webhook was set' . PHP_EOL, $output);
217-
220+
sleep(1);
218221
TestHelpers::setObjectProperty($botManager->getAction(), 'action', 'unset');
219222
$output = $botManager->validateAndSetWebhook()->getOutput();
220223
self::assertSame('Webhook was deleted' . PHP_EOL, $output);
221-
224+
sleep(1);
222225
$output = $botManager->validateAndSetWebhook()->getOutput();
223226
self::assertSame('Webhook is already deleted' . PHP_EOL, $output);
224227
}
225228

229+
/**
230+
* @group live
231+
*/
226232
public function testUnsetWebhookViaRunLiveBot()
227233
{
228234
$_GET = ['a' => 'unset'];
@@ -364,13 +370,19 @@ public function testGetOutput()
364370
self::assertEmpty($botManager->getOutput());
365371
}
366372

373+
/**
374+
* @group live
375+
*/
367376
public function testGetUpdatesLiveBot()
368377
{
369378
$botManager = new BotManager(self::$live_params);
370379
$output = $botManager->run()->getOutput();
371380
self::assertContains('Updates processed: 0', $output);
372381
}
373382

383+
/**
384+
* @group live
385+
*/
374386
public function testGetUpdatesLoopLiveBot()
375387
{
376388
// Webhook must NOT be set for this to work!

0 commit comments

Comments
 (0)