php - Questions regarding PHPUnit mock feature -


Can someone provide me a reference for a good PHPUnit fake guide? One does not seem to be sufficiently detailed, I am trying to study PHPUnit by reading the source code, but I am not familiar with the word matcher, invocation motors, stub returns etc.

I need to know about the following:

1) For many calls to the method of a counterfeit How is expected, but each brings a different set value back?

  $ tableMock - & gt; Hopefully ($ --- (exactly - 2)) - & gt; Method ('Find') - & gt; Will be ($-this-> return value (2)); // I need a second call to return different values ​​ 

2) The method of the mock object with a call How to expect parameters in many ways?

[ Note: All code samples from linked sites, follow links for more Make a complete explanation. ]

return different values ​​

(current) PHPUnit Documentation suggests or:

  $ stub-> ($ This- & gt; none) - & gt; Method ('doSomething') - & gt; ($ - this-> return callback ('str_rot13')); $ Stub-> Expect ($ this- & gt; Any ()) - & gt; Method ('DoSomething') - & gt; Will be ($ this- & gt; onConsecutiveCalls (2, 3, 5, 7));  

Expect multiple parameters

with () can contain:

  $ observer -> ($ this- & gt; once ()) - & gt; Method ('reportError') - & gt; GreaterThan (0), $ this- & gt; StringContains ('some'), $ this-> gt ($ this- & gt; anything);  

Test multiple calls

However, on the related topic (and not in PHPUnit documentation, which I can find), you do not have to click on () From:

  $ inputFile-> Expected ($ -> (0)) - & gt; Method ('Read') - & gt; - & gt; Return value ("3 4")); $ Inputfile- & gt; ($ -> (- (1)) - & gt; method ('read') - & gt; will ($ -> - ($ 6-); return value ("6" 6); $ inputfile - & gt; Hope ($ -> (- (2)) - & gt; Method ('Read') -> Will ($ this-> Return Value (NULL));  < / Pre> 

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -