test double - An example (or several) about method at() in phpunit -


would anybody, please, show me example at method in phpunit test doubles. don't understand purpose?

the purpose of at() function specify order methods on mock should called. if use once() or exactly(), test pass no matter order methods called phpunit checking called during test not when.

for example:

class footest extends phpunittestcase {     public function testproperorderofmethods() {          $mockobject = $this->getmockbuilder('barobject')              ->setmethods(['baz', 'boz'])              ->getmock();           $mockobject->expects($this->at(0))              ->method('boz');           $mockobject->expects($this->at(1))              ->method('bar');           $sut = new foo();          $sut->methodbeingtested($mockobject); } 

this requires our function needs like:

public function methodbeingtested($dependecy) {     $dependency->boz();     $dependency->bar(); } 

and fail if function order changed.

an example use case might class using object connects service , retrieves data. want have connection opened, retrieve data, , close connection. or may need make further requests depending on response. either way of these actions need happen in specific order in test, use at().


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -