PHPUnit and Jenkins

PHP, QA, and Jenkins
Eric Cope
June 25, 2013
About Me
• I run Voltamp Media Inc., a 1-man web-dev
• PHP-literate since 2002
• CodeIgniter since 2005 (1.6 whenever that
• Bitten by the TDD bug around 2006
• Met Hudson/Jenkins in 2011
The Tools
• Jenkins -
– Continuous Integration Tool
– Basic install is a quick download then:
• java –jar jenkins.war
• Normal vs. LTS
– For bigger installations, its recommended to run within a
java container, like Tomcat.
• PHPUnit –
– A set of QA tools
– Installation is via PEAR
• Selenium –
– java -jar selenium-server-standalone-2.31.0.jar
Getting Started
• Open a browser to:
– http://localhost:8080
Managing Jenkins
• File System Location
– Config files
– Project build areas
– Manage plugins
• Start from here -
• Get the plugins
Static Code Analysis Plug-ins
Clover PHP Plugin
Plot plugin
DRY Plugin
Checkstyle Plugin
PMD Plugin
Git Plugin
HTML Publisher Plugin
xUnit Plugin
The First Job
• Each job must be configured!
– Source Code – how to get the code
– Build triggers (poll SCM, commit hooks)
– Build Steps
• Scripts (very limited environment)
• Maven
• Ant – see for yours!
– Post Build Steps
• Plots, reports
The ANT Script
• This is auto-generated,
then modified as
• Test by running:
% ant /path/to/build.xml
• More at
The PHPUnit Script
• This is auto-generated, then modified as needed too
• Test by running: % phpunit
PHPUnit Tips and Tricks - fixtures
• YAML files can be used within a fixture
PHPUnit Tips and Tricks – data
• YAML files can
be used as a
data provider
– Calls the provider
(returns an array)
– For each row it calls the
• The YAML is
PHPUnit Tips and Tricks – Exceptions
• Test your exceptions!
• Check exception class and code
Bonus! PHPUnit and Selenium
• Make Jenkins drive PHPUnit drive Selenium!
My Issues - controller
• My current projects use CodeIgniter. CIUnit
makes using PHPUnit and CI better, but setup
is painful.
– End case of parent controller
• Correct parent class in setUp, but not in the
• MY_Controller vs. Controller
– $this->CI = set_controller('MY_Controller');
My Issues - Selenium
• Selenium has matured quite a bit, but
documentation and support is still very lean.
• PHPUnit’s Selenium2 class is much better, but still
leaves much to be desired.
– Click() does not wait for the page to load after a form
submission. Selenese supported clickandwait(), but I
can’t find documentation…
Still to Learn/Do
Dependency Injection
Code Coverage
More Integration coverage with Selenium
Exclude External Libraries in analysis || fix
• Better TDD / BDD

similar documents