Skip to content
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

How to mock or disable Botman middleware? #1225

Open
chimit opened this issue Nov 17, 2020 · 0 comments
Open

How to mock or disable Botman middleware? #1225

chimit opened this issue Nov 17, 2020 · 0 comments

Comments

@chimit
Copy link

chimit commented Nov 17, 2020

  • BotMan Version: 2.6.1
  • PHP Version: 7.4
  • Messaging Service(s): Telegram
  • Cache Driver: file

Description:

I need to skip Botman middleware in tests. The default Laravel Illuminate\Foundation\Testing\WithoutMiddleware trait doesn't disable Botman middleware in tests. I also tried to mock it but without success:

I have a CreateUniverse Matching middleware. First I resolve it through the Service Containter:

//
// botman.php
//

$middleware = resolve(CreateUniverse::class);

$botman->hears('hi', function (BotMan $bot) {
    $bot->reply('hello');
})->middleware($middleware);

Then I'm trying to mock it:

//
// RoutesTests.php
//

$middleware_double = Mockery::mock(CreateUniverse::class);

$middleware_double->shouldReceive('matching')
    ->once()
    ->with(Mockery::any())
    ->andReturn(true);

$this->app->instance(CreateUniverse::class, $middleware_double);

$this->bot
    ->receives('hi')
    ->assertReply('hello');

But get an error:

Mockery\Exception\InvalidCountException: Method matching(<Any>) from Mockery_0_App_Http_Middleware_CreateUniverse should be called exactly 1 times but called 0 times.

It looks like my mock is not applied.

@chimit chimit changed the title WithoutMiddleware doesn't work How to mock or disable Botman middleware? Nov 18, 2020
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

1 participant