Unit Test-what are the useful design patterns in php?

Source: Internet
Author: User
Recently, data access objects, templates, and command modes were used in the project. I feel that it has played a very good role in improving the structure. The command mode improves the if branch structure of the controller, and the action code is simplified to two lines. One problem currently is that controllers cannot perform unit tests, so we have to simplify the generation as much as possible. in recent projects, we have used data access objects, templates, and command modes. I feel that it has played a very good role in improving the structure. The command mode improves the if branch structure of the controller, and the action code is simplified to two lines.

One problem currently is that the controller cannot perform unit tests, so we have to simplify the code as much as possible.

Do you have any good experience?

We recommend a good book: restructuring and model.

Reply content:

Recently, data access objects, templates, and command modes were used in the project. I feel that it has played a very good role in improving the structure. The command mode improves the if branch structure of the controller, and the action code is simplified to two lines.

One problem currently is that the controller cannot perform unit tests, so we have to simplify the code as much as possible.

Do you have any good experience?

We recommend a good book: restructuring and model.

It is not absolutely easy to use. sometimes you will love a design pattern during this period and think it is the most perfect design pattern in the world. this is the only one in your life, you can't help but boast about it.

But maybe you will forget it for the next project. What you said is still in the scope of program structure. my experience is that you should not think about refactoring at the beginning of the project, so that you will constantly struggle with the original code and cannot extricate yourself, I believe everyone has heard of the story of a programmer's code change. The Superior asked a programmer to add a function. Finally, the programmer directly overwrites others. I want to measure whether a programmer is mature, that is, whether he can suppress this impulse at the right time.

As for the problem that the controller you mentioned cannot be tested, I think it does not exist. However, we have to invite QA to answer this question.

Unit testing is not possible because the dependencies on different layers are too strong and the dependency generation method is not elegant enough and messy. as a result, you cannot easily replace this dependency for unit testing.

What you are talking about is that the controller cannot perform a good unit test. I guess it is because of the data persistence layer. master MF recommends the domain model to solve this dependency problem well, however, it will increase the complexity of the project. this is a point that architects need to weigh!

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.