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

  • Home
  • SEARCH
  • 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

Im trying to integrate my PHPUnit tests into Hudson using the xUnit plugin. After
I'm currently using Zend Framework in conjunction with PHPUnit to conduct unit testing on
Whats the way to unit test Doctrine 2 models? I am using it with
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using C#, I need a class called User that has a username, password, active
Trying to get started using phpunit and can't get it installed/setup properly. When I
I'm using PHPUnit's Selenium extension to do web testing. I'm finding it very slow,
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a

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.