Skip to content

Functional testing in Laravel Project #201

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

Closed
ivankovbas opened this issue Jun 24, 2016 · 8 comments
Closed

Functional testing in Laravel Project #201

ivankovbas opened this issue Jun 24, 2016 · 8 comments

Comments

@ivankovbas
Copy link

Hi!
I'm using the SDK in my Laravel project and I want to write functional tests like this:

    ...
    public function testStartCommandWorksAsExpected() {
        $this->post($this->getWebHookUrl(), $this->prepareMessage("/start"));
        $this->seeInDatabase('dialogues', ['user_chat_id' => 0]);
    }
    ...

post method emulates Request object, but not php://input. So the SDK can't populate Update object correctly cause of that: https://github.com/irazasyed/telegram-bot-sdk/blob/master/src/Api.php#L966

So, how can I write my tests?

@jonnywilliamson
Copy link
Contributor

Yeah I've had this issue since the very start.

Some non-optimal solutions

http://stackoverflow.com/questions/3221542/how-do-i-override-php-input-when-doing-unit-tests

http://news-from-the-basement.blogspot.ie/2011/07/mocking-phpinput.html

If you have any better suggestions please pass them on and make a PR too!

@jonnywilliamson
Copy link
Contributor

Still have this problem but don't know of a good way around it. Anyone else any clever solutions?

http://stackoverflow.com/questions/16296899/file-get-contentsphp-input-empty-in-unit-test

@jonnywilliamson
Copy link
Contributor

I've had an idea. Seems to be working!

PR coming!

@mobasher92
Copy link

I have a problem with laravel. the webhook is set but whenever a request is sent to my webhook I just want to log that it's working with "Log::info('webhook is working!');"
but I get this error : "Illuminate\Session\TokenMismatchException"
I tried to solve it by adding the route exceptions in protected $except in this file: app/Http/Middleware/VerifyCsrfToken.php
but I'm still getting the error :(
can you help me please?

@irazasyed
Copy link
Owner

@mobasher92 Create a new issue with your route codes and the $except array, so we can verify and suggest something.

@irazasyed irazasyed reopened this Sep 2, 2016
@McGo
Copy link

McGo commented Sep 16, 2016

@mobasher92 your route seems to be setup in web middleware group. This include the check for CSRF token which is not sent from telegram. Just setup the route without web middleware and you are done.

Sorry: was reposted as own topix.

@mobasher92
Copy link

I did it in laravel 5.1. the $exception property is not supported in laravel 5 but in larvel 5.1 when I did the installation step in this doc: https://telegram-bot-sdk.readme.io/docs
I had a problem in this step:
php artisan vendor:publish --provider="Telegram\Bot\Laravel\TelegramServiceProvider"
I got the message that nothing to be published and telegram config file was not cpoied to config folder so i did it manually but after that when I wanted to user Telegram::... in my code I got this error that "Telegram class is not found ..."

why? how can i specify in code that where is the Telegram class I am using?

@irazasyed
Copy link
Owner

Please refer this example starter: https://github.com/irazasyed/telegram-bot-laravel-starter

Closing this issue as it's quite old now. But feel free to create a new one after testing the above starter. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants