CKvUMceUAAMtMaz
WordPress x CI is a talk by our Engineer Horike Takahiro, along with web designer and programmer Takashi Kitajima, and front-end engineer Toro Unit. This is an introductory talk to their “WordPress x CI hands-on”.

 

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.

Screen Shot 2015-08-03 at 17.00.44
Authored by Horike and megumithemes, WP Syndicate is a plugin published in WordPress.org. that they will use as an example for plugin maintenance, which is quite a long process.

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

Test-Driven Development

First, you should create a test and after which, you should refine your code.

Screen Shot 2015-08-03 at 17.12.28
Established in 2001, PHPUnit is a multifunctional PHP testing framework where you can write unit tests.

PHPUnit Flow of Development:

  • Write test code
  • Write the code of plugins
  • Run the test in phpunit command

Test Case

Screen Shot 2015-08-03 at 17.15.56

Assertion
By comparing the actual results with the expected value, the success or failure of the test is determined.

Reference: Appendix with various assertion methods 

Annotation
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.

Screen Shot 2015-08-03 at 17.55.49

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.

Travis CI

  • 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

Screen Shot 2015-08-03 at 17.35.05

Result

Screen Shot 2015-08-03 at 17.39.39

“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

 

Deployment Automation

Normal Deployment:

  • 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

 

 

Screen Shot 2015-08-03 at 17.46.46

Wordmove

  • WordPress deployment tools made with Ruby
  • Automatically replace URL in staging and production in DB
  • Movefile describes deployment information