Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In cases where you use the same method more than once, you should use the "at" declaration with the proper count where executed in the code. This way PHPUnit knows which one you mean, and can fulfill the expectation/assertion properly.</p> <p>The following is a generic example where method 'run' is used several times:</p> <pre><code>public function testRunUsingAt() { $test = $this-&gt;getMock('Dummy'); $test-&gt;expects($this-&gt;at(0)) -&gt;method('run') -&gt;with('f', 'o', 'o') -&gt;will($this-&gt;returnValue('first')); $test-&gt;expects($this-&gt;at(1)) -&gt;method('run') -&gt;with('b', 'a', 'r') -&gt;will($this-&gt;returnValue('second')); $test-&gt;expects($this-&gt;at(2)) -&gt;method('run') -&gt;with('l', 'o', 'l') -&gt;will($this-&gt;returnValue('third')); $this-&gt;assertEquals($test-&gt;run('f', 'o', 'o'), 'first'); $this-&gt;assertEquals($test-&gt;run('b', 'a', 'r'), 'second'); $this-&gt;assertEquals($test-&gt;run('l', 'o', 'l'), 'third'); } </code></pre> <p>I think this is what you're looking for, but if I'm misunderstanding please let me know.</p> <p>Now in terms of mocking anything, you can mock it as many times as you want, but you are not going to want to mock it with the same name as in the setup, else every time you use it you are referring to the setup. If you need to test similar methods in different scenarios, then mock it for each test. You could create one mock in the setup, yet for one test use a different mock of a similar item within an individual test, but not of the global name.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload