Advanced OOP for WordPress Part 8: using test led development to develop new features for extensible WordPress plug-ins

In the last post in this series, I looked at the low-level API revision of the plug-in, which uses tests to guide the process and ensure that everything works properly. It is called \
Test – led development (TDD) is actually a way to test code – based changes before they are created. This will test the specification that defines the new function \/ bug fix \/ whether it works. Existing tests also define whether to generate new function \/ error correction \/ regression errors. Switching from an existing code base to TDD is not easy. Let’s see how to use this existing plug-in. Before evaluating an existing test, it is important to confirm what the existing test is doing. Now we mainly have a test. The test result is the arrangement of androg wp_posts androg. Through similar tests, verify whether the rest API response is correct. The
The content of multi wp_posts is wp\u posts. Now we have identified what is missing from the test suite. Now you are ready to create your tests. Starting with the analog input, we begin to create the array that we want this factory class to input. I created that array in a factory test. Now we will create a non working version of the factory and create tests to verify basic functionality. The following is an overview of the search class that uses two interfaces and has getter functionality. That’s what my factory makes. We will start the factory using the parameters to be added and the post type to be added, and using the export search method. The
Now you can create a return type that contains the exposed methods of each definition. It will not pass yet. It calls methods that we haven’t written yet. After adding this article to these methods, you can quantify whether it has worked. But it is ahead of us. First, you must have the search class set up everything. Before it happens, we must know what it is doing. Search is responsible for putting systems together. Therefore, although multiple tasks are performed, as long as the role of the controller is to assign another system according to the logic defined on the other system, there is still only one responsibility. The
Let’s list the tasks that need dispatch. In order to know the path of the schema that you want to modify and modify a specific rest API path, you must use an object that implements the modifyschemacontract interface. To modify the whitelist of query parameters, you must use an object that implements the modify queryargscontract interface. To make these changes, you must connect to the WordPress plug-in API (hook). Let’s start with the last link plug-in API. That is, we have the least control, indicating what we should do. By making the plug-in API provide data, people no longer worry about how to obtain all the correct dependent objects of wp_query, wp\rest\u request and wp\rest\u request from the core. The
Search needs to add a hook and want to remove it. Since it is likely to be reused, a formal mode interface has been added. My goal is to use the filterqueryargs() and filterqueryargs() methods filterqueryargs() in the last set of interfaces
You can import small tiles. This requires a second repackaging of the two interfaces, which I showed earlier and always said we should visit again. Now is the time for a second revision. The new interface for filtering query arguments is as follows: The following is a new interface for filtering mode parameters: This report removes what these classes actually need to connect to the word press plug-in API. Now it is all handled by the search class. In addition, the male shouldfilter() malemethod both have the same signature. I like this. Interfaces can inherit from other interfaces, so you can move methods to their own interfaces that both interfaces inherit. Thus, each interface creates only one requirement that the interface separation principle tells you. Instead, I would say it is wrong, so you can modify it and add the complete request. Write a blog post for this and reply to @me on twitter. Capture dependencies using the plug-in API this factory can set filters for input methods, but cannot set filters for modifying actual query results. Before that, Tonya and I discussed the methods that I decided that the class responsible for generating results should at least recognize wp\u query and wp\u rest\u request. For this reason, the reference of wp_rest_request is required at present. WordPress does not have a service container for my solution request, so what you can see in this submission is that you can capture the current request and inject it into the content publisher using the rest_pre\u serve\u request filter. This filterwpquery in the filterwpquery class. Wp\u rest\u request is required inside the getposts() method. To import the request, a new capturerequest method is added and placed in the static variables available in getposts (). I can still test it with unit tests, replace the plug-in API with inline, and my other tests are still valid. At the beginning of scalability, the following article describes how to make the system scalable. The filterwpquery class now has an init (), which I wrap as a setter method with a corresponding getter. In this way, getposts () acts as the dispatcher for the last set contentgetter. I hope this router is more abstract. For example, different post types have different implementations. At this point, the class is as follows: Now, you can replace all the items in the plug-ins that need to be replaced, and there is a factory to manage these items. The following article will be written on this basis. All the code in this document and the previous document is added to the sample plug-in through this pull request. There are more tests than discussed in this article. I repeat that the plug-in does not have 100% test coverage and has not done what it should do. Tonya and I will improve it during our writing. You are invited to participate. I think contributing to this plugin will be a good way to apply what you are learning.

Author:

Leave a Reply

Your email address will not be published. Required fields are marked *