Git Product home page Git Product logo

Comments (2)

punyflash avatar punyflash commented on June 17, 2024 1

Hello! This issue is related to #28.

Glad you enjoy working with my library. Firstly, bot testing is extremely unstable and was not officially released yet. And probably, will not and will be deleted in future versions as it is not testing telegram's logic - only mocked response, and I'm not really sure if I've finished mocks for every possible Telegram's method. However, you are using fake toggle wrong. You should use it before using Telegram's API method, same as async and exceptions. For example, in your code you should use it like so:

public function testIssueExample(): void
{
    $bot = LaravelWrapper::bot(); // LaravelWrapper is a Facade for Laravel
    $bot->clearHandlers();
    $bot->addHandler(fn (TeleBot $bot, Update $update, $next) =>
        $bot->fake()->sendMessage([
            'chat_id' => -1,
            'text'    => $update->message->text,
        ])
    );

    $messages = ['random', 'text'];

    foreach ($messages as $message) {
        $update = Update::create([
            'message' => [
                'chat' => [
                    'id' => -1,
                ],
                'text' => $message,
            ],
        ]);

        $response = $bot->handleUpdate($update);
        $this->assertEquals($response->text, $message);
    }
}

You getting Not Found error because when you calling this:

$bot->sendMessage([
    'chat_id' => -1,
    'text'    => $update->message->text,
]);

, you sending request to Telegram's API and trying to send message to chat with id -1 which is not exists

from telebot.

VampireAotD avatar VampireAotD commented on June 17, 2024 1

Thank you very much for your reply!

So for now i came up with two options for me: refactor my handlers a bit or stick to $bot->fake()->handleUpdate() in loop,
will figure out which option is for me better later :)

As for tests, i don't know about coverage of all methods and even though its just mocks, i was really happy to see you added such simple and efficient way to test bots and handlers, because now it is very easy to test single and chains of handlers and their responses, and though it's up to you but i hope you won't delete it, because it is a solid base for testing that made it so much simpler than it used to be 😍

Anyway, thank you very much for your time and help, looking forward to use new versions of this library and wish you all goods 😊

from telebot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.