Skip to content

Instantly share code, notes, and snippets.

@kurtpayne
Last active April 8, 2019 01:17
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurtpayne/3429214 to your computer and use it in GitHub Desktop.
Save kurtpayne/3429214 to your computer and use it in GitHub Desktop.
WordPress Unit Tests Jenkins Config
#!/bin/bash
find $1 \( -type f -and \( -name "*.php" -or -name "*.inc" -or -name "*.phtml" \) \) -exec php -l {} \; | grep -v "No syntax errors"
<phpunit
bootstrap="includes/bootstrap.php"
backupGlobals="false"
colors="false"
>
<testsuites>
<!-- Default test suite to run all tests -->
<testsuite>
<directory suffix=".php">tests</directory>
<exclude>tests/actions/closures.php</exclude>
<exclude>tests/image/editor.php</exclude>
<exclude>tests/image/editor_gd.php</exclude>
<exclude>tests/image/editor_imagick.php</exclude>
<file phpVersion="5.3.0">tests/actions/closures.php</file>
<file phpVersion="5.3.0">tests/image/editor.php</file>
<file phpVersion="5.3.0">tests/image/editor_gd.php</file>
<file phpVersion="5.3.0">tests/image/editor_imagick.php</file>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>ajax</group>
</exclude>
</groups>
<filter>
<whitelist addUncoveredFilesFromWhitelist="false">
<directory suffix=".php">wordpress/wp-admin</directory>
<directory suffix=".php">wordpress/wp-includes</directory>
<exclude>
<directory suffix=".php">wordpress/wp-includes/ID3</directory>
<directory suffix=".php">wordpress/wp-includes/SimplePie</directory>
<directory suffix=".php">wordpress/wp-includes/Text</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml" showUncoveredFiles="false" />
<log type="coverage-html" target="build/logs/coverage" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="80" showUncoveredFiles="false" />
<log type="junit" target="build/logs/junit.xml" />
</logging>
</phpunit>
# Base system
yum update
yum install yum-priorities
rpm -Uvh http://mirrors.rit.edu/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/ius-release-1.0-11.ius.el6.noarch.rpm
yum install httpd mysql-server mysql httpd-devel install gcc-c++ openssl-devel tcl-devel expat-devel pcre-devel make
yum install php php-common php-devel php-pear php-pdo php-pecl-apc php-cli php-mysql php-gd php-pecl-imagick php-xml php-tidy php-mbstring php-pecl-xdebug
yum --enablerepo=remi update -y
yum install git subversion munin munin-node patch
chkconfig mysqld on
chkconfig httpd on
chkconfig munin-node on
service mysqld start
service httpd start
service munin-node start
# java
yum install java-1.7.0-openjdk.x86_64
yum install java-1.7.0-openjdk-devel.x86_64
cd /opt
wget http://www.poolsaboveground.com/apache//ant/binaries/apache-ant-1.9.0-bin.tar.gz
tar -xzvf apache-ant-1.9.0-bin.tar.gz
# jenkins
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
yum install jenkins
chkconfig jenkins on
service jenkins start
# php
wget http://pear.php.net/go-pear.phar
php go-pear.phar
rm go-pear.phar
pear config-set auto_discover 1
pear install --alldeps pear.phpunit.de/PHPUnit
pear install --alldeps pear.phpunit.de/phpcpd
pear channel-discover pear.phpmd.org
pear channel-discover pear.pdepend.org
pear install --alldeps phpmd/PHP_PMD
pear channel-discover pear.docblox-project.org
pear install docblox/DocBlox
pear install PHP_CodeSniffer
# Configure jenkins
# 1.) Set the ant installation to /opt/ant-1.9.0
# 2.) Add yourself as a user
# 3.) Set up matrix based security, etc.
# 4.) Add some plugins (DRY, PMD, clover php, static analysis, task scanner, duplicate code scanner, gravatar)
# 5.) Add a new project (e.g. "WordPress")
# 6.) Choose "free style project"
# 7.) ... sorry, just got here ... the rest will need a screenshot I think.
<project name="WordPress" default="build" basedir=".">
<target name="clean">
<!-- Clean up -->
<delete dir="build"/>
<!-- Create build directories -->
<mkdir dir="${basedir}/build/coverage"/>
<mkdir dir="${basedir}/build/logs"/>
<mkdir dir="${basedir}/build/docs"/>
<!-- Get a copy of the project -->
<copy tofile="${basedir}/phpunit_jenkins.xml" file="/tests/phpunit_jenkins.xml" />
</target>
<!-- Run unit tests and generate junit.xml and clover.xml -->
<target name="phpunit">
<copy tofile="${basedir}/wp-tests-config.php" file="${basedir}/wp-tests-config-sample.php" />
<replaceregexp file="${basedir}/wp-tests-config.php" match="yourdbnamehere" replace="wordpress_tests" byline="true" />
<replaceregexp file="${basedir}/wp-tests-config.php" match="yourusernamehere" replace="wordpress_tests" byline="true" />
<replaceregexp file="${basedir}/wp-tests-config.php" match="yourpasswordhere" replace="************" byline="true" />
<!-- <replaceregexp file="${basedir}/wp-testlib/testcase.php" match="'ROLLBACK' \);" replace="'ROLLBACK' ); ini_set( 'memory_limit', -1 );" byline="true" /> -->
<exec executable="phpunit" failonerror="true" dir="${basedir}">
<arg line="--configuration=${basedir}/phpunit_jenkins.xml" />
</exec>
</target>
<!-- Run build tasks in parallel -->
<target name="buildTasks">
<parallel>
<antcall target="docblox" />
<!-- <antcall target="phpdoc" /> -->
<antcall target="lintcheck"/>
<antcall target="phpcpd" />
<!-- <antcall target="phpmd" /> -->
<antcall target="phpunit" />
</parallel>
</target>
<!-- Lint check every php file -->
<target name="lintcheck">
<exec executable="phpl" output="${basedir}/build/logs/lintcheck.txt">
<arg line="${basedir}" />
</exec>
</target>
<!-- Generate API documentation using docblox -->
<target name="docblox">
<exec executable="docblox" output="${basedir}/build/docs/errors.txt">
<arg line="project:run
--directory ${basedir}/wordpress
--target ${basedir}/build/docs
--ignore build/logs,build/coverage,build/docs
--title WordPress
--extensions php
--force" />
</exec>
</target>
<!-- Generate API documentation using phpdoc2 -->
<target name="phpdoc">
<exec executable="phpdoc" output="${basedir}/build/docs/errors.txt">
<arg line="-t ${basedir}/build/docs -d ${basedir}/wordpress -e php" />
</exec>
</target>
<!-- Detect duplicate code -->
<target name="phpcpd">
<exec executable="phpcpd">
<arg value="--log-pmd" />
<arg value="${basedir}/build/logs/pmd-cpd.xml" />
<arg path="${basedir}/wordpress" />
</exec>
</target>
<!-- Look for unused variables and overly complex code -->
<target name="phpmd">
<exec executable="phpmd">
<arg path="${basedir}/wordpress" />
<arg value="xml" />
<arg value="unusedcode" />
<arg value="--reportfile" />
<arg value="${basedir}/build/logs/phpmd.xml" />
</exec>
</target>
<!-- delete config -->
<target name="deleteConfig">
<delete file="${basedir}/wp-tests-config.php" />
<delete file="${basedir}/phpunit_jenkins.xml" />
</target>
<!-- and build ... -->
<target name="build" depends="clean,buildTasks,deleteConfig"/>
</project>
@kurtpayne
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment