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

Illuminate\Queue\CallQueuedHandler uses a non existent function in Illuminate\Contracts\Bus\Dispatcher #22951

Closed
Naouak opened this issue Jan 29, 2018 · 5 comments

Comments

@Naouak
Copy link
Contributor

Naouak commented Jan 29, 2018

  • Laravel Version: 5.5.32
  • PHP Version: Irrelevant
  • Database Driver & Version: Irrelevant

Description:

$handler = $this->dispatcher->getCommandHandler($command) ?: null;

In this file, $this->dispatcher is an instance of Illuminate\Contracts\Bus\Dispatcher.
Illuminate\Contracts\Bus\Dispatcher has no method getCommandHandler defined so when mockery create a mock of the dispatcher, the function getCommandHandler is not available.
You get this error:

BadMethodCallException : Method Mockery_0_Illuminate_Contracts_Bus_Dispatcher::getCommandHandler() does not exist on this mock object
 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:70
 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:49
 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:76
 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php:42
 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Queue.php:44
 /var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:475
 /var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:434
 /var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:369
 /var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:200
 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:465
// ...

Steps To Reproduce:

This test generates the error.

<?php

class BuggyListener implements \Illuminate\Contracts\Broadcasting\ShouldBroadcast
{
    public function broadcastOn()
    {
        return [];
    }
}

class LaravelBugTest extends Illuminate\Foundation\Testing\TestCase
{
    public function testBug()
    {
        $this->expectsJobs([]);
        event(new BuggyListener());
    }

    public function createApplication()
    {
        $app = require __DIR__.'/../bootstrap/app.php';
        $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

        return $app;
    }
}
@Naouak Naouak changed the title Illuminate/Queue/CallQueuedHandler use a non existent function in Illuminate\Contracts\Bus\Dispatcher Illuminate/Queue/CallQueuedHandler uses a non existent function in Illuminate\Contracts\Bus\Dispatcher Jan 29, 2018
@Naouak Naouak changed the title Illuminate/Queue/CallQueuedHandler uses a non existent function in Illuminate\Contracts\Bus\Dispatcher Illuminate\Queue\CallQueuedHandler uses a non existent function in Illuminate\Contracts\Bus\Dispatcher Jan 29, 2018
@themsaid
Copy link
Member

It's just that the contract is missing a few methods, feel free to send a PR on 5.6 to add the missing methods.

@Jnesselr
Copy link
Contributor

Jnesselr commented Jul 5, 2018

I'm currently getting the same error: BadMethodCallException : Method Mockery_0_Illuminate_Contracts_Bus_Dispatcher::getCommandHandler() does not exist on this mock object

I've upgraded to version 5.6.26. What's weird to me is that I can use the expectsJobs in another context where I use "dispatch" directly, but it's failing in this context where I'm expecting it to be fired as a reaction from an event.

@jcooke22
Copy link

I was also getting this error on Laravel 5.3:

BadMethodCallException : Method Mockery_0_Illuminate_Contracts_Bus_Dispatcher::getCommandHandler() does not exist on this mock object

I'm not able to upgrade the Laravel version to 5.6 right now so I implemented a workaround by overriding the withoutJobs() method on TestCase to use a custom Dispatcher interface which includes the missing method signatures.

TestCase
Dispatcher

@coreation
Copy link

.6.26. What's weird to me is that I can use the expectsJobs in another context where I use "dispatch" directly, but it's failing in this context where I'm expecting it to be fired as a reaction from an event.

Did you find a solution for this one?

@Jnesselr
Copy link
Contributor

Jnesselr commented Nov 8, 2018

.6.26. What's weird to me is that I can use the expectsJobs in another context where I use "dispatch" directly, but it's failing in this context where I'm expecting it to be fired as a reaction from an event.

Did you find a solution for this one?

I did! Finally. And I made a pull request to boot! (Which is linked above)

taisph pushed a commit to cubs/laravel-framework that referenced this issue May 25, 2020
taisph pushed a commit to cubs/laravel-framework that referenced this issue Apr 28, 2021
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