This document appears to be a presentation about unit testing for WordPress. Some key points:
- The presenter has over a decade of PHP experience and 8 years experience with WordPress.
- Different types of testing are covered, including unit, integration, and functionality testing. PHPUnit is introduced as a tool for unit testing.
- Examples are provided for writing basic unit tests for PHP code using PHPUnit, including setting up tests, mocking WordPress functions, and testing exceptions.
- Tips are given for unit testing WordPress plugins and themes, such as using WordPress mocking libraries and focusing tests on application code rather than WordPress core functions.
Machine Learning Software Engineering Patterns and Their Engineering
Unit testing for WordPress
1. Sudar Muthu | @sudarmuthu #WCPune
Unit Testing For
WordPress
WordCamp Pune, 2015
Sudar Muthu
http://sudarmuthu.com
https://github.com/sudar
2. Sudar Muthu | @sudarmuthu #WCPune
Me
• Programming in PHP for more than a decade and in
WordPress for about 8 years.
• Big fan of automating process and workflows.
• Contributor to a couple of open source projects.
• Remote worker at 10up (and yes 10up is hiring :) )
3. Sudar Muthu | @sudarmuthu #WCPune
What about you?
• What is your typical development environment?
• What is your experience with PHP and WordPress?
• What is your experience with Unit Testing?
• What are your expectations out of this talk?
4. Sudar Muthu | @sudarmuthu #WCPune
Unit Testing
Credit: https://twitter.com/alistratov/status/599109195548459009
5. Sudar Muthu | @sudarmuthu #WCPune
Is there something wrong?
class Sample {
protected $value;
public function initialise($value) {
$this->value = $value;
}
public function execute() {
if (!$this->value) {
throw new Exception("value not set");
}
return $value * 10; // business logic
}
}
$sample = new Sample;
$sample->execute();
6. Sudar Muthu | @sudarmuthu #WCPune
Finding bugs is not
easy
25. Sudar Muthu | @sudarmuthu #WCPune
Some PHPUnit Tips
• Have a fast test suite
• Use Composer
• Enable code coverage in reports
• phpunit.xml.dist vs phpunit.xml
• Use specific assertions
• Check out Unit tests in WordPress core
26. Sudar Muthu | @sudarmuthu #WCPune
WordPress plugin
skeleton with Tests
Use yo generator
https://github.com/10up/generator-wp-make