Longman\TelegramBot\Tests\Unit\TestHelpers::startFakeConversation PHP Method

startFakeConversation() public static method

Start a fake conversation for the passed command and return the randomly generated ids.
public static startFakeConversation ( ) : array
return array
    public static function startFakeConversation()
    {
        if (!DB::isDbConnected()) {
            return false;
        }
        //Just get some random values.
        $message_id = mt_rand();
        $user_id = mt_rand();
        $chat_id = mt_rand();
        //Make sure we have a valid user and chat available.
        $message = self::getFakeMessageObject(['message_id' => $message_id], ['id' => $user_id], ['id' => $chat_id]);
        DB::insertMessageRequest($message);
        DB::insertUser($message->getFrom(), null, $message->getChat());
        return compact('message_id', 'user_id', 'chat_id');
    }

Usage Example

コード例 #1
0
 public function testUpdateConversationNotes()
 {
     $info = TestHelpers::startFakeConversation();
     $conversation = new Conversation($info['user_id'], $info['chat_id'], 'command');
     $conversation->notes = 'newnote';
     $conversation->update();
     $conversation2 = new Conversation($info['user_id'], $info['chat_id'], 'command');
     $this->assertSame('newnote', $conversation2->notes);
     $conversation3 = new Conversation($info['user_id'], $info['chat_id']);
     $this->assertSame('newnote', $conversation3->notes);
 }