Dirty data processing in PHP unit test

Source: Internet
Author: User
During unit tests, dirty data is inevitable. What should we do with dirty data? The first method we thought of was to delete and modify the test method, record the data before the operation, and restore the data after the operation is completed. Add, record the new primary key, and delete it in the test script after the test is completed. I previously thought about a lot of clever methods to make operations more

During unit tests, dirty data is inevitable. What should we do with dirty data? The first method we thought of was: In the test method, the data was deleted/modified, recorded before the operation, and restored after the operation was completed. Add, record the new primary key, and delete it in the test script after the test is completed. I previously thought about a lot of clever methods to make operations more

During unit tests, dirty data is inevitable. What should we do with dirty data?
The first method we come up with is:
In the test method,
Deleted/changed. Data is recorded before the operation and restored after the operation.
Add, record the new primary key, and delete it in the test script after the test is completed.

I thought about a lot of methods to make it easier, but they are not perfect, and some are even very bad.
1. Add an observer to the data layer and notify the observer to process the changed data.
In this way, not only some changes may be missed, but also the structure of the program needs to be re-designed, the data layer is not feasible.
2. Use a temporary table
Create a temporary table in setUp () and bind it to the table gateway class. Delete the temporary table in tearDown.
In this way, when a test class needs to call multiple table gateway classes, it is a disaster to get n table gateway classes and bind them to the model.

In the end, the first thought is better.

Original article address: PHP unit test dirty data processing method. Thank you for sharing it with me.

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.