Unit test-What are the useful design patterns in PHP?

Source: Internet
Author: User
In recent projects, data Access objects, templates, and command patterns have been used. The feeling has a good effect on the improvement of the structure. The IF branch structure of the controller is improved with the command mode, and the action code is simplified to two lines.

One problem is that the controller is not able to do unit tests and has to simplify the code as much as possible.

Do you have any good experience?

Recommend a good book: refactoring and Patterns.

Reply content:

In recent projects, data Access objects, templates, and command patterns have been used. The feeling has a good effect on the improvement of the structure. The IF branch structure of the controller is improved with the command mode, and the action code is simplified to two lines.

One problem is that the controller is not able to do unit tests and has to simplify the code as much as possible.

Do you have any good experience?

Recommend a good book: refactoring and Patterns.

There is no absolutely good, sometimes you will be in this time more in favor of a design pattern, think it is the world's most perfect design mode, this is the only one of your life, you will be tempted to praise it, always hanging in the mouth.

But maybe next project you will forget it completely. You say these also belong to the scope of the program structure, my experience is not at the beginning of the project to focus on the construction, so you will continue to struggle with the original code can not extricate themselves, I believe that we have heard a programmer to change the story of the code, the superior let a programmer add a function, and finally the programmer to rewrite the other people's Things I want to measure whether a programmer's maturity is a sign that he can suppress the impulse at the right time.

As you said the controller can not test the problem, I think there is no. But this has to be an invitation to QA to answer.

The inability to unit test, most likely due to the strong dependency in different layers, and the way the dependencies are not elegant and messy, makes it impossible for you to easily replace this dependency for unit testing.

You said the controller is not good unit testing, I guess it should be because of the data persistence layer caused, the master MF recommended is a domain model to solve this dependency problem, but will increase the complexity of the project, this is the need for architecture adjuster tradeoff point!

  • Related Article

    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.