Skip to content

Commit 9ed9e51

Browse files
committed
Make live tests think that Telegram has called them.
1 parent 94e9ee7 commit 9ed9e51

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/BotManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ public function getOutput(): string
508508
*/
509509
public function isValidRequest(): bool
510510
{
511+
// If we're running from CLI, requests are always valid, unless we're running the tests.
511512
if ((!self::inTest() && 'cli' === PHP_SAPI) || false === $this->params->getBotParam('validate_request')) {
512513
return true;
513514
}

tests/TelegramBotManager/Tests/BotManagerTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ public static function setUpBeforeClass()
4444
];
4545
}
4646

47+
/**
48+
* To test the live commands, act as if we're being called by Telegram.
49+
*/
50+
protected function makeRequestValid()
51+
{
52+
$_SERVER['REMOTE_ADDR'] = '149.154.167.197';
53+
}
54+
4755
public function testSetParameters()
4856
{
4957
$botManager = new BotManager(array_merge(ParamsTest::$demo_vital_params, [
@@ -239,9 +247,11 @@ public function testValidateAndSetWebhookSuccessLiveBot()
239247

240248
/**
241249
* @group live
250+
* @runInSeparateProcess
242251
*/
243252
public function testDeleteWebhookViaRunLiveBot()
244253
{
254+
$this->makeRequestValid();
245255
$_GET = ['a' => 'unset'];
246256
$botManager = new BotManager(array_merge(self::$live_params, [
247257
'webhook' => ['url' => 'https://example.com/hook.php'],
@@ -438,20 +448,24 @@ public function testIsValidRequestValidate()
438448

439449
/**
440450
* @group live
451+
* @runInSeparateProcess
441452
*/
442453
public function testGetUpdatesLiveBot()
443454
{
455+
$this->makeRequestValid();
444456
$botManager = new BotManager(self::$live_params);
445457
$output = $botManager->run()->getOutput();
446458
self::assertContains('Updates processed: 0', $output);
447459
}
448460

449461
/**
450462
* @group live
463+
* @runInSeparateProcess
451464
*/
452465
public function testGetUpdatesLoopLiveBot()
453466
{
454-
// Webhook must NOT be set for this to work!
467+
$this->makeRequestValid();
468+
// Webhook MUST NOT be set for this to work!
455469
$this->testDeleteWebhookViaRunLiveBot();
456470

457471
// Looping for 5 seconds should be enough to get a result.

0 commit comments

Comments
 (0)