Facebook's newly developed PHP mock tool: fbmock_php Tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.