They said that the common issue in traditional development is when you write the code, you have to test it in the browser, write the code again and continue, and if an error occurs, you have to modify the code.
Result: additional development and/or bug fixes.
According to them, the code becomes complicated every time the version increases. Sometimes they even forget why they made a specific function in the first place.
Then one day… with a version update, the plugin became buggy! So what can you do to avoid this?
Will you create a test specification document? It’s difficult to write, so you may not want to do that, and therefore plugin maintenance is not done.
The fastest solution is Continuous Integration.
For application development, there is an ongoing quality improvement and shorter lead times.
Their tip is to automate this flow: Development –> test –> Git, SVN reflection –> Deploy
First, you should create a test and after which, you should refine your code.
PHPUnit Flow of Development:
- Write test code
- Write the code of plugins
- Run the test in phpunit command
By comparing the actual results with the expected value, the success or failure of the test is determined.
Reference: Appendix with various assertion methods
Describes the test run-time options in the form of PHP comment.
Example, @after can be used to specify methods that should be called after each test method in a test case class.
Reference: Appendix with annotations
WordPress uses PHPUnit
In a sample test, they created a post with the title “Hello!”
The post title hello is returned.
They also ran a sample test [hello_world] short code (assertEquals verifies the result of the short code).
With continuous PHPUnit testing, quality is ensured.
- CI service is available on GitHub
- Run the test when the hook is pushed to GitHub
- The test setting is in travis.yml
travis.yml – test can be in multiple PHP and WordPress version
“passing” shows that the test is through
Travis CI Benefits
- passing the test at the time of the push can be secured
- automatic testing in PHP and multiple versions of WordPress
- the test quality can be described on GitHub
- Upload file to server (FTP)
- FTP: upload file to server / phpmyadmin database replacement
Normal Deployment Problems:
- manual work complexity
- (broken heart with) replacement of database
- WordPress deployment tools made with Ruby
- Automatically replace URL in staging and production in DB
- Movefile describes deployment information