Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8684453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:18:37+00:00 2026-06-12T22:18:37+00:00

I have a class I need to mock: class MessagePublisher { /** * @param

  • 0

I have a class I need to mock:

class MessagePublisher
{
    /**
     * @param \PhpAmqpLib\Message\AMQPMessage $msg
     * @param string $exchange - if not provided then one passed in constructor is used
     * @param string $routing_key
     * @param bool $mandatory
     * @param bool $immediate
     * @param null $ticket
     */
    public function publish(AMQPMessage $msg, $exchange = "", $routing_key = "", $mandatory = false, $immediate = false, $ticket = null)
    {
        if (empty($exchange)) {
            $exchange = $this->exchangeName;
        }

        $this->channel->basic_publish($msg, $exchange, $routing_key, $mandatory, $immediate, $ticket);
    }
}

I am using Mockery 0.7.2

$mediaPublisherMock = \Mockery::mock('MessagePublisher')
    ->shouldReceive('publish')
    ->withAnyArgs()
    ->times(3)
    ->andReturn(null);

unfortunately my tests failed, due to this error

call_user_func_array() expects parameter 1 to be a valid callback,
class ‘Mockery\Expectation’ does not have a method ‘publish’ in
/vendor/mockery/mockery/library/Mockery/CompositeExpectation.php
on line 54

I have tried to debug I found that tests fails in this code

public function __call($method, array $args)
{
    foreach ($this->_expectations as $expectation) {
        call_user_func_array(array($expectation, $method), $args);
    }
    return $this;
}

where
$method = ‘publish’
$args = array()
$expectation is instance of Mockery\Expectation object ()

I am using php 5.3.10 – any idea what is wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:18:38+00:00Added an answer on June 12, 2026 at 10:18 pm

    This is happening because you are assigning a mock expectation to $mediaPublisherMock, rather than the mock itself. Try adding the getMock method to the end of that call, like:

    $mediaPublisherMock = \Mockery::mock('MessagePublisher')
        ->shouldReceive('publish')
        ->withAnyArgs()
        ->times(3)
        ->andReturn(null)
        ->getMock();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need mock some class with final method using mockito. I have wrote something
I have class grades that I need to check if a specific grade is
I have a class that I need to perform some actions on but I
I have a class that I need to be able to serialize to a
I have class Meat extends Food { $var = Food::foodFunction… } I need to
In php have a class SoapClient I need a equivalente class in Java, anyone
I currently have a class where I need accomplish the equivalent of the following
I have a class derived from Dictionary. I need this class to simulate a
I have class Fruit with data and logic. Now I need a lot of
I have class Base and classes Derived_1 , Derived_2 ... I need derived classes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.