-
Notifications
You must be signed in to change notification settings - Fork 671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Todo] Write Tests #5
Comments
Ugh. Don't make me learn this stuff! My brain can't keep up! |
It's good to learn though..lol For long run it'll be helpful to automatically test things :D |
Hi, I've pushed some tests, covering the basics. Hope it helps! |
Do |
@antoniomadonna, providing configuration for Phpunit via XML (bootstrap and other variables) is better way: https://phpunit.de/manual/current/en/organizing-tests.html#organizing-tests.xml-configuration |
ok @zhukovra added config file |
Excellent. This is a good start. I have the tests installed and all passing here. I do have a few suggestions. I've only just started to implement tests in my own projects, so it's a learning curve for me but here's some thoughts. 1) Composer.lockWe now need to ensure that a Without the lock file, we can NOT be certain we are all pulling in exactly the same version of the dependencies. (In fact you will receive a @irazasyed - You need to commit a 2) Guzzle StereoI've started to use This allows us to hit the API with some requests, save them to a json file, and then use them over and over again to test other parts of the code without having to hit the real Telegram API servers. It works really well. Perhaps we could integrate some of these into some functional tests at a later date. 3) How the tests are written.If you have a few minutes, please take a look at this video from jeffrey_way at laracasts. It's a wonderful lesson/suggestion on how we should be naming our tests and WHY. In this short video I think he's using Have done this now for a few weeks, I really see the benefit of doing this. It kinda frees up your mind a little. It's very easy to do in phpunit too. All we do is change this public function testAddsMultipleCommands()
{
$this->api->addCommands([MockCommand::class, MockCommandTwo::class]);
$commands = $this->api->getCommands();
$this->assertInstanceOf(MockCommand::class, $commands['mycommand']);
$this->assertInstanceOf(MockCommandTwo::class, $commands['mycommand2']);
} To this: /** @test */
public function it_checks_the_correct_number_and_type_of_commands_get_added()
{
$this->api->addCommands([MockCommand::class, MockCommandTwo::class]);
$commands = $this->api->getCommands();
$this->assertInstanceOf(MockCommand::class, $commands['mycommand']);
$this->assertInstanceOf(MockCommandTwo::class, $commands['mycommand2']);
$this->assertCount(2, $this->api->getCommands());
} I'm interested to hear your feedback on this. |
@jonnywilliamson Thanks for writing your suggestions. They really look good. Here's my response. I'm going one by one, same as your points.
Thanks! |
@jonnywilliamson thanks for your feedback :)
|
Exactly, I think your method in the unit tests is very good. It just might be more useful in integration tests later. The |
Hi, So I spent the morning trying to see if I can expand on the tests that have been provided so far. I think I've made a reasonable attempt at it. I decided I wanted to extract all the mocking of telegram api responses and update responses into their own class. I didn't like having that all in one test file. I made the TGMock file with static methods as I think this shouldn't cause any problems and it makes it pretty straightforward when you want to grab a mocked object. If people think this it is better to DI it into All tests were passing when I committed. I'm interested to see what you think. There's no point me continuing if I'm making mistakes. |
Need to write tests.
The text was updated successfully, but these errors were encountered: