Improvements for testing #87
Replies: 2 comments
-
Hi! In general testing Telegram API a bit complicated as there is a bunch of logic happens inside Telegram servers itself like invoice generation, callbacks, inline callbacks etc. And all attached to the IDs generated by Telegram. I was thinking for two years how to make tests more convenient, so they could replicate logic of Telegram API easy and be a verification that if your code runs it should run with Telegram servers as well. But I didn't find a good solution. I'm not satisfied with the current way of mocking responses, yeah, but I've not came up with anything better, so the topic of testing is open for discussion. |
Beta Was this translation helpful? Give feedback.
-
Hello! Sorry for the late response. The current implementation of mocks is indeed effective and in many situations mocks Telegram's responses well, I think, I wouldn't came up with a better solution myself. However, the main aspect of this discussion is not to completely rethink current implementation of mocks, but to slightly extend them and adapt them to be more flexible for testing. As I wrote earlier, many methods have already hardcoded data, and in some cases this limits the completeness of testing, as it is impossible to check whether my data will actually be sent to Telegram. In my previous post, I tried to provide a solution that I think could be used to improve testing. In your opinion, would it be possible to add a similar solution to allow mocks to work with data that user provided? |
Beta Was this translation helpful? Give feedback.
-
Hello!
Recently, i wanted to test some of my handlers, and discovered that some of them are not giving me expected results.
For example, wanted to test a handler that returns user a message with caption and photo:
But got this exception:
Cannot cast value of type string to type WeStacks\TeleBot\Objects\PhotoSize at vendor/westacks/telebot/src/Contracts/TelegramObject.php:40
.This was a bit confusing, because if not faking the request, everything works perfectly. So i went to check what is wrong, and i discovered that i can only pass
chat_id
, everything else is pretty much hardcoded inmock
method:And in other handlers as well, for example in
ExportChatInviteLinkMethod
:But mostly in all tests i need to check some specific data, like
photo
, orfirst_name
, which are hardcoded, but every method has$arguments
which are mostly not used.So the question is: do you plan to add support of using passed arguments in tests?
Maybe, for example, adding
defaults
method toTelegramMethod
class will help? That way each method will be able to return default values for mocks or override defaults if user provided arguments himself, something like this:I'm sorry if i wrote this in wrong category, just wanted to know if this could be possible?
Also, thank you for your work on this project, its always nice to see new updates :)
Beta Was this translation helpful? Give feedback.
All reactions