Skip to content

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

@Naouak

Description

@Naouak
  • 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;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions