SlideShare a Scribd company logo
Automatic testing
and quality assurance
for WordPress plugins
WordCamp Jyväskylä 2018
Otto Kekäläinen
@ottokekalainen
WP-palvelu.fi
● WP-palvelu.fi – WordPress hosting
and upkeep
● CEO, sysadmin and developer
● Linux and open source advocate
● Contributed to WordPress Core, fi
and sv translations, Linux, Docker,
Nginx, Redis, MariaDB…
● Twitter:@ottokekalainen
Otto Kekäläinen
Enterprise grade
hosting and upkeep
for WordPress
EVERYBODY WANTS QUALITY
Developers just don’t have
enough time or customers’ budget
Automatic ~ zero cost
DO EVERYTHING THAT CAN BE AUTOMATED
● scan code to find errors
○ static analysis
● run code to find errors
○ unit and integration tests
TOOLS
1. what to do about PHP code
2. how to automate
WHAT TO DO ABOUT PHP CODE
● PHP Code Sniffer
● PHP unit tests
● PhantomJS integration tests
● performance
○ execution time
○ memory usage
PHP CODE SNIFFER
PHPCS
PHPCFB AND GIT CITOOL
phpcs.xml
<?xml version="1.0"?>
<ruleset name="Seravo">
<!-- show progress -->
<arg value="p"/>
<!-- check current and all subfolders if no file parameter given -->
<file>.</file>
<rule ref="Squiz.PHP.CommentedOutCode"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
<rule ref="Generic.Commenting.Todo"/>
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<rule ref="WordPress-Extra">
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent"/>
<exclude name="Generic.WhiteSpace.ScopeIndent"/>
<exclude name="WordPress.WhiteSpace.PrecisionAlignment.Found" />
<exclude name="WordPress.PHP.YodaConditions" />
</rule>
</ruleset>
phpcs --standard=Security
FILE: tools/gapi.php
---------------------------------------------------------------------
FOUND 1 ERROR AND 8 WARNINGS AFFECTING 8 LINES
---------------------------------------------------------------------
35 | WARNING | Possible RFI detected with GADWP_DIR on include_once
51 | WARNING | Function array_map() that supports callback detected
148 | WARNING | Possible XSS detected with esc_url on echo
152 | WARNING | Possible XSS detected with __ on echo
156 | WARNING | Possible XSS detected with _e on echo
307 | WARNING | Crypto function crc32 used.
767 | WARNING | Function array_map() that supports callback
---------------------------------------------------------------------
More tips at seravo.com/coding-wordpress-in-style-with-phpcs
PHP UNIT
TESTS
assertEquals(a, b)
INTE-
GRATION
TESTS
now with
PhantomJS
soon with
Headless
Chromium
Example test code
it "There's a login form" do
expect(page).to have_id "wp-submit"
end
# Only try logging in if we could create a test user
if WP.user?
it "Logged in to WordPress Dashboard" do
within("#loginform") do
fill_in 'log', :with => WP.user.username
fill_in 'pwd', :with => WP.user.password
end
click_button 'wp-submit'
# Should obtain cookies and be able to visit /wp-admin
expect(page).to have_id "wpadminbar"
Read more at seravo.com/docs/tests/integration-tests
Measure execution time and memory
echo "<!-- Measurements: ";
echo memory_get_usage();
echo " - ";
echo (microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]);
echo " -->";
$ for x in {1..20}
do curl -s http://localhost | grep "Measurements"
done
<!-- Measurements: 5761720 - 0.2341411113739
<!-- Measurements: 5761720 - 0.24964690208435
<!-- Measurements: 5761704 - 0.25908708572388
<!-- Measurements: 5761720 - 0.23540115356445
...
HOW TO AUTOMATE
● git pre-commit hook
● Travis CI
GIT PRE-COMMIT HOOK IN ACTION
Example .git/hooks/pre-commit
# Loop all files that are about to be committed (diff of git head and staged)
echo "==> Checking syntax errors..."
for FILE in $(git diff --cached --name-only); do
resource="$REPO_DIR/$FILE"
##
# Test PHP syntax for all changed *.php and *.module files
##
if [[ "$FILE" =~ ^.+(php|module)$ ]]; then
if [[ -f $resource ]]; then
phpcs "$resource" 1> /dev/null
if [ $? -ne 0 ]; then
errors+=("PHP syntax Error: $FILE")
fi
fi
fi
done
See code at seravo.com/coding-wordpress-in-style-with-phpcs
TRAVIS CI IN ACTION
Example .travis.yml
before_install:
- if [[ "$SNIFF" == "1" ]]; then git clone …
script:
# Syntax check all php files and fail for any error text in STDERR
- '! find . -type f -name "*.php" -exec 
php -d error_reporting=32767 -l {} ; 2>&1 >&- | grep "^"'
# More extensive PHP Style Check
- if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/bin/phpcs -i;
$PHPCS_DIR/bin/phpcs --standard=phpcs.xml; fi
- phpunit
Live examples
github.com/Seravo/woo-pakettikauppa
github.com/Seravo/seravo-plugin
github.com/Seravo/linux-tuki.fi
github.com/Seravo/wp-https-domain-alias
travis-ci.org/Seravo
FREE FOR OPEN SOURCE CODE SERVICES
● cocodacy.com
● codeclimate.com
● codeship.com
● coveralls.io
● coverity.com
● sourceclear.com
● travis-ci.org (.com for private repos)
Listed in alphabetic order, no preference.
WordPress plugins have
a reputation of low
quality. Help us prove
them wrong. Start using
automatic quality testing!
THANK YOU!
KIITOS!
@SeravoFi
@ottokekalainen

More Related Content

PDF
Improving WordPress performance (xdebug and profiling)
PDF
How to investigate and recover from a security breach in WordPress
PDF
Use Xdebug to profile PHP
PPTX
Improving WordPress Performance: Xdebug and PHP profiling
PDF
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
PDF
Bower & Grunt - A practical workflow
PDF
Forget Grunt and Gulp! Webpack and NPM rule them all!
KEY
Write php deploy everywhere
Improving WordPress performance (xdebug and profiling)
How to investigate and recover from a security breach in WordPress
Use Xdebug to profile PHP
Improving WordPress Performance: Xdebug and PHP profiling
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
Bower & Grunt - A practical workflow
Forget Grunt and Gulp! Webpack and NPM rule them all!
Write php deploy everywhere

What's hot (20)

PDF
10 things every developer should know about their database to run word press ...
PDF
Front-end tools
PPTX
Xdebug, KCacheGrind and Webgrind with WampServer
PDF
Search in WordPress - how it works and howto customize it
PPTX
Grunt and Bower
PDF
DevOps tools for everyone - Vagrant, Puppet and Webmin
PDF
Npm scripts
PPTX
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
PDF
What makes me "Grunt"?
PPTX
Bower - A package manager for the web
PPTX
Ryan Duff 2015 WordCamp US HTTP API
PDF
DalekJS Workshop at T3DD14
PDF
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
PDF
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
PPTX
DJUGL - Django and AWS Lambda
PDF
Node.js & Twitter Bootstrap Crash Course
PDF
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
PDF
Dalek.js - Automated cross browser testing with JavaScript
PPTX
Lecture: Webpack 4
PDF
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
10 things every developer should know about their database to run word press ...
Front-end tools
Xdebug, KCacheGrind and Webgrind with WampServer
Search in WordPress - how it works and howto customize it
Grunt and Bower
DevOps tools for everyone - Vagrant, Puppet and Webmin
Npm scripts
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
What makes me "Grunt"?
Bower - A package manager for the web
Ryan Duff 2015 WordCamp US HTTP API
DalekJS Workshop at T3DD14
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
DJUGL - Django and AWS Lambda
Node.js & Twitter Bootstrap Crash Course
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Dalek.js - Automated cross browser testing with JavaScript
Lecture: Webpack 4
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
Ad

Similar to Automatic testing and quality assurance for WordPress plugins (20)

PDF
Automatic testing and quality assurance for WordPress plugins and themes
PDF
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
PPTX
Quality code in wordpress
PPTX
Introduction to Continous Integration with WordPress
PDF
Workshop quality assurance for php projects - phpbelfast
PDF
Workshop quality assurance for php projects - ZendCon 2013
PDF
Improving WordPress Performance with Xdebug and PHP Profiling
PDF
Web development automatisation for fun and profit (Artem Daniliants)
PDF
Joomla Code Quality Control and Automation Testing
PDF
Debugging: Rules And Tools - PHPTek 11 Version
PPTX
Getting started with PHPUnit
PDF
Release with confidence
PDF
WordPress Acceptance Testing, Solved!
PPTX
Continuous feature-development
PDF
The Journey Towards Continuous Integration
KEY
Prepare for PHP Test Fest 2009
KEY
Php|tek '12 It's More Than Just Style
PDF
Unit testing for WordPress
PPTX
Continuous Delivery - Automate & Build Better Software with Travis CI
KEY
Workshop quality assurance for php projects tek12
Automatic testing and quality assurance for WordPress plugins and themes
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Quality code in wordpress
Introduction to Continous Integration with WordPress
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - ZendCon 2013
Improving WordPress Performance with Xdebug and PHP Profiling
Web development automatisation for fun and profit (Artem Daniliants)
Joomla Code Quality Control and Automation Testing
Debugging: Rules And Tools - PHPTek 11 Version
Getting started with PHPUnit
Release with confidence
WordPress Acceptance Testing, Solved!
Continuous feature-development
The Journey Towards Continuous Integration
Prepare for PHP Test Fest 2009
Php|tek '12 It's More Than Just Style
Unit testing for WordPress
Continuous Delivery - Automate & Build Better Software with Travis CI
Workshop quality assurance for php projects tek12
Ad

More from Otto Kekäläinen (20)

PDF
FOSDEM2021: MariaDB post-release quality assurance in Debian and Ubuntu
PDF
MariaDB quality assurance in Debian and Ubuntu
PDF
DebConf 2020: What’s New in MariaDB Server 10.5 and Galera 4?
PDF
Technical SEO for WordPress - 2019 edition
PDF
How MariaDB packaging uses Salsa-CI to ensure smooth upgrades and avoid regre...
PDF
DebConf 2019 MariaDB packaging in Debian BoF
PDF
The 5 most common reasons for a slow WordPress site and how to fix them
PDF
Technical SEO for WordPress
PDF
WordPress-tietoturvan perusteet
PDF
Technical SEO for WordPress - 2017 edition
PDF
MariaDB adoption in Linux distributions and development environments
PDF
WordPress security 101 - WP Jyväskylä Meetup 21.3.2017
PDF
WordPress security 101 - WP Turku Meetup 2.2.2017
PDF
Find WordPress performance bottlenecks with XDebug PHP profiling
PDF
Testing and updating WordPress - Advanced techniques for avoiding regressions
PDF
Git best practices 2016
PDF
MariaDB Developers Meetup 2016 welcome words
PDF
MariaDB in Debian and Ubuntu: The next million users
PDF
Koodikerho PEPE Pajapäivä 6.9.2016
PDF
MariaDB Foundation presentation and membership info
FOSDEM2021: MariaDB post-release quality assurance in Debian and Ubuntu
MariaDB quality assurance in Debian and Ubuntu
DebConf 2020: What’s New in MariaDB Server 10.5 and Galera 4?
Technical SEO for WordPress - 2019 edition
How MariaDB packaging uses Salsa-CI to ensure smooth upgrades and avoid regre...
DebConf 2019 MariaDB packaging in Debian BoF
The 5 most common reasons for a slow WordPress site and how to fix them
Technical SEO for WordPress
WordPress-tietoturvan perusteet
Technical SEO for WordPress - 2017 edition
MariaDB adoption in Linux distributions and development environments
WordPress security 101 - WP Jyväskylä Meetup 21.3.2017
WordPress security 101 - WP Turku Meetup 2.2.2017
Find WordPress performance bottlenecks with XDebug PHP profiling
Testing and updating WordPress - Advanced techniques for avoiding regressions
Git best practices 2016
MariaDB Developers Meetup 2016 welcome words
MariaDB in Debian and Ubuntu: The next million users
Koodikerho PEPE Pajapäivä 6.9.2016
MariaDB Foundation presentation and membership info

Recently uploaded (20)

PDF
System and Network Administration Chapter 2
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Introduction to Artificial Intelligence
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Understanding Forklifts - TECH EHS Solution
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Softaken Excel to vCard Converter Software.pdf
System and Network Administration Chapter 2
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Wondershare Filmora 15 Crack With Activation Key [2025
Which alternative to Crystal Reports is best for small or large businesses.pdf
Odoo POS Development Services by CandidRoot Solutions
Adobe Illustrator 28.6 Crack My Vision of Vector Design
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Operating system designcfffgfgggggggvggggggggg
Introduction to Artificial Intelligence
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Reimagine Home Health with the Power of Agentic AI​
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Understanding Forklifts - TECH EHS Solution
2025 Textile ERP Trends: SAP, Odoo & Oracle
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
How to Migrate SBCGlobal Email to Yahoo Easily
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Softaken Excel to vCard Converter Software.pdf

Automatic testing and quality assurance for WordPress plugins

  • 1. Automatic testing and quality assurance for WordPress plugins WordCamp Jyväskylä 2018 Otto Kekäläinen @ottokekalainen WP-palvelu.fi
  • 2. ● WP-palvelu.fi – WordPress hosting and upkeep ● CEO, sysadmin and developer ● Linux and open source advocate ● Contributed to WordPress Core, fi and sv translations, Linux, Docker, Nginx, Redis, MariaDB… ● Twitter:@ottokekalainen Otto Kekäläinen
  • 3. Enterprise grade hosting and upkeep for WordPress
  • 4. EVERYBODY WANTS QUALITY Developers just don’t have enough time or customers’ budget
  • 6. DO EVERYTHING THAT CAN BE AUTOMATED ● scan code to find errors ○ static analysis ● run code to find errors ○ unit and integration tests
  • 7. TOOLS 1. what to do about PHP code 2. how to automate
  • 8. WHAT TO DO ABOUT PHP CODE ● PHP Code Sniffer ● PHP unit tests ● PhantomJS integration tests ● performance ○ execution time ○ memory usage
  • 10. PHPCS
  • 11. PHPCFB AND GIT CITOOL
  • 12. phpcs.xml <?xml version="1.0"?> <ruleset name="Seravo"> <!-- show progress --> <arg value="p"/> <!-- check current and all subfolders if no file parameter given --> <file>.</file> <rule ref="Squiz.PHP.CommentedOutCode"/> <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/> <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/> <rule ref="Generic.Commenting.Todo"/> <rule ref="Generic.ControlStructures.InlineControlStructure"/> <rule ref="WordPress-Extra"> <exclude name="Generic.WhiteSpace.DisallowSpaceIndent"/> <exclude name="Generic.WhiteSpace.ScopeIndent"/> <exclude name="WordPress.WhiteSpace.PrecisionAlignment.Found" /> <exclude name="WordPress.PHP.YodaConditions" /> </rule> </ruleset>
  • 13. phpcs --standard=Security FILE: tools/gapi.php --------------------------------------------------------------------- FOUND 1 ERROR AND 8 WARNINGS AFFECTING 8 LINES --------------------------------------------------------------------- 35 | WARNING | Possible RFI detected with GADWP_DIR on include_once 51 | WARNING | Function array_map() that supports callback detected 148 | WARNING | Possible XSS detected with esc_url on echo 152 | WARNING | Possible XSS detected with __ on echo 156 | WARNING | Possible XSS detected with _e on echo 307 | WARNING | Crypto function crc32 used. 767 | WARNING | Function array_map() that supports callback --------------------------------------------------------------------- More tips at seravo.com/coding-wordpress-in-style-with-phpcs
  • 16. Example test code it "There's a login form" do expect(page).to have_id "wp-submit" end # Only try logging in if we could create a test user if WP.user? it "Logged in to WordPress Dashboard" do within("#loginform") do fill_in 'log', :with => WP.user.username fill_in 'pwd', :with => WP.user.password end click_button 'wp-submit' # Should obtain cookies and be able to visit /wp-admin expect(page).to have_id "wpadminbar" Read more at seravo.com/docs/tests/integration-tests
  • 17. Measure execution time and memory echo "<!-- Measurements: "; echo memory_get_usage(); echo " - "; echo (microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]); echo " -->"; $ for x in {1..20} do curl -s http://localhost | grep "Measurements" done <!-- Measurements: 5761720 - 0.2341411113739 <!-- Measurements: 5761720 - 0.24964690208435 <!-- Measurements: 5761704 - 0.25908708572388 <!-- Measurements: 5761720 - 0.23540115356445 ...
  • 18. HOW TO AUTOMATE ● git pre-commit hook ● Travis CI
  • 19. GIT PRE-COMMIT HOOK IN ACTION
  • 20. Example .git/hooks/pre-commit # Loop all files that are about to be committed (diff of git head and staged) echo "==> Checking syntax errors..." for FILE in $(git diff --cached --name-only); do resource="$REPO_DIR/$FILE" ## # Test PHP syntax for all changed *.php and *.module files ## if [[ "$FILE" =~ ^.+(php|module)$ ]]; then if [[ -f $resource ]]; then phpcs "$resource" 1> /dev/null if [ $? -ne 0 ]; then errors+=("PHP syntax Error: $FILE") fi fi fi done See code at seravo.com/coding-wordpress-in-style-with-phpcs
  • 21. TRAVIS CI IN ACTION
  • 22. Example .travis.yml before_install: - if [[ "$SNIFF" == "1" ]]; then git clone … script: # Syntax check all php files and fail for any error text in STDERR - '! find . -type f -name "*.php" -exec php -d error_reporting=32767 -l {} ; 2>&1 >&- | grep "^"' # More extensive PHP Style Check - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/bin/phpcs -i; $PHPCS_DIR/bin/phpcs --standard=phpcs.xml; fi - phpunit
  • 24. FREE FOR OPEN SOURCE CODE SERVICES ● cocodacy.com ● codeclimate.com ● codeship.com ● coveralls.io ● coverity.com ● sourceclear.com ● travis-ci.org (.com for private repos) Listed in alphabetic order, no preference.
  • 25. WordPress plugins have a reputation of low quality. Help us prove them wrong. Start using automatic quality testing!