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 3443484
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:47:49+00:00 2026-05-18T08:47:49+00:00

I am using PHPUnit for my unit tests I am using a mock object

  • 0

I am using PHPUnit for my unit tests I am using a mock object to test if a method is called with the correct parameters. This works fine when I just want to do this once.

    $logMock = $this->getMockBuilder('Logger')
            ->disableOriginalConstructor()
            ->getMock();

    //check if it updates the correct record
    $logMock->expects($this->exactly(1))
            ->method('updateLog')
            ->with(456, 'some status');

Now I have the situation that I want to test if the updateLog is called a second time (with different parameters). I don’t see how I can do this with the ‘with’ method.

Does anybody have a suggestion?

  • 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-05-18T08:47:50+00:00Added an answer on May 18, 2026 at 8:47 am

    I don’t know your mocking framework. Usually you just create another expectation though. I assume that should work with this framework as well.

    $logMock->expects($this->exactly(1))
             ->method('updateLog')
             ->with(100, 'something else');
    

    Edit

    It seems that the PHPUnit framework doesn’t support multiple different expectations on the same method. According to this site you have to use the index functionality.

    It would then look like this

    $logMock->expects($this->at(0))
            ->method('updateLog')
            ->with(456, 'some status');
    $logMock->expects($this->at(1))
             ->method('updateLog')
             ->with(100, 'something else');
    $logMock->expects($this->exactly(2))
            ->method('updateLog');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a unit test for a controller using Zend and PHPUnit
I am currently performing unit tests on my code (using PHPUnit and Jenkins) but
I am using PHPUnit to test insertion of objects via my storage object. Each
I am trying to unit test my Zend Framework application using PHPUnit 3.6.4. I
I'm writing unit tests for a project (written in PHP, using PHPUnit) that have
I'm using PHPUnit to try to unit test some PHP files that are part
I am used to writing unit tests in Zend Framework 1.9 using PHPUnit_Framework_TestCase for
i am using simpletest as my php unit test framework. i put all my
I'm writing a unit test for a class method that calls another class's method
Hey everyone, I've been using PHPUnit to to do unit testing on a Symfony/Doctrine

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.