Comments (2)
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.
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)
- Wrong response from the webhook: 403 Forbidden HOT 1
- Clean up political shit from where it's fucked up like no place HOT 1
- Method answerInlineQuery missing in PHPDoc
- WebApps support HOT 1
- Invalid handler type HOT 1
- Error Handling HOT 4
- get error when use many hendlers in laravel HOT 2
- How can I make a Menu button which opening a web app? HOT 2
- Ошибка в документации HOT 1
- Can't run 2.0 on PHP 7.4 HOT 1
- Cannot cast value of type NULL to type string in Inline mode HOT 3
- [Cannot cast value of type NULL to type string error in Inline mode] HOT 6
- Upgrading from v1 to v2.4 HOT 2
- [BUG] message thread not found HOT 2
- [BUG] Declaration of Handler::write(array $record): void must be compatible with AbstractProcessingHandler::write(Monolog\LogRecord $record): void HOT 7
- Can you provide an example of a bot with laravel? HOT 1
- [BUG] Argument #1 ($bot) must be of type TeleBot, WeStacks\TeleBot\TeleBot given HOT 1
- Error in RequestInputHandler while executing $this->acceptInput()
- Laravel telebot config on database
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from telebot.