To make testing run faster and more reliable, writing tests is more convenient, people often use mock instead of directly using real external dependencies recently, Facebook has written a new PHP mock tool that looks very neat and tidy with its mock-up. When using other PHP mock frames, the code that is written requires more statements and makes the test too dependent on the specifics of the implementation. For example, when we use PHPUnit to make a mock, but simply return some values, the code might look like this [PHP]
$user = $this->getmock (' user ') ->expects ($this->any ()) ->method (' GetID ') ->will ($ This->returnvalue (1234);
When using Fbmock, the code is as follows: [php] $user = mock (' user ')->mockreturn (' GetID ', 1234); In fact, Fbmock is not really a mock frame, because it does not have the same value as the above code. So, it can only be regarded as a pile with spy function. In fact, this expectation check in a mock frame is best used sparingly, because it is a bit too restrictive. In the case of fbmock above, I don't really care how many times GetID () was called. Of course, sometimes it is important to check which method is called, which can simply depend on the assertion in PHPUnit. [php] $logger = mock (' logger '); Run code that uses $logger//Make sure ' data ' is logged $this->assertcalledonce ($logger, ' log ', array (' data ')); Currently, Fbmock supports Zend PHP 5.4+ and HipHop VMs.
http://www.bkjia.com/PHPjc/477686.html www.bkjia.com true http://www.bkjia.com/PHPjc/477686.html techarticle to make testing run faster and more reliable, writing tests is more convenient, people usually use mock instead of directly using real external dependencies recently, Facebook has written a new PHP mock tool ...